Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
81ec4fd
Prototype resolving to JS when go-to-def aliases all resolve to ambie…
andrewbranch Feb 25, 2022
422d845
Add test infrastructure
andrewbranch Mar 1, 2022
1b43352
Start fleshing out test coverage
andrewbranch Mar 2, 2022
7aeb92f
Fix some go-to-def stuff
andrewbranch Mar 8, 2022
f2915e6
Finish lodash test case
andrewbranch Mar 10, 2022
309c4bb
Make go-to-implementation never return ambient results
andrewbranch Mar 10, 2022
381799d
Build new functionality into go-to-implementation
andrewbranch Mar 11, 2022
0727702
Update baselines
andrewbranch Mar 11, 2022
ebeda0b
Two more test cases
andrewbranch Mar 14, 2022
03ea413
Refine definition searches for unresolved imports
andrewbranch Mar 14, 2022
e5556b8
Revert "Build new functionality into go-to-implementation"
andrewbranch Mar 14, 2022
6104a5c
Fix tests
andrewbranch Mar 14, 2022
bea3de0
Merge branch 'main' into go-to-js
andrewbranch Mar 14, 2022
4e64659
Revert go-to-implementation changes
andrewbranch Mar 14, 2022
1cb2ba6
Wow a bunch of code was unnecessary
andrewbranch Mar 14, 2022
7e57890
Update baselines and go-to-def test
andrewbranch Mar 15, 2022
43c01e2
Fix navigation on symbols that are not aliases but resolve through al…
andrewbranch Mar 16, 2022
34c6cfd
Temporarily replace go-to-def with new command implementation
andrewbranch Mar 15, 2022
7357593
Revert "Temporarily replace go-to-def with new command implementation"
andrewbranch Mar 16, 2022
d14e43d
Revert "Wow a bunch of code was unnecessary"
andrewbranch Mar 21, 2022
4e1cf1c
Bring back some deleted code needed for a new test case
andrewbranch Mar 21, 2022
52a79d5
Clean up a little
andrewbranch Mar 22, 2022
e011f2d
Rename more stuff
andrewbranch Mar 22, 2022
05cfd27
Update test
andrewbranch Mar 22, 2022
b95f496
Update API baseline
andrewbranch Mar 22, 2022
b883898
Temporarily replace go-to-def with new command implementation
andrewbranch Mar 15, 2022
373bca2
PR review fixes
andrewbranch Apr 4, 2022
c05adbd
Merge branch 'main' into go-to-js
andrewbranch Apr 4, 2022
3a85dc8
Fix getTopMostDeclarationNamesInFile
andrewbranch Apr 4, 2022
7dd9db8
Rename local
andrewbranch Apr 4, 2022
0f3b29c
Use hash set
andrewbranch Apr 4, 2022
234c139
Remove option from commandLineParser
andrewbranch Apr 4, 2022
92ff999
Merge branch 'main' into go-to-js
andrewbranch Apr 6, 2022
1698930
Keep noDtsResolution project around
andrewbranch Apr 7, 2022
859ed79
Handle AuxiliaryProject kind in ScriptInfo getDefaultProject etc.
andrewbranch Apr 7, 2022
7be215a
Do not run updateGraph in the background for AuxiliaryProject
andrewbranch Apr 7, 2022
8f4e622
Don’t create auxiliary project outside of semantic mode
andrewbranch Apr 7, 2022
d633356
No-op on scheduled invalidation
andrewbranch Apr 7, 2022
b89b7cb
Add comments to unit test
andrewbranch Apr 7, 2022
a59024c
Sync compiler options to auxiliary project
andrewbranch Apr 7, 2022
7f290bb
Fix case sensitivity
andrewbranch Apr 7, 2022
c5bddbe
Update extensionIsOk with new file extensions
andrewbranch Apr 7, 2022
24c0d8a
PR feedback
andrewbranch Apr 13, 2022
f6bd9d8
Update API baseline
andrewbranch Apr 13, 2022
2cb2048
Mark scheduleInvalidateResolutionsOfFailedLookupLocations internal
andrewbranch Apr 13, 2022
f9f4592
Use same heuristics on property accesses of loosely-resolvable aliase…
andrewbranch Apr 14, 2022
e302f56
Rename command, and no need to return the bound span
andrewbranch Apr 14, 2022
3f15ed3
Update API baseline
andrewbranch Apr 14, 2022
f80c9ef
Merge branch 'main' into go-to-js
andrewbranch Apr 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename command, and no need to return the bound span
  • Loading branch information
andrewbranch committed Apr 14, 2022
commit e302f56b62b097ca3ba340f6479c3199772e7b2d
27 changes: 12 additions & 15 deletions src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,21 @@ namespace ts.server {
}));
}

getSourceDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan {
getSourceDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfo[] {
const args: protocol.FileLocationRequestArgs = this.createFileLocationRequestArgs(fileName, position);
const request = this.processRequest<protocol.SourceDefinitionAndBoundSpanRequest>(CommandNames.SourceDefinitionAndBoundSpan, args);
const response = this.processResponse<protocol.DefinitionInfoAndBoundSpanResponse>(request);
const request = this.processRequest<protocol.FindSourceDefinitionRequest>(CommandNames.FindSourceDefinition, args);
const response = this.processResponse<protocol.DefinitionResponse>(request);
const body = Debug.checkDefined(response.body); // TODO: GH#18217

return {
definitions: body.definitions.map(entry => ({
containerKind: ScriptElementKind.unknown,
containerName: "",
fileName: entry.file,
textSpan: this.decodeSpan(entry),
kind: ScriptElementKind.unknown,
name: "",
unverified: entry.unverified,
})),
textSpan: this.decodeSpan(body.textSpan, request.arguments.file)
};
return body.map(entry => ({
containerKind: ScriptElementKind.unknown,
containerName: "",
fileName: entry.file,
textSpan: this.decodeSpan(entry),
kind: ScriptElementKind.unknown,
name: "",
unverified: entry.unverified,
}));
}

getImplementationAtPosition(fileName: string, position: number): ImplementationLocation[] {
Expand Down
8 changes: 3 additions & 5 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ namespace ts.server.protocol {
SignatureHelp = "signatureHelp",
/* @internal */
SignatureHelpFull = "signatureHelp-full",
SourceDefinitionAndBoundSpan = "sourceDefinitionAndBoundSpan",
/* @internal */
SourceDefinitionAndBoundSpanFull = "sourceDefinitionAndBoundSpan-full",
FindSourceDefinition = "findSourceDefinition",
Status = "status",
TypeDefinition = "typeDefinition",
ProjectInfo = "projectInfo",
Expand Down Expand Up @@ -907,8 +905,8 @@ namespace ts.server.protocol {
readonly command: CommandTypes.DefinitionAndBoundSpan;
}

export interface SourceDefinitionAndBoundSpanRequest extends FileLocationRequest {
readonly command: CommandTypes.SourceDefinitionAndBoundSpan;
export interface FindSourceDefinitionRequest extends FileLocationRequest {
readonly command: CommandTypes.FindSourceDefinition;
}

export interface DefinitionAndBoundSpanResponse extends Response {
Expand Down
39 changes: 7 additions & 32 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1229,14 +1229,11 @@ namespace ts.server {
};
}

private getSourceDefinitionAndBoundSpan(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.DefinitionInfoAndBoundSpan | DefinitionInfoAndBoundSpan {
private findSourceDefinition(args: protocol.FileLocationRequestArgs): readonly protocol.DefinitionInfo[] {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
const scriptInfo = Debug.checkDefined(project.getScriptInfo(file));

const unmappedDefinitionAndBoundSpan = project.getLanguageService().getDefinitionAndBoundSpan(file, position);
let definitions = this.mapDefinitionInfoLocations(unmappedDefinitionAndBoundSpan?.definitions || emptyArray, project).slice();
let textSpan = unmappedDefinitionAndBoundSpan?.textSpan;
const unmappedDefinitions = project.getLanguageService().getDefinitionAtPosition(file, position);
let definitions: readonly DefinitionInfo[] = this.mapDefinitionInfoLocations(unmappedDefinitions || emptyArray, project).slice();
const needsJsResolution = this.projectService.serverMode === LanguageServiceMode.Semantic && (
!some(definitions, d => toNormalizedPath(d.fileName) !== file && !d.isAmbient) ||
some(definitions, d => !!d.failedAliasResolution));
Expand All @@ -1246,10 +1243,7 @@ namespace ts.server {
definitions?.forEach(d => definitionSet.add(d));
const noDtsProject = project.getNoDtsResolutionProject([file]);
const ls = noDtsProject.getLanguageService();
const definitionAndBoundSpan = ls.getDefinitionAndBoundSpan(file, position, /*searchOtherFilesOnly*/ true);
textSpan ||= definitionAndBoundSpan?.textSpan;
const jsDefinitions = definitionAndBoundSpan
?.definitions
const jsDefinitions = ls.getDefinitionAtPosition(file, position, /*searchOtherFilesOnly*/ true)
?.filter(d => toNormalizedPath(d.fileName) !== file);
if (some(jsDefinitions)) {
for (const jsDefinition of jsDefinitions) {
Expand Down Expand Up @@ -1282,23 +1276,8 @@ namespace ts.server {
definitions = arrayFrom(definitionSet.values());
}

if (!textSpan) {
return { definitions: emptyArray, textSpan: undefined! };
}

definitions = definitions.filter(d => !d.isAmbient && !d.failedAliasResolution);

if (simplifiedResult) {
return {
definitions: this.mapDefinitionInfo(definitions, project),
textSpan: toProtocolTextSpan(textSpan, scriptInfo)
};
}

return {
definitions: definitions.map(Session.mapToOriginalLocation),
textSpan,
};
return this.mapDefinitionInfo(definitions, project);

function findImplementationFileFromDtsFileName(fileName: string, resolveFromFile: string, auxiliaryProject: Project) {
const nodeModulesPathParts = getNodeModulePathParts(fileName);
Expand Down Expand Up @@ -1348,7 +1327,6 @@ namespace ts.server {
const ls = project.getLanguageService();
const program = ls.getProgram()!;
const initialNode = getTouchingPropertyName(program.getSourceFile(file)!, position);
textSpan = createTextSpanFromNode(initialNode); // TODO remove me
if ((isStringLiteralLike(initialNode) || isIdentifier(initialNode)) && isAccessExpression(initialNode.parent)) {
return forEachNameInAccessChainWalkingLeft(initialNode, nameInChain => {
if (nameInChain === initialNode) return undefined;
Expand Down Expand Up @@ -2933,11 +2911,8 @@ namespace ts.server {
[CommandNames.DefinitionAndBoundSpanFull]: (request: protocol.DefinitionAndBoundSpanRequest) => {
return this.requiredResponse(this.getDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false));
},
[CommandNames.SourceDefinitionAndBoundSpan]: (request: protocol.SourceDefinitionAndBoundSpanRequest) => {
return this.requiredResponse(this.getSourceDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ true));
},
[CommandNames.SourceDefinitionAndBoundSpanFull]: (request: protocol.SourceDefinitionAndBoundSpanRequest) => {
return this.requiredResponse(this.getSourceDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false));
[CommandNames.FindSourceDefinition]: (request: protocol.FindSourceDefinitionRequest) => {
return this.requiredResponse(this.findSourceDefinition(request.arguments));
},
[CommandNames.EmitOutput]: (request: protocol.EmitOutputRequest) => {
return this.requiredResponse(this.getEmitOutput(request.arguments));
Expand Down
4 changes: 2 additions & 2 deletions src/services/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ namespace ts.GoToDefinition {
return undefined;
}

export function getDefinitionAndBoundSpan(program: Program, sourceFile: SourceFile, position: number, searchOtherFilesOnly?: boolean): DefinitionInfoAndBoundSpan | undefined {
const definitions = getDefinitionAtPosition(program, sourceFile, position, searchOtherFilesOnly);
export function getDefinitionAndBoundSpan(program: Program, sourceFile: SourceFile, position: number): DefinitionInfoAndBoundSpan | undefined {
const definitions = getDefinitionAtPosition(program, sourceFile, position);

if (!definitions || definitions.length === 0) {
return undefined;
Expand Down
4 changes: 2 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1773,9 +1773,9 @@ namespace ts {
return GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position, searchOtherFilesOnly);
}

function getDefinitionAndBoundSpan(fileName: string, position: number, searchOtherFilesOnly?: boolean): DefinitionInfoAndBoundSpan | undefined {
function getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined {
synchronizeHostData();
return GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position, searchOtherFilesOnly);
return GoToDefinition.getDefinitionAndBoundSpan(program, getValidSourceFile(fileName), position);
}

function getTypeDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined {
Expand Down
3 changes: 0 additions & 3 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,6 @@ namespace ts {
// eslint-disable-next-line @typescript-eslint/unified-signatures
getDefinitionAtPosition(fileName: string, position: number, searchOtherFilesOnly: boolean): readonly DefinitionInfo[] | undefined;
getDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
/*@internal*/
// eslint-disable-next-line @typescript-eslint/unified-signatures
getDefinitionAndBoundSpan(fileName: string, position: number, searchOtherFilesOnly: boolean): DefinitionInfoAndBoundSpan | undefined;
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined;
getTypeDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
getImplementationAtPosition(fileName: string, position: number): readonly ImplementationLocation[] | undefined;
Expand Down