TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Handle undefined `location.parent` when getting completionEntryDetails

Open MariaSolOs opened this issue 2 years ago • 6 comments

Fixes #54106

MariaSolOs avatar May 04 '23 21:05 MariaSolOs

Tests are pending because I don't know how to test completionEntryDetails. verify.completions seems to only check completionInfo, and I cannot use the resulting andApplyCodeAction because the entry I want to test doesn't have a description or source (which are needed in the parameter options).

MariaSolOs avatar May 04 '23 21:05 MariaSolOs

Where is this location coming from? All source files should be bound and have parents, so is this location the SourceFile itself?

jakebailey avatar May 04 '23 21:05 jakebailey

Where is this location coming from? All source files should be bound and have parents, so is this location the SourceFile itself?

Correct. So with the example from the bug:

/**/
type lolol = any;
declare const lolol: any;

When explicitly requesting completions in /**/, location will be the source file itself, which causes the error in the line I'm changing.

MariaSolOs avatar May 04 '23 21:05 MariaSolOs

@jakebailey @DanielRosenwasser @andrewbranch any hints on how I can test this with fourslash?

MariaSolOs avatar May 04 '23 21:05 MariaSolOs

Are the details in https://github.com/microsoft/TypeScript/blob/main/tests/cases/fourslash/completionsObjectLiteralMethod2.ts what you're trying to get at?

jakebailey avatar May 04 '23 22:05 jakebailey

Are the details in https://github.com/microsoft/TypeScript/blob/main/tests/cases/fourslash/completionsObjectLiteralMethod2.ts what you're trying to get at?

Hmm no this isn't helping me here. The completion entry remains the same with and without my change, like I need to simulate selecting the actual completion to trigger the failure.

MariaSolOs avatar May 04 '23 22:05 MariaSolOs

Okay I was able to test this with verify.baselineCompletions(). You were right @iisaduan!

MariaSolOs avatar May 05 '23 19:05 MariaSolOs