JS: propose semantically sensible completions
The JavaScript language server should only propose completions that semantically might make sense at that position. In particular, my issue is that global or local identifiers should not be proposed at a position immediately following an identifier and a dot:
A completion after the text http. should not propose http, process, or any other words that make sense only as identifiers themselves, but not necessarily as a property. By contrast, createServer might be proposed here.
Example: Consider the following JS file content:
var http = require("http");
http.
If you now trigger a textDocument/completion with params.position = {line: 1, character: 5}, there will be a response containing a CompletionItem with label: "http".
I am not saying that the LS must propose all the possible properties, as it is well-known that they would be very hard to determine statically for JavaScript. What I am saying is that names that are found in e.g. global or local scope are not suitable in general as property names to any object and thus should not be proposed.
Edit: One might imagine that the completions http or process at a position after the string http. (example above) are meant as replacements for the existing string http.; i.e., http. would become process, for example. Such semantics of the LS would not make any sense, I think, because if I type http. and trigger a completion, I do want the string that I've already typed to remain and to be considered part of the final text.
Edit: Alternatively, if no differentiation with respect to the prefix is possible, I would request sending a textEdit instead of label or insertText, with a range that includes the existing prefix, e.g.:
range: {
start: { line: 1, character: 0 },
end : { line 1, character : 5 }
},
newText: "process"
(See also issue #490.)
This sounds like a duplicate of #432
So what's the solution proposal? Will it stay that way? All those issues marked as duplicates to #432, and #432 itself, seem to deal with the application in tools such as VSCode.
What I am concerned about is not what some tool displays as completions, but what I get from the language server.
Should I open a PR?
#432 was resolved as being a bug in neovim, which wouldn't send the right textDocument/didChange. If you believe it is not, do you have a full log of the communication? Which client are you using?
I'm using a custom client. Here's the communication between client and server:
request:
response:
file a.js:
console.log
As you can see, the completion was triggered after the dot.
Could you please post full logs (including initialize, didOpen, etc)? Preferrably as a text file. The language server has a command line option to log all communication to a file.
Changed title again as your last edit was misleading; I don't want the LS to propose "stand-alone" identifiers (non-properties) after a dot (leading to <some object>.<another object>), as outlined in the initial comment.
Will update this with logs as soon as I find the time.
In the meantime I've stumbled upon the strict flag. This might do what I want. However I cannot simply set it when requireing lib/language-server-stdio.js as I currently do (this being another story).