A brand-new language server for Typst, plus a VS Code extension

Overview

Typst LSP

A brand-new language server for Typst.

Features

  • Syntax highlighting, error reporting, code completion, and function signature help
  • Compiles to PDF on save (configurable to as-you-type, or can be disabled)

This repo consists of:

Near future goals

  • Improved preview (e.g. built-in PDF viewer, render to image for speed)
  • Support for more editors

Development guide

Prerequisites

Install:

  • Rust for the LSP itself
  • Rust Analyzer an extension for Rust LSP for VS Code
  • node for the VS Code extension; it may be easiest to install via fnm

First time setup

  1. Clone this repository locally
  2. Open it in VS Code; it's needed to run the extension
  3. In the addons/vscode subdirectory:
    1. Run npm install to install extension dependencies
    2. Run npm run compile to build the extension
  4. Run through the development cycle once to initialize and test everything
  5. (Optional: install the dev version of the extension): Press Ctrl+Shift+P, and choose Developer: Install Extension from Location... and choose the directory for the extension, addons/vscode/. There will not be any messages, but the extension can be found in the Extensions @installed list.

Development cycle

  1. Make any changes
  2. Run cargo install --path .; at present, the VS Code extension just invokes the typst-lsp command to start the LSP, and this command will compile and replace that binary with the latest version
    • If modifying the extension, keep npm run watch running, or npm run compile after changes
  3. Press Ctrl+F5 to launch the "Extension Development Host"; if it's already running, invoke "Developer: Reload Window" from the command palette in the Extension Development Host
  4. Within the Extension Development Host, the extension will be active and ready for testing
Comments
  • Add Rust Analyzer in the install instructions

    Add Rust Analyzer in the install instructions

    UPDATE: This PR now specifies the dependence on Rust Analyzer through the install instructions.

    Currently, installing the extension for developers, depends on Rust Analyzer. That is due to "type": "cargo" is a construction from rust-analyzer.

    ~~Instead, this just invokes cargo as a shell command.~~

    opened by CGMossa 12
  • add release action

    add release action

    Adds a release.yml github actions workflow that builds the server binary and extension for every target listed in https://code.visualstudio.com/api/working-with-extensions/publishing-extension#platformspecific-extensions.

    The action runs on new git tags, and creates a release with all the binaries and vsix, and calls vsce publish. You'll need to add a VSCE_PAT github secret (how to get access token) and add a publisher field to the package.json.

    • add png version of icon
    • change extension.ts to look for bundled executable first, falls back to typst-lsp[.exe] (could also be configurable via vscode settings)
    • add LICENSE file and package.json properties to addons/vscode
    • add esbuild for bundling and change package.json scripts
      • npm run package builds .vsix, bundles using esbuild minified
      • npm run compile bundles using esbuild with source maps
      • npm run check runs tsc to check typescript
      • npm run lint/lint-fix as before

    If you'd like to have anything changed let me know :)

    opened by jakobhellermann 8
  • Fix panic error when unwrapping root_uri without workspace

    Fix panic error when unwrapping root_uri without workspace

    Fix the following error when opening a singe file (with no folder in the workspace)

    thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/main.rs:26:29
    

    fixes #41 fixes #36

    opened by Bramas 7
  • VSC Extension not properly handling symlinks in path

    VSC Extension not properly handling symlinks in path

    • Component:
      • [ ] VSCode Extension
      • [x] VSCodium Extension
      • [ ] LSP (used with other editor)
    • Extension version: 0.4.0
    • LSP version: 0.4.0
    • OS version and name: OpenSUSE Tumbleweed, snapshot 20230402
    • [X] I am on the latest stable version of the extension/LSP.
    • [X] I have searched the issues of this repo and believe that this is not a duplicate.

    Issue

    Since the latest release (0.4.0 - this did not occur in 0.3.2), when opening a .typ file in a workspace whose path contains symlinks, the extension seems to automatically resolve the symlinks, and, when you click on errors or similar to check where they are, it opens the file again, but on the actual absolute path instead of the symlinked path. This has become somewhat of an annoyance, as my usual workspace uses symlinks in its path.

    Reproduction Steps

    1. Create a folder, e.g. mkdir /tmp/a
    2. Create a typst file in there with an error, e.g. echo "soajdfo()asdfo" >> /tmp/a/bad.typ
    3. Create a symlink to the folder, e.g. ln -s /tmp/a /tmp/b
    4. Open the symlink as a workspace in Code/Codium, e.g. codium /tmp/b
    5. Open the bad.typ file, and edit it slightly (e.g. write "abc" at the end) to ensure it is not opened as a preview (but for editing)
    6. Open the errors panel, and click the error (to be taken to it)

    Expected Result: it just takes you to the error in the currently open file Actual Result: it opens the file again, as if it was external to the current project, but in the absolute path (with symlinks resolved) instead of relative to the current (symlinked) directory

    opened by PgBiel 5
  • Bump typst version to 0.2.0

    Bump typst version to 0.2.0

    Thanks for your hard work on this awesome extension. But I think it depends on a considerably outdated version of Typst. Given that the new Typst 0.2.0 has introduced brand new syntaxs like unpacking (see https://github.com/typst/typst/releases/tag/v0.2.0), I think it is a good time to bump typst version to a newer one.

    I have tested the compilation and installation, they work fine, but I do realize there are some incompatibility with the newer syntax. I am not that familiar with Rust so help needed here from you capable guys. Take this PR as a reminder to upgrade typst version then, maybe?

    opened by TeddyHuang-00 5
  • [Feature]

    [Feature] "Show PDF" button

    This PR is in response to #69.

    Discussion

    I am not really happy how the file extension/type is currently manually changed from .typ to .pdf. I'll happily implement something more robust if somebody has a recommendation.

    opened by dvdvgt 5
  • Out of Memory

    Out of Memory

    Process typst-lsp caused out of memory and was killed. It eat 8+Gb session. A single main.typ file was editted for several hours.

    • Component:
      • [ ] VSCode Extension
      • [ ] VSCodium Extension
      • [x] LSP (+ neovim)
    • Extension version:
    • LSP version: 0.3.1-1
    • OS version and name: ArchLinux
    • [x] I am on the latest stable version of the extension/LSP.
    • [x] I have searched the issues of this repo and believe that this is not a duplicate.
    opened by daskol 5
  • Ever-growing memory usage

    Ever-growing memory usage

    • [x] I have searched the issues of this repo and believe that this is not a duplicate.
    • [x] I have searched the discussions and believe that my question is not already covered.

    Feature Request

    The memory usage of the typst-lsp grows linearly with time, until after a few hours of intense usage it reaches nearly 32 GB of RAM. Most of this seems to be unused entries in typst's comemo cache, since swapping doesn't hurt performance much. Could the LSP be configured to perform regular evictions of old cache entries, via https://docs.rs/comemo/latest/comemo/fn.evict.html?

    opened by imbrem 5
  • Clippy lints are not enforced in CI

    Clippy lints are not enforced in CI

    Right now clippy lints are not causing an error in CI, they just raise warnings (e.g. https://github.com/nvarner/typst-lsp/actions/runs/4523508185/jobs/7966681325)

    Is that something that we want to change to enforce consistency?

    The following command causes errors on clippy warnings: cargo clippy -- -Dwarnings

    opened by beeb 5
  • Configurable lsp location for the vscode extension

    Configurable lsp location for the vscode extension

    • [x] I have searched the issues of this repo and believe that this is not a duplicate.
    • [x] I have searched the discussions and believe that my question is not already covered.

    Feature Request

    Add an option to use typst-lsp from PATH (or any absolute path), instead of relying the bundled excutable.

    The bundled executable will not work on every linux distro.

    opened by viperML 4
  • Doesn't create a PDF

    Doesn't create a PDF

    Perhaps a dumb question, but I installed the VSCode extension (on Windows 10), created a .typ file, entered some random text, saved it. Nothing happens. No pdf is created, nothing in Output window. VSCode is showing "Typst" for document and extension settings for PDF creation are set "onSave". Am I missing something obvious? Also, perhaps add a paragraph to readme on what to expect (i.e. if configured properly, a NAME.pdf should appear alongside original text).

    opened by MihaMarkic 4
  • Functions from modules do not syntax highlight

    Functions from modules do not syntax highlight

    • Component:
      • [x] VSCode Extension
      • [ ] VSCodium Extension
      • [ ] LSP (used with other editor)
    • Extension version: v0.4.0
    • LSP version: v0.4.0
    • OS version and name: macOS 13.3
    • [x] I am on the latest stable version of the extension/LSP.
    • [x] I have searched the issues of this repo and believe that this is not a duplicate.

    Issue

    Looks like something is wrong with the TextMate grammar as modules are scoped as entity.other.interpolated.typst.source.typst instead of entity.name.function.typst.source.typst

    Can be quickly reproduced by making a module.typ file with #let hello_world() = [hello world!] and then a test.typ file with #import "module.typ" #module.hello_world()

    Logs

    image

    opened by jesseylin 0
  • Auto-refresh PDF file

    Auto-refresh PDF file

    • [x] I have searched the issues of this repo and believe that this is not a duplicate.
    • [x] I have searched the discussions and believe that my question is not already covered.

    Feature Request

    Pull request #72 seems to create or open the generated pdf in VSCode only after push the "Show PDF" Button. Could you please make the pdf file auto refreshed after compiling like the latex/markdown extensions in vscode.

    opened by maoshunyu 5
  • [Feature Request] Settings for additional font directories

    [Feature Request] Settings for additional font directories

    • [x] I have searched the issues of this repo and believe that this is not a duplicate.
    • [x] I have searched the discussions and believe that my question is not already covered.

    Feature Request

    Could we have a new setting for additional font directories? Just like the --font-path option in typst. It would be useful when using fonts that are not embedded. Also some dependent settings like whether to search recursively. Thanks for your contributions! I am enjoying using this extension!

    opened by LuhaoLiu 0
  • Syntax highlighting issue of italic and bold text

    Syntax highlighting issue of italic and bold text

    • Component:
      • [x] VSCode Extension
      • [ ] VSCodium Extension
      • [ ] LSP (used with other editor)
    • Extension version: 0.3.2
    • LSP version: (not sure. should be the one bundled with the extension)
    • OS version and name: OpenSUSE Tumbleweed 20230322, VSCode 1.77.0
    • [x] I am on the latest stable version of the extension/LSP.
    • [x] I have searched the issues of this repo and believe that this is not a duplicate.

    Issue

    First big thanks for the fabulous work!

    Here's an issue with the rendering in the editor view of VSCode:

    image

    But the view is correct when the styled parts are put in the same line:

    image

    Logs

    N/A

    opened by Alecton4 1
  • PDF not exported when non-main source files are changed (onSave or onType)

    PDF not exported when non-main source files are changed (onSave or onType)

    • Component:
      • [x] VSCode Extension
      • [ ] VSCodium Extension
      • [x] LSP (used with other editor)
    • Extension version: v0.3.1
    • LSP version:
    • OS version and name:
    • [x] I am on the latest stable version of the extension/LSP.
    • [x] I have searched the issues of this repo and believe that this is not a duplicate.

    Issue

    Reproduce:

    • [VSCode Extension setting] Export PDF: onSave and onType
    • Folder structure
    .
    ├── other.typ
    ├── main.pdf
    ├── main.typ
    └── template.typ
    
    • In main.typ:
    #include "other.typ"
    

    When other.typ is modified, the PDF will not be rendered automatically.

    opened by xingjian-zhang 3
  • Outline feature support

    Outline feature support

    • [x] I have searched the issues of this repo and believe that this is not a duplicate.
    • [x] I have searched the discussions and believe that my question is not already covered.

    Feature Request

    Implement the outline of the typst source file and display the outline in the VSCode outline view. image This feature might require building the AST of a typst source file.

    opened by KagaJiankui 0
Releases(v0.4.1)
Owner
Nathan Varner
Undergrad in CS and Math at the University of Michigan, graduating 2025
Nathan Varner
A LSP (Language Server Protocol) server for OpenSCAD.

openscad-LSP A LSP (Language Server Protocol) server for OpenSCAD. inspired by dzhu/openscad-language-server Tested with VSCode on Mac and Windows. Te

Leathong 20 Dec 15, 2022
impl LSP (Language Server Protocol) Server for librime

rime-ls 为 rime 输入法核心库 librime (的部分功能) 实现 LSP 协议, 从而通过编辑器的代码补全功能输入汉字. 项目还处在早期阶段, 各方面都非常不成熟. 目标是提供 rime + LSP 的通用解决方案, 在不同编辑器内实现与其他 rime 前端类似的输入体验. Feat

zilch40 55 Jan 22, 2023
IDE tools for writing pest grammars, using the Language Server Protocol for Visual Studio Code, Vim and other editors

Pest IDE Tools IDE support for Pest, via the LSP. This repository contains an implementation of the Language Server Protocol in Rust, for the Pest par

pest 20 Apr 8, 2023
Visual Studio extension for Rust

Visual Studio extension for Rust Currently in development, and not feature complete. Stable versions are available on the Visual Studio extension gall

PistonDevelopers 697 Dec 18, 2022
Rust extension for Visual Studio 2017 with RLS support

Rust support for Visual Studio 2017 Preview Adds language support for Rust to Visual Studio 2017. Supports: code completion goto definition find all r

Zoey Riordan 111 Aug 4, 2022
crates is an extension aims to help people to manage their dependencies for rust (crates.io & TOML).

crates Hello Rust & VSCode lovers, This is crates, an extension for crates.io dependencies. Aims helping developers to manage dependencies while using

Seray Uzgur 164 Jan 4, 2023
Auto-Complete is an intelligent auto-completion extension for Emacs.

Auto-Complete is an intelligent auto-completion extension for Emacs. It extends the standard Emacs completion interface and provides an environment that allows users to concentrate more on their own work.

Emacs Auto-Complete 1.7k Dec 28, 2022
GitHub CLI extension to show & rename the default branch.

gh-default-branch GitHub CLI extension to show & rename the default branch. rename subcommand was inspired by this gist. ⚠️ Caution The rename subcomm

Daido Shota 8 Sep 22, 2022
A native debugger extension for VSCode based on LLDB

Features Conditional breakpoints, function breakpoints, logpoints, Hardware data access breakpoints (watchpoints), Launch debuggee in integrated or ex

null 1.6k Dec 31, 2022
Rust IDE support for Atom, powered by the Rust Language Server (RLS)

IDE-Rust Rust language support for Atom-IDE, powered by rust-analyzer. Features Auto-completion Diagnostics (errors and warnings from rustc) Document

The Rust Programming Language 239 Dec 14, 2022
Kakoune Language Server Protocol Client

Kakoune Language Server Protocol Client kak-lsp is a Language Server Protocol client for Kakoune implemented in Rust. Installation Note kak-lsp.toml d

null 495 Dec 17, 2022
Language Server Protocol (LSP) support for vim and neovim.

For legacy python implementation, see branch master. LanguageClient-neovim Language Server Protocol support for vim and neovim. More recordings at Upd

Junfeng Li 3.5k Dec 29, 2022
An experimental proofreading and linting language server for markdown files ✍️

prosemd is an experimental proofreading and linting language server for markdown files. It aims to provide helpful and smart diagnostics when writing

Phil Pluckthun 132 Dec 14, 2022
Repository for the Rust Language Server (aka RLS)

Rust Language Server (RLS) The RLS provides a server that runs in the background, providing IDEs, editors, and other tools with information about Rust

The Rust Programming Language 3.6k Dec 30, 2022
Experimental treesiter based language server, let's see how far this goes 😆.

tsls Tree-sitter based language server for general languages. Warning: It's in active development right now, and bug is expected. Features Go To Defin

Keyv Chan 16 Sep 11, 2022
Fennel language server protocol (LSP) support.

fennel-language-server Fennel language server protocol (LSP) support. fennel-language-server is currently in a very early stage and unreliable. Use it

null 68 Dec 27, 2022
WIP: Asynchronous Language Server Protocol framework

async-lsp Asynchronous Language Server Protocol (LSP) framework based on tower. ⚠️ This project serves as a proof-of-concept for LSP with middlewares

null 9 Apr 11, 2023
Rust for Visual Studio Code

Hello everyone. I'm a maintainer and I'm very busy. At some point rls-vscode will supersede the extension. Until that moment someone should maintain t

null 482 Dec 17, 2022
Apprentice-vscode - a port of @romainl’s excellent Apprentice Vim colour scheme to VS Code

Apprentice for VS Code apprentice-vscode is a port of @romainl’s excellent Apprentice Vim colour scheme to VS Code. The theme is available in two vari

Luna Razzaghipour 6 Dec 21, 2022