nvarner / typst-lsp

A brand-new language server for Typst, plus a VS Code extension
MIT License
1.16k stars 77 forks source link

How to use this LSP with the KDE Kate text editor #404

Open kleinbottle opened 6 months ago

kleinbottle commented 6 months ago

Feature Request

Dear Folks,

Thank your for creating this LSP.

I am a long time user of the KDE kate text editor and would like to use the typst-lsp server with kate.

I have installed the AUR package typst-lsp-bin from https://aur.archlinux.org/packages/typst-lsp-bin.

I am trying to get kate to recognize and use typst-lsp-bin but have not been able to do so thus far.

The recommended syntaxes to add a new language server for kate are shown here.

I added the following JSON block to my settings.json for kate as shown below:

{
    "servers": {
        "typst": {
            "command": ["/usr/bin/typst-lsp"],
            "url": "https://github.com/nvarner/typst-lsp",
            "highlightingModeRegex": "^Typst$"
        }
    }
}

However, I ended up with the following error:

[08:50:41  LSP Client Warning] Failed to find server binary: vscode-json-languageserver
Please check your PATH for the binary
See also https://github.com/microsoft/vscode/tree/main/extensions/json-language-features/server for installation or details

Does typst-lsp only support VSCode?

It would be great if typst-lsp could support other text editors as well.

Kindly make it usable with kate or let me know the correct JSON syntax.

Many thanks.

PgBiel commented 6 months ago

I installed typst-lsp from nixpkgs and managed to use it within Kate with the following configuration:

{
    "servers": {
        "typ": {
            "command": ["/nix/store/ax813pfbcg9sjzyasam9paw432bakfjf-typst-lsp-0.12.0/bin/typst-lsp"],
            "highlightingModeRegex": "^Typst$"
        }
    }
}

Could be a problem with the specific package you're using, but either way the above worked for me. You might have to create a Typst filetype by going to Kate's settings, Open / Save, Modes & Filetypes, naming it "Typst" and assigning the typ file extension. I also assigned Rust's syntax highlighting, although that didn't seem to affect anything.

kleinbottle commented 6 months ago

@PgBiel: Thank you for your reply. I have now set up a new Filetype for Typst. But there is no syntax highlighting for Typst-specific keywords. Punctuation, brackets and strings are highlighted, but that is all.

I expected the typst-lsp to give me syntax highlighting, but it does not, even though it does on VSCode/VSCodium via an extension from the marketplace, but by the same author.

Do you get Typst-specific syntax highlighting with kate? From the KDE kate website, it does not seem to have it. Please see:

https://kate-editor.org/syntax/

nvarner commented 6 months ago

In short, there's no good way to provide syntax highlighting to every editor. This extension has the best support for VS Code(ium), so other editors will usually be worse for now.

Kate seems to use its own custom format for syntax highlighting, which means writing and maintaining a syntax highlighting file just for Kate. However, from what you've said and some brief research, Kate seems to support semantic highlighting. It would require some code changes, but it would be an easier way to get Typst syntax highlighting in Kate.

Ultimately, this means there's probably no quick fix right now.

nvarner commented 6 months ago

I put some time into investigating this. It looks like Kate in particular has only very limited support for semantic tokens. This probably means Typst won't have very good syntax highlighting in Kate unless someone writes a Kate-specific grammar for the language.

You'll also need to update your LSP configuration so that typst-lsp actually attempts to use semantic tokens.

{
    "servers": {
        "typst": {
            "command": ["/your/path/to/typst-lsp"],
            "url": "https://github.com/nvarner/typst-lsp",
            "highlightingModeRegex": "^Typst$",
            "initializationOptions": {
                "semanticTokens": "enable"
            }
        }
    }
}

Choosing Rust syntax highlighting is technically wrong, since that just tells Kate to imagine your Typst code is really just Rust. That means it will probably highlight many things incorrectly. However, it's possible that this will give better results than semantic tokens alone, just because of the limitations of Kate's implementation.

nvarner commented 6 months ago

(Extremely) relevant Kate MR: https://invent.kde.org/utilities/kate/-/merge_requests/1247

kleinbottle commented 6 months ago

You'll also need to update your LSP configuration so that typst-lsp actually attempts to use semantic tokens.

I have done so, and the typst-lsp server is well and truly recognized in kate but the syntax highlighting is limited. Rust provides more "color" but might be wrong as you have suggested.

I have a few questions on which I will get back to you.

jgardona commented 2 months ago

I have tryed all these things from kate flatpack and nothing works. Lsp even don't starts.