Using tree-sitter to assist LSP completion #3346
-
Hey 👋 I hope it's ok to ask questions here! I am working on a creating a tree-sitter for SurrealQL the query language of SurrealDB. I have started the grammar. It is very much a work in progress. While working on the grammar, I wanted to see if I could use my newly created tree-sitter as a parser for an LSP I am building. I am trying to implement completion and failing miserably (this is my first time with tree-sitter and LSPs 😆 ). Does anyone have any advice? I have some examples of what I am trying to achieve: "X" is a place holder for where the cursor will be:
1. SELECT X
Completion list would be ["VALUE"]
2. SELECT amount FROM payments X
Completion list should be ["ORDER BY", "WHERE", "SPLIT", "GROUP BY"]
3. SELECT amount FROM payments:cellan X
Completion list should be ["ORDER BY", "WHERE", "SPLIT", "GROUP BY"] Essentially, I want to get the closest previous node to the cursor. I can map the node to the values I want to populate for completion. However, when I parse the code the node kind for value X "source_file". Do I need to walk the cursor, should I query the tree, or should I take a completely different approach? I am not sure if it is the way my grammar is set up or I am going about this the wrong way. Any advice would be appreciated! 🙏🏻 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I added some rudimentary completion capabilities to asm-lsp using tree-sitter's rust bindings. The basic building blocks for this were:
To give some more concrete info, in asm-lsp: Hope this is helpful :) |
Beta Was this translation helpful? Give feedback.
I added some rudimentary completion capabilities to asm-lsp using tree-sitter's rust bindings. The basic building blocks for this were:
tree…