Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kleinbottle opened this issue Dec 31, 2023 · 7 comments
Open

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

kleinbottle opened this issue Dec 31, 2023 · 7 comments
Labels
enhancement New feature or request language server Related to the language server

Comments

@kleinbottle
Copy link

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

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
Copy link
Contributor

PgBiel commented Dec 31, 2023

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
Copy link
Author

@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
Copy link
Owner

nvarner commented Jan 1, 2024

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
Copy link
Owner

nvarner commented Jan 7, 2024

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
Copy link
Owner

nvarner commented Jan 7, 2024

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

@nvarner nvarner added enhancement New feature or request language server Related to the language server labels Jan 7, 2024
@kleinbottle
Copy link
Author

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
Copy link

jgardona commented May 19, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request language server Related to the language server
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

4 participants