-
Notifications
You must be signed in to change notification settings - Fork 49
TODO: Auto calculate startcol via cm_refresh_patterns #30
Comments
It would be interesting to see how VS code and language server protocol implements this |
Yeah, It seems there's no concept of |
LSP has |
IMO, the pattern is for the framework figuring out when to notify the source and then get the popup. It is useful, and should be configurable. For example, there are users who want longer typing to trigger completion popup, to keep themselves from distraction.
It is also possible for NCM to have |
VsCode completion is very fast even though it is running js. So I created a vscode extension and played around with how it works. export function activate(context: vscode.ExtensionContext) {
const PLAIN_TEXT: vscode.DocumentFilter = { language: '*', scheme: 'untitled' };
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(PLAIN_TEXT, new MyCompletionItemProvider(), 'c'));
}
export class MyCompletionItemProvider implements vscode.CompletionItemProvider {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionList> {
return new Promise<vscode.CompletionList>(resolve => {
const items: vscode.CompletionItem[] = [
new vscode.CompletionItem("test"),
new vscode.CompletionItem("test2"),
new vscode.CompletionItem("abcdef"),
new vscode.CompletionItem("abcdefgh"),
];
resolve(new vscode.CompletionList(items, false));
});
}
}
I put a breakpoint at https://github.com/Microsoft/vscode/blob/2540cbb603f25e5a8f92c8d0657646c77540dfef/src/vs/editor/common/model/wordHelper.ts. There is a default word pattern so the completion provider doesn't need to specify it. go completion for vscode seems to do extra computation before actually asking the server https://github.com/Microsoft/vscode-go/blob/798da91e2708df4bb56d6dda764515682a2e51e3/src/goSuggest.ts#L51 |
@prabirshrestha I'll consider adding default word pattern. VIM has It would still be nice to reuse this option. Then buffer keyword completion would be more sensible for the buffer. |
So this should be the reason for being very fast? By caching the completion results early (the start of a word) before displaying the popup menu (after specific amout of characters being typed)? |
If you have code installed creating an extension and debugging should be very easy. They recently officialy added Seems like they cache at start of the word before displaying the popupmenu but doesn't wait for specific amount of characters being typed or wait for a timer. Here are the things I tried and noticed.
Each completion provider can provide optional addition list of trigger characters. Theoretically this same could be used instead of export const USUAL_WORD_SEPARATORS = '`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?';
/**
* Create a word definition regular expression based on default word separators.
* Optionally provide allowed separators that should be included in words.
*
* The default would look like this:
* /(-?\d*\.\d\w*)|([^\`\~\!\@\#\$\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g
*/
function createWordRegExp(allowInWords: string = ''): RegExp {
var usualSeparators = USUAL_WORD_SEPARATORS;
var source = '(-?\\d*\\.\\d\\w*)|([^';
for (var i = 0; i < usualSeparators.length; i++) {
if (allowInWords.indexOf(usualSeparators[i]) >= 0) {
continue;
}
source += '\\' + usualSeparators[i];
}
source += '\\s]+)';
return new RegExp(source, 'g');
}
// catches numbers (including floating numbers) in the first group, and alphanum in the second
export const DEFAULT_WORD_REGEXP = createWordRegExp(); Provide completion items can return /**
* Represents a collection of [completion items](#CompletionItem) to be presented
* in the editor.
*/
export class CompletionList {
/**
* This list it not complete. Further typing should result in recomputing
* this list.
*/
isIncomplete: boolean;
/**
* The completion items.
*/
items: CompletionItem[];
} Now this finally makes sense to me why LSP interface is the way it is. Here are other interesting tricks to make it fast that are not related to
Seems like the function should be changed to something like |
I've already changed the function parameters in order to work with LSP server, https://github.com/roxma/nvim-completion-manager/blob/master/doc/nvim-completion-manager.txt#L261 The startcol should stay. In this way, |
default_word_pattern is already implemented here. Other optimizations for speed are omitted currently for simplicity. |
Early caching for candidates has been implemented now. Warm up at startup does not seems to be NCM's duty, I think I should leave it to the source implementation. The NCM python source framework can receive buffer events so it should be able to implement it easilly. |
Related startcol issue autozimu/LanguageClient-neovim#15 (comment) The default word pattern by NCM does not work for php language server, since PHP variable start's with |
looking at the source of language provider I see $serverCapabilities->completionProvider->triggerCharacters = ['$', '>']; Once the server is initialized and you have to add these two characters as part of trigger and it should work. |
@prabirshrestha Thanks for the information! |
… server capabilities triggerCharacters. thanks to @prabirshrestha, related links: roxma/nvim-completion-manager#30 (comment), #15
couldn't the regex be changed to just splitting on not alnum ? I don't know the spec for what is in the list though |
I'm wondering on this too. Maybe it takes care of unicode character better. |
in vimregex : |
…ased on the last matching group of cm_refresh_patterns. It could easily lead to confusion. #30
This is the cm_refresh_pattern of bufkeyword currently:
The framework should be able to calculate startcol using the last matching group of the pattern, if the pattern is changed into this:
Props:
Cons:
The text was updated successfully, but these errors were encountered: