mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-18 17:27:54 -05:00
Changed command designed based on review input
This commit is contained in:
@@ -268,6 +268,10 @@ namespace ts.server {
|
||||
}));
|
||||
}
|
||||
|
||||
getDefinitionAndBoundSpan(_fileName: string, _position: number): DefinitionInfoAndBoundSpan {
|
||||
return notImplemented();
|
||||
}
|
||||
|
||||
getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] {
|
||||
const args: protocol.FileLocationRequestArgs = this.createFileLocationRequestArgs(fileName, position);
|
||||
|
||||
@@ -531,10 +535,6 @@ namespace ts.server {
|
||||
return notImplemented();
|
||||
}
|
||||
|
||||
getSpanForPosition(_fileName: string, _position: number): TextSpan {
|
||||
return notImplemented();
|
||||
}
|
||||
|
||||
getCodeFixesAtPosition(file: string, start: number, end: number, errorCodes: number[]): CodeAction[] {
|
||||
const args: protocol.CodeFixRequestArgs = { ...this.createFileRangeRequestArgs(file, start, end), errorCodes };
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@ namespace ts.server.protocol {
|
||||
Definition = "definition",
|
||||
/* @internal */
|
||||
DefinitionFull = "definition-full",
|
||||
/* @internal */
|
||||
DefinitionAndBoundSpan = "definitionAndBoundSpan",
|
||||
/* @internal */
|
||||
DefinitionAndBoundSpanFull = "definitionAndBoundSpan-full",
|
||||
Implementation = "implementation",
|
||||
/* @internal */
|
||||
ImplementationFull = "implementation-full",
|
||||
@@ -690,6 +691,11 @@ namespace ts.server.protocol {
|
||||
file: string;
|
||||
}
|
||||
|
||||
export interface DefinitionInfoAndBoundSpan {
|
||||
definitions: ReadonlyArray<FileSpan>;
|
||||
textSpan: TextSpan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Definition response message. Gives text range for definition.
|
||||
*/
|
||||
|
||||
@@ -601,20 +601,57 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
if (simplifiedResult) {
|
||||
return definitions.map(def => {
|
||||
const defScriptInfo = project.getScriptInfo(def.fileName);
|
||||
return {
|
||||
file: def.fileName,
|
||||
start: defScriptInfo.positionToLineOffset(def.textSpan.start),
|
||||
end: defScriptInfo.positionToLineOffset(textSpanEnd(def.textSpan))
|
||||
};
|
||||
});
|
||||
return this.getSimplifiedDefinition(definitions, project);
|
||||
}
|
||||
else {
|
||||
return definitions;
|
||||
}
|
||||
}
|
||||
|
||||
private getDefinitionAndBoundSpan(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.DefinitionInfoAndBoundSpan | DefinitionInfoAndBoundSpan {
|
||||
const { file, project } = this.getFileAndProject(args);
|
||||
const position = this.getPositionInFile(args, file);
|
||||
const scriptInfo = project.getScriptInfo(file);
|
||||
|
||||
const definitionAndBoundSpan = project.getLanguageService().getDefinitionAndBoundSpan(file, position);
|
||||
|
||||
if (!definitionAndBoundSpan || !definitionAndBoundSpan.definitions) {
|
||||
return {
|
||||
definitions: emptyArray,
|
||||
textSpan: undefined
|
||||
};
|
||||
}
|
||||
|
||||
if (simplifiedResult) {
|
||||
return {
|
||||
definitions: this.getSimplifiedDefinition(definitionAndBoundSpan.definitions, project),
|
||||
textSpan: this.getSimplifiedTextSpan(definitionAndBoundSpan.textSpan, scriptInfo)
|
||||
};
|
||||
}
|
||||
|
||||
return definitionAndBoundSpan;
|
||||
}
|
||||
|
||||
private getSimplifiedDefinition(definitions: ReadonlyArray<DefinitionInfo>, project: Project): ReadonlyArray<protocol.FileSpan> {
|
||||
return definitions.map(def => {
|
||||
const defScriptInfo = project.getScriptInfo(def.fileName);
|
||||
const simplifiedTextSpan = this.getSimplifiedTextSpan(def.textSpan, defScriptInfo);
|
||||
|
||||
return {
|
||||
file: def.fileName,
|
||||
start: simplifiedTextSpan.start,
|
||||
end: simplifiedTextSpan.end
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private getSimplifiedTextSpan(textSpan: TextSpan, scriptInfo: ScriptInfo): protocol.TextSpan {
|
||||
return {
|
||||
start: scriptInfo.positionToLineOffset(textSpan.start),
|
||||
end: scriptInfo.positionToLineOffset(textSpanEnd(textSpan))
|
||||
};
|
||||
}
|
||||
|
||||
private getTypeDefinition(args: protocol.FileLocationRequestArgs): ReadonlyArray<protocol.FileSpan> {
|
||||
const { file, project } = this.getFileAndProject(args);
|
||||
const position = this.getPositionInFile(args, file);
|
||||
@@ -1081,13 +1118,6 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
private getSpanForLocation(args: protocol.FileLocationRequestArgs): TextSpan {
|
||||
const { file, project } = this.getFileAndProject(args);
|
||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||
|
||||
return project.getLanguageService().getSpanForPosition(file, this.getPosition(args, scriptInfo));
|
||||
}
|
||||
|
||||
private getFormattingEditsForRange(args: protocol.FormatRequestArgs): protocol.CodeEdit[] {
|
||||
const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args);
|
||||
const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file);
|
||||
@@ -1715,13 +1745,10 @@ namespace ts.server {
|
||||
return this.requiredResponse(this.getDefinition(request.arguments, /*simplifiedResult*/ false));
|
||||
},
|
||||
[CommandNames.DefinitionAndBoundSpan]: (request: protocol.DefinitionRequest) => {
|
||||
const definitions = this.getDefinition(request.arguments, /*simplifiedResult*/ false);
|
||||
const textSpan = definitions.length !== 0 ? this.getSpanForLocation(request.arguments) : {};
|
||||
|
||||
return this.requiredResponse({
|
||||
definitions,
|
||||
textSpan
|
||||
});
|
||||
return this.requiredResponse(this.getDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ true));
|
||||
},
|
||||
[CommandNames.DefinitionAndBoundSpanFull]: (request: protocol.DefinitionRequest) => {
|
||||
return this.requiredResponse(this.getDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false));
|
||||
},
|
||||
[CommandNames.TypeDefinition]: (request: protocol.FileLocationRequest) => {
|
||||
return this.requiredResponse(this.getTypeDefinition(request.arguments));
|
||||
|
||||
Reference in New Issue
Block a user