-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fixes to session's handling of empty results #17728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/server/session.ts
Outdated
@@ -809,7 +809,7 @@ namespace ts.server { | |||
// The rename info should be the same for every project | |||
const renameInfo = defaultProject.getLanguageService().getRenameInfo(file, position); | |||
if (!renameInfo) { | |||
return undefined; | |||
return emptyArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we confident that callers expecting a protocol.RenameResponseBody
won't hit this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh, got the meaning of simplifiedResult
backwards.
@@ -714,7 +714,7 @@ namespace ts.server { | |||
const documentHighlights = project.getLanguageService().getDocumentHighlights(file, position, args.filesToSearch); | |||
|
|||
if (!documentHighlights) { | |||
return undefined; | |||
return emptyArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -624,7 +624,7 @@ namespace ts.server { | |||
|
|||
const definitions = project.getLanguageService().getTypeDefinitionAtPosition(file, position); | |||
if (!definitions) { | |||
return undefined; | |||
return emptyArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -901,7 +901,7 @@ namespace ts.server { | |||
} | |||
} | |||
|
|||
private getReferences(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.ReferencesResponseBody | ReadonlyArray<ReferencedSymbol> { | |||
private getReferences(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.ReferencesResponseBody | undefined | ReadonlyArray<ReferencedSymbol> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we are okay with returning undefined
on success?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really have a way to return a ReferencesResponseBody
if the cursor wasn't at a valid location. It would be nice if we had some way to indicate a non-result in a way that's distinguishable from a crash in services.
if (simplifiedResult) { | ||
return mapDefined(completions.entries, entry => { | ||
return mapDefined(completions && completions.entries, entry => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have thought we'd want to return emptyArray
when !completions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mapDefined
always returns a defined result.
Assuming we're okay with returning |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ref: #17165 (review)