Skip to content
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

Make the completion trigger character conditional #1413

Open
jdneo opened this issue Feb 16, 2022 · 9 comments
Open

Make the completion trigger character conditional #1413

jdneo opened this issue Feb 16, 2022 · 9 comments
Labels
completion feature-request Request for new features or functionality
Milestone

Comments

@jdneo
Copy link
Member

jdneo commented Feb 16, 2022

This is a feature request to make the completion trigger character take effect conditionally.

Considering the following Java code:

String s = new |

When user enter the space, it would be helpful to show a completion list. This behavior can be observed in other IDEs:

completion

But simply adding space to the trigger characters could be a problem because not every space needs to follow a completion action.

Is it possible to make it conditional? For example, only taking effect when there is a "new" before space.

@rcjsuen
Copy link
Contributor

rcjsuen commented Feb 16, 2022

@jdneo I do not believe this is possible. This question/request may be more appropriate for the microsoft/language-server-protocol repository.

@jdneo

This comment was marked as off-topic.

@dbaeumer dbaeumer transferred this issue from microsoft/vscode-languageserver-node Feb 21, 2022
@dbaeumer dbaeumer added feature-request Request for new features or functionality completion and removed feature-request Request for new features or functionality labels Feb 21, 2022
@dbaeumer
Copy link
Member

@jrieken has this come up in VS Code ?

@hrsh7th
Copy link

hrsh7th commented Feb 21, 2022

The lua-language-server achives the similar functionality.
That LS specified the as triggerCharacter and textDocument/completion returns context-aware completion response.

@jdneo
Copy link
Member Author

jdneo commented Feb 21, 2022

Share one more information. I observed the ms-dotnettools.csharp also implemented this feature.

Currently in Java, we are planning to add " " as a trigger character and looking backward to see if it's "new " at where the completion is triggered.

@puremourning
Copy link

In ycmd triggers were always regex based. LSP using a single character has always seemed limiting (think, even c -> and c++ ::). Adding space as a trigger character is a bad idea imo as semantic completion requests can be quite slow, particularly for ‘global scope’ in many languages. And this is going to lead to a lot of pointless requests.

I think a protocol supported regex trigger would be better. Or just press a manual trigger.

@jrieken
Copy link
Member

jrieken commented Feb 21, 2022

@jrieken has this come up in VS Code ?

Yes, it has come up in the past but not in recent years. I believe extension use the last character of their words like > of -> and check the prefix themselves. We can consider adding support for longer prefix strings but I am unsure about regex because it comes at a certain cost.

@hrsh7th
Copy link

hrsh7th commented Feb 21, 2022

I'm against regular expressions. I think there are many dialects and some clients cannot handle it.

The advantage of a single character is that it can be handled by the editor's keypress handler.
However, if we make the space a trigger string, we may consider that the completion request runs indented...

@puremourning
Copy link

puremourning commented Feb 21, 2022

FWIW, these are the regex triggers that ycmd uses by default. We add the 'trigger characters' provided by LSP servers to these lists dynamically: https://github.com/ycm-core/ycmd/blob/master/ycmd/completers/completer_utils.py#L180-L211 (for some languages we actually ignore them, as they are inferior in practice to our hard-coded ones).

The LSP already includes a regular expression syntax, defined to be some subset of javascript's (https://microsoft.github.io/language-server-protocol/specifications/specification-current/#regExp). Anyway, I do tend to agree that is somewhat unfortunate and in practice (as you see above) most expression are just "multiple characters" rather than actually complex expressions.

Perhaps the 'trigger characters' could be augmented with alternative "trigger prefixes" which is to say "Trigger if the prefix at the current cursor position matches these characters". The challenge there is that the "whitespace" trigger that prompted this request no longer works if you enter multiple spaces as in X x = new <space><space><space><here> (whereas it's trivial with a regex)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completion feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

6 participants