Skip to content

New CompletionTriggerKind to distinguish manual and automatic invocation. #1791

Open
@ddickstein

Description

@ddickstein

The current specification for CompletionTriggerKind specifies the enum value 1 as:

/**
* Completion was triggered by typing an identifier (24x7 code
* complete), manual invocation (e.g Ctrl+Space) or via API.
*/
export const Invoked: 1 = 1;

I think it is valuable to be able to distinguish between these cases. For example, there may be situations in which you do not want to provide 24x7 code completion because it's less likely what the user wants, yet you still want to provide completion results to the user when they explicitly ask for it.

A motivating example here is what to do when the user is choosing argument names for a new function definition. On the one hand, because the user is defining the function from scratch, existing identifiers in the code from other contexts don't have any bearing on what the arguments for this new function might be. On the other hand, there might be a certain value that the user is passing around to several functions, and it could be helpful to use the same name in all places. So when the user explicitly asks for completion, we want to provide it.

Another example is what to do when the user is naming a variable or function. The same point applies - the user is defining a fresh variable or function, so completing existing variables or functions is unlikely to be helpful. However, the user might be intentionally shadowing a variable or function, and in that case completion can be helpful.

I have less of a sense of whether it could be valuable to distinguish the 24x7 and API cases, but I also think it's more helpful than harmful to have the protocol draw distinctions and let language servers conflate them as they see fit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions