-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Session: don't return undefined if a response is required #17165
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
@@ -606,7 +606,7 @@ namespace ts.server { | |||
|
|||
const definitions = project.getLanguageService().getDefinitionAtPosition(file, position); | |||
if (!definitions) { | |||
return undefined; | |||
return []; |
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 these results mutable? Can we use a shared emptyArray
construct?
src/server/session.ts
Outdated
@@ -995,7 +995,7 @@ namespace ts.server { | |||
return args.position !== undefined ? args.position : scriptInfo.lineOffsetToPosition(args.line, args.offset); | |||
} | |||
|
|||
private getFileAndProject(args: protocol.FileRequestArgs, errorOnMissingProject = true) { | |||
private getFileAndProject(args: protocol.FileRequestArgs, errorOnMissingProject = true): { file: NormalizedPath, project: Project } { |
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.
Do we need the return type defined here, since it is correctly inferred?
Looks like the build is failing. Can you take a look? |
Fix is #17685, will merge once that's in |
@rbuckton Build is passing now, good to go? |
…17165) * Session: don't return undefined if a response is required * Use ReadonlyArray and emptyArray * Remove inferred return type
@@ -813,7 +815,7 @@ namespace ts.server { | |||
if (!renameInfo.canRename) { | |||
return { | |||
info: renameInfo, | |||
locs: [] | |||
locs: 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.
Missed one on line 812?
@@ -909,7 +911,7 @@ namespace ts.server { | |||
if (simplifiedResult) { | |||
const nameInfo = defaultProject.getLanguageService().getQuickInfoAtPosition(file, position); | |||
if (!nameInfo) { | |||
return undefined; |
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.
Might break deserialization.
@@ -1172,7 +1174,7 @@ namespace ts.server { | |||
|
|||
const completions = project.getLanguageService().getCompletionsAtPosition(file, position); | |||
if (!completions) { | |||
return undefined; |
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.
Might break deserialization.
@@ -615,7 +617,7 @@ namespace ts.server { | |||
} | |||
} | |||
|
|||
private getTypeDefinition(args: protocol.FileLocationRequestArgs): protocol.FileSpan[] { | |||
private getTypeDefinition(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.FileSpan> { |
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.
Line 627?
const { configFile, project } = this.getConfigFileAndProject(args); | ||
if (configFile) { | ||
return this.getConfigFileDiagnostics(configFile, project, args.includeLinePosition); | ||
} | ||
return this.getDiagnosticsWorker(args, /*isSemantic*/ true, (project, file) => project.getLanguageService().getSemanticDiagnostics(file), args.includeLinePosition); | ||
} | ||
|
||
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): protocol.DocumentHighlightsItem[] | DocumentHighlights[] { | ||
private getDocumentHighlights(args: protocol.DocumentHighlightsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.DocumentHighlightsItem> | ReadonlyArray<DocumentHighlights> { |
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.
Line 717?
@Andy-MS It might be safest to revert this (and hold off on #17727) until we further discuss the implications for clients. (cc: @minestarks, @rbuckton) |
Might be better to wait for |
Sequel to #16773
This doesn't yet fix
SignatureHelp
, since that doesn't return an array. I'm not sure if VSCode is depending on us sending back an "error" response if the user isn't currently at a signature.