-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
CompletionItem - multiple text edits, onDidAcceptCommand #6874
Comments
[ |
I like the idea of running a command since it allows for cases like downloading a typings file. But there are lot of cases as well that only need to apply multiple edits. Could we have both, providing an array of edits or an command. |
yes - I came to the same conclusion, esp when a command also wants to modify the current text document. Coordinating a command and a text edit would be hairy... |
Agree on the coordination command and text. That is why I would do exclusive or. |
@DustinCampbell fyi |
sounds great! |
Also, there is a little know thing with completions and that is placeholders... It's undocumented and somewhat internal but it would be easy to make it like snippets. That is a completion can contain placeholders, tab positions, and the final cursor position. Like so:
It would do something like this: For instance for method completion a powerful language brain could already propose arguments for function calls etc |
I really like this idea. I'm currently at the state that I'm inserting the wanted symbol at the place with the CompletionItemProvider and then let the 👍 Cheers |
@DustinCampbell @buehler We have a way to get into a 'snippet mode' when accepting a completion - that's multiple potentially linked cursors after selecting an item. We have them to help with subsequent edits and we plan to make them official (#3210). Snippet mode does conflict with additional edits and we will likely not allow both in one completion. Would that be a problem for you guys? |
For now, fine by me :-) I dunno if this answers your question... Cheers |
Yeah, thanks. Multiple text edits is definitely on our list, the import-scenario is what we are looking at but also want to think a little out of the box |
Cool! |
There is an undocumented feature which we lend from text mate snippets. Basically, you can use a special syntax in your completion and the editor will enter a snippet mode. See this sample:
The double-curly-bracket is somewhat internal but we plan to allow more of the text mate snippet syntax in completions. Combining that with additional edits is tricky |
I'm primarily looking for a way to provide C# completion on 1. Before completion: 2. After completion: Implementing this properly requires the following:
I'm not sure snippets will achieve the desired result. |
Oh shiny 👍 |
fyi @DustinCampbell With this hacked-up completion item provider (note that the filter text must be set) languages.registerCompletionItemProvider('csharp', {
provideCompletionItems(doc, pos) {
const range = doc.getWordRangeAtPosition(pos);
const word = doc.getText(range);
if (word === 'override') {
const item = new vscode.CompletionItem('M1()', vscode.CompletionItemKind.Method);
item.textEdit = vscode.TextEdit.replace(range, 'protected override void M1()\n{\n\tthrow new NotImplementedException();{{}}\n}')
item.additionalTextEdits = [vscode.TextEdit.insert(new vscode.Position(0, 0), 'using System;\n')];
item.filterText = word;
return [item];
}
}
}); Still on my list
|
@jrieken I notice your current implementation has a command running after the text edit is made - I think that should enable my use case, where the additional edit (again inserting/modifying an import statement) is made via an external language service (ie provided asynchronously only after an individual completion is selected). Am I right in that? I think it could be a common enough case. |
Yes and no. If you want to make additional modifications to the document I d recommend to use the
I'm obviously just guessing because I don't know anything about your language service but if you have a chance to compute those additional edits during the first request do it ;-) Last, you might be interested in #10561 which is about expanding a snippet when being inserted. |
@jrieken Unfortunately that's not possible if all edits must be provided for all completion items up front - rather than eg as a promise on the completion item (or at least the downsides you list are more acceptable than having to do so). |
Running an async aftermath command isn't a show stopper. Make sure to use small edits and compare the document version before and after the long running operation. |
Very pretty @jrieken! |
Closing. The remaining work is #10561 |
We should investigate if we should allow running a command on suggest. That would allow for more advanced code actions, like 'add import', 'download typing files' etc on completion. An alternative would be the
onDidExecuteCommand
event which folks ask for. Internally accepting a completion is a command - if we broadcast that someone else could run a followup command.The text was updated successfully, but these errors were encountered: