LanguageServer.jl
LanguageServer.jl copied to clipboard
Suppress exact matches in identifier completions
When you type a new identifier, for example a struct or function definition, there is one completion item with the exact part of the name that you have already typed. This will update after each key stroke, because CompletionList.isIncomplete is always set to true, so the client will continuously re-request completions:
https://github.com/julia-vscode/LanguageServer.jl/blob/864e4efde07611e309d315cf180003155ac990ad/src/requests/completions.jl#L98
Example screenshot from VSCode:
If you confirm this completion, nothing happens because it just replaces the typed identifier, which already was the exact same text. Even if you haven't typed the end yet, it won't be inserted for you. So I think this completion item is pretty useless and could be removed. (In Sublime the popup heavily flickers if there are no other completions visible, and I wasn't able to find a good workaround for that on the client side).
I was able to remove the completion by excluding exact matches at https://github.com/julia-vscode/LanguageServer.jl/blob/864e4efde07611e309d315cf180003155ac990ad/src/requests/completions.jl#L262
like this:
--- a/src/requests/completions.jl
+++ b/src/requests/completions.jl
@@ -259,7 +259,7 @@ function collect_completions(x::StaticLint.Scope, spartial, state::CompletionSta
possible_names = String[]
for n in x.names
resize!(possible_names, 0)
- if is_completion_match(n[1], spartial)
+ if is_completion_match(n[1], spartial) && n[1] != spartial
push!(possible_names, n[1])
end
if (nn = string_macro_altname(n[1]); nn !== nothing) && is_completion_match(nn, spartial)
Although I don't know where the x.names exactly come from or whether there is a better solution.