Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

JS: propose semantically sensible completions #489

Open
@yeahio

Description

@yeahio

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.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions