Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: request autocompletion without typing a letter#310

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
juleswritescode merged 13 commits intomainfromfeat/autocompl
Apr 13, 2025

Conversation

juleswritescode
Copy link
Collaborator

@juleswritescodejuleswritescode commentedApr 4, 2025
edited
Loading

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, theu 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 theu 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 ofselect * 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.

@juleswritescodejuleswritescode changed the titleso far…improve auto completionsApr 4, 2025
@juleswritescodejuleswritescode marked this pull request as ready for reviewApril 11, 2025 10:49
@juleswritescodejuleswritescode changed the titleimprove auto completionsfeat: request autocompletion without typing a letterApr 11, 2025
Copy link
Collaborator

@psteinroepsteinroe left a 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();
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Collaborator

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.

@juleswritescode
Copy link
CollaboratorAuthor

juleswritescode commentedApr 11, 2025
edited
Loading

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?

I think I would shy away from that – we would mutate the tree that is also used for other features… seems like a source of very annoying bugs :/

Also, keep in mind that:

  1. the statement is likely pretty small and the parsing should happen quickly and
  2. that we don't need to create a tree and will reuse the existing one if the user has already written a letter.

I added some benchmarks – on my machine, reusing the old treesitter takes about 500 nanoseconds, and creating a new one about 5-150 microseconds depending on the size of the sql.

Screenshot 2025-04-11 at 18 32 12

I mean, I can play a Counterspell when I see a hakbal in about that time, but I wouldn't mind waiting that long for completions

@juleswritescode
Copy link
CollaboratorAuthor

juleswritescode commentedApr 12, 2025
edited
Loading

@psteinroe Curious about your opinion: I tried moving theGetCompletionsMapper into the completions crate, but then I couldn't access theparser.cst_db because that's private. But it's weird to write feature-functions and comments into the parsed_document I think :/

We could make theparser.cst_db public, or provide aparser.get_tree() method, or leave the mappers in the crate… what do you think?

@psteinroe
Copy link
Collaborator

psteinroe commentedApr 12, 2025
edited
Loading

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! 🙏🏼

Copy link
Collaborator

@psteinroepsteinroe left a 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.

juleswritescode reacted with thumbs up emoji
@juleswritescodejuleswritescode merged commitd439c36 intomainApr 13, 2025
7 checks passed
@psteinroepsteinroe mentioned this pull requestApr 15, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@psteinroepsteinroepsteinroe approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@juleswritescode@psteinroe

[8]ページ先頭

©2009-2025 Movatter.jp