[TSServer] Completion trigger characters #21012
Labels
Committed
The team has roadmapped this issue
Fixed
A PR has been merged for this issue
Suggestion
An idea for TypeScript
VS Code Tracked
There is a VS Code equivalent to this issue
Milestone
TL;DR: Add the concept of a triggerCharacter for completions. Update the TS Server so that it uses the triggerCharacter to determine if completions should be returned at the requested location or not
Background
VS Code uses trigger characters to automatically show suggestions as a user types. Registering
"
as a trigger character for example means that suggestions are shown automatically whenever a user types"
.The VS Code TS extension uses these trigger character to determine if we should request completions from TS Server. For the trigger character
"
for example, the VS Code TS extension has logic so that it only requests completions when you start typing an import path:and not when you type out a string #like:
This is because the TS Server still returns completion entires in the second case, and we want to ensure these do not show up unless a user explicitly requests them.
The TS Server currently has no knowledge of what triggered a completions request.
Problem
The VS Code TS extension's logic that determines when to request completions from the TSServer is very simple. It just runs some regular expressions on the current line to check if they resemble a valid auto-suggest context. This works well enough for limiting the
"
trigger to import paths, but there are other cases where this is too limiting.Take:
TS can provide helpful suggestions here but we do not show them automatically because triggering on every
"
would show suggestions in too many locations (like for the case"abc"|
noted above).Another example would be microsoft/vscode#40539 which tracks showing jsx tag suggestions automatically when you type
<
. Again, VS Code cannot just blindly register<
as a trigger character, as this would cause suggestions to be shown whenever you type a less-than operator in an expression.Proposal
Make the TS server trigger character aware. Use the trigger character information and TypeScript's more complete understanding of the current document to determine when to return completions and when not to.
When the trigger character is
"
for example, the TS server would return completions for import paths like:and for literal types like:
but not for strings:
A similar check could be done for the triggerCharacter
<
, which should only return completions when the<
is used as a jsx tag opening.To implement this, add a new optional
triggerCharacter
field toCompletionsRequestArgs
When a triggerCharacter is provided, use this to determine if completions should be returned or not. If the triggerCharacter is
undefined
, there would be no change from the existing behaviorThe text was updated successfully, but these errors were encountered: