4 ms·
Is anyone using treesitter with lsp-mode? I see some people say it's possible and use both together but I thought for the most part language servers offer the
by Difwif 3y ago
Is anyone using treesitter with lsp-mode?
I see some people say it's possible and use both together but I thought for the most part language servers offer the same set of features, and probably better? My current mental model for how to use them together is that the majority of the languages I quickly read I set up treesitter for speed. For languages I read extensively or write I set up a language server.
- BaculumMeumEst 3y agothey are mostly used for different things. lsp (and lsp-mode) are mostly concerned with IDE functionality- go-to definition, show references, displaying project errors in real time without explicitly building, etc. tree-sitter builds a syntax tree of your source code; its applications are things like syntax highlighting and structural navigation of your code. there is some overlap in functionality, lsp has somewhat supported mechanisms for syntax highlighting iirc, but they are fairly orthogonal overall so yes, it makes sense to use them together
- Difwif 3y agoInteresting, I know LSPs provide me some syntax highlighting and some structural navigation but I haven't compared the two APIs directly. I assumed most LSPs are a superset.
- Difwif 3y agoQuick follow up, looked into the LSP spec and it does define "SemanticTokens" since 3.16 https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_semanticTokens https://microsoft.github.io/language-server-protocol/specifi... Obviously it depends on the LSP implementation but it looks expressive enough to replace treesitter?
- mdaniel 3y agoThat was interesting, thanks for pointing it out I was tremendously sad to see that the Typescript Language Server wasn't owned by Microsoft <https://microsoft.github.io/language-server-protocol/implementors/servers/ https://microsoft.github.io/language-server-protocol/impleme...>, since if there was any sanity in the world a spec bump would travel with a reference implementation showing how they envision such a thing being used But, I found that the Typescript Language Server that they did list does indeed have a semantic-tokens module in it, although it's much shorter than I would have expected from reading that section in the spec: https://github.com/typescript-language-server/typescript-language-server/blob/v3.3.2/src/features/semantic-tokens.ts https://github.com/typescript-language-server/typescript-lan...
- tuukkah 3y agoThat code implements a (luckily) simple transformation from Microsoft's tsserver format to Microsoft's LSP format: > Transforms the semantic token spans given by the ts-server into lsp compatible spans
- nequo 3y agoI use both. In my experience, syntax highlighting with language servers is slower than with tree-sitter. It stands to reason: a language server often does way more than just incremental parsing of the source code into a concrete syntax tree. By limiting itself to syntax, tree-sitter can be much faster.
- Difwif 3y agoDo you keep the lsp semantic tokens capability enabled along with treesitter or only use treesitter for syntax highlights?