Skip to content

feature: Snippet completions #1705

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

Closed
yaahc opened this issue Aug 19, 2019 · 12 comments
Closed

feature: Snippet completions #1705

yaahc opened this issue Aug 19, 2019 · 12 comments
Labels
A-completion autocompletion

Comments

@yaahc
Copy link
Member

yaahc commented Aug 19, 2019

currently, rls supports presenting completions for associated functions as snippets where you can jump through the various args.

Screenshot from 2019-08-19 12-05-11
Screenshot from 2019-08-19 12-05-22

rust-analyzer does not yet have this feature. Instead it will insert a pair of parens, and place the cursor between them if the function has 1 or more args, and after if the function has no args.

Screenshot from 2019-08-19 12-06-22
Screenshot from 2019-08-19 12-06-32

We should add support for snippets and do our best to at least support all the features that rls does with snippets and function completions.

@yaahc
Copy link
Member Author

yaahc commented Aug 19, 2019

More comments from @matklad on zulip

I can't give a super-thorogh mentoring instructions right now, but (besides dec docs in the repo) what you want to look at are:

@matklad
Copy link
Member

matklad commented Aug 22, 2019

@yaahc see #1715 which implements feature flags. In particular, "completion.insertion.add-call-parenthesis" controls "auto insert ()" behavior.

@bstaletic
Copy link
Contributor

Hello, I'm a maintainer of a client that doesn't support snippets. Currently rust-analyzer doesn't work because it always returns snippets on completion. I wanted to try completion.insertion.add-call-parenthesis and pretend that rust-analyzer isn't completing snippets, just to see how it works.

Sending {"completion.insertion.add-call-parenthesis":false} in initializationOptions didn't work, the () still got inserted. So how is this option supposed to be used?

@matklad
Copy link
Member

matklad commented Dec 10, 2019

@bstaletic at the moment, rust-analyzer doesn't support non-snippet based completion. Strictly speaking, this is a violation of the LSP protocol, which requires to consult the corresponding client capability before sending completion. However, at the moment we deliberately target "the latest" version of the protocol (more discussion here). I've opened #2518 to add proper support here.

What completion.insertion.add-call-parenthesis feature does is removing a specific snippet some users find annoying, it does not disable all snippets. However, looking at the code, it seems like it should fall back to plain completion in this snippet.

I think the problem is that you need to nest insertion into featureFlags key. See sublime example here: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/README.md#sublime-text-3. I would argue that this featureFlags nesting makes sense from the implementation point of view, but, UI-wise, you are not the first person confused with it... We should remove this nesting on the surface some day.

@bstaletic
Copy link
Contributor

@matklad Thanks for opening #2518, I did leave my thoughts regarding snippets there.

@flodiebold flodiebold added the A-completion autocompletion label Dec 26, 2019
@Avishayy
Copy link
Contributor

I guess no one wants to implement this yet; I'll bite the bullet and attempt to implement this as my first issue, anything I should know?

@matklad
Copy link
Member

matklad commented Feb 29, 2020

I believe #1705 (comment) still lists the most relevant things.

@Avishayy
Copy link
Contributor

I see, thank you.

@kjeremy
Copy link
Contributor

kjeremy commented Mar 3, 2020

bors bot added a commit that referenced this issue Mar 4, 2020
3432: Feature/snippet completions r=matklad a=iTZAvishay

This PR implements #1705 and is based on #3430 to avoid future conflicts.

The completions are placing default values with the names of the parameters, demo: 
![call_me_demo](https://user-images.githubusercontent.com/5567310/75828341-461ca400-5db4-11ea-88d8-88e59ac1a197.gif)


Co-authored-by: Avishay Matayev <[email protected]>
@justinas
Copy link

Having #3432 merged, what is left to fully support snippets?

@Ten0
Copy link

Ten0 commented Apr 21, 2020

Hmm I beleive RLS supports a derive snippet and other things of the same kind, which would be useful to add as well :)

@matklad
Copy link
Member

matklad commented Apr 22, 2020

Yeah, I belive the original issue is fixed. For code snippets, which is a different feature from completion, my general stance is that they are often (but not always) a work-around for a missing feature in and IDE.

For derive specifically, see #4015

@matklad matklad closed this as completed Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion autocompletion
Projects
None yet
Development

No branches or pull requests

8 participants