-
Notifications
You must be signed in to change notification settings - Fork 98
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
feat: request autocompletion without typing a letter #310
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me overall. just would like to double check if we really need to instantiate the tree sitter parser with every request 😢. can't we just mutate the tree?
also: we will have a bunch of conflicts, and a few things will need to be handled differently. but no issues, just that we should merge yours first so I can fix the merge conflicts with mine.
sql.push(c); | ||
} | ||
|
||
let mut parser = tree_sitter::Parser::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isnt there a way to modify the tree sitter tree instead of reparsing the string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can pass the passer down to here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think editing the node isn to possible, so maybe we should try to pass the existing tree sitter parser down.
@psteinroe Curious about your opinion: I tried moving the We could make the |
ah sorry, i didn't mean to move the mapper there. I was thinking to clone or copy the tree sitter parser to skip the initialisation costs. Will look at the pr later, thanks for trying! 🙏🏼 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one detail, rest lgtm! I would say we go with constructing a new parser with every request for now and then check it later if we get problems.
@@ -24,3 +28,167 @@ impl IntoIterator for CompletionsResult { | |||
self.items.into_iter() | |||
} | |||
} | |||
|
|||
pub(crate) fn get_statement_for_completions<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't this be implemented as a Filter
in parsed_document
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because I need to peek into the next statement for the overlap check :/
If you have other ideas, let me know!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. maybe we can find a good abstraction for this but for now lets roll with this.
So far, we were relying on complete tree-sitter trees for autocompletion.
This works fine if you type the first letter of a node, say:
select * from u|
Now, the
u
is considered a table node, and we can look for tables.But this PR makes it such that we can also request completions if we haven't typed the
u
yet.It does so by checking whether the tree is valid and, if not, injecting a token to fix the tree-sitter tree.
Additionally, in the case of
select * from |
, the workspace would consider the cursor to be outside the statement. I added a little offset so the cursor still matches a statement if it's 2 characters after the last token.