Skip to content

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

Merged
3 commits merged into from
Aug 14, 2017
Merged

Fixes to session's handling of empty results #17728

3 commits merged into from
Aug 14, 2017

Conversation

ghost
Copy link

@ghost ghost commented Aug 10, 2017

@ghost ghost requested a review from amcasey August 10, 2017 19:42
@@ -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;
Copy link
Member

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?

Copy link
Author

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;
Copy link
Member

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;
Copy link
Member

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> {
Copy link
Member

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?

Copy link
Author

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 => {
Copy link
Member

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.

Copy link
Author

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.

@amcasey
Copy link
Member

amcasey commented Aug 10, 2017

Assuming we're okay with returning undefined bodies when a response is required, this change looks better than #17727.

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ghost ghost merged commit 80a7ed9 into master Aug 14, 2017
@ghost ghost deleted the session branch August 14, 2017 20:42
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants