mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Changed command designed based on review input
This commit is contained in:
@@ -432,6 +432,9 @@ namespace Harness.LanguageService {
|
||||
getDefinitionAtPosition(fileName: string, position: number): ts.DefinitionInfo[] {
|
||||
return unwrapJSONCallResult(this.shim.getDefinitionAtPosition(fileName, position));
|
||||
}
|
||||
getDefinitionAndBoundSpan(): ts.DefinitionInfoAndBoundSpan {
|
||||
throw new Error("Not supported on the shim.");
|
||||
}
|
||||
getTypeDefinitionAtPosition(fileName: string, position: number): ts.DefinitionInfo[] {
|
||||
return unwrapJSONCallResult(this.shim.getTypeDefinitionAtPosition(fileName, position));
|
||||
}
|
||||
@@ -490,9 +493,6 @@ namespace Harness.LanguageService {
|
||||
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): ts.TextSpan {
|
||||
return unwrapJSONCallResult(this.shim.getSpanOfEnclosingComment(fileName, position, onlyMultiLine));
|
||||
}
|
||||
getSpanForPosition(): ts.TextSpan {
|
||||
throw new Error("Not supportred on the shim.");
|
||||
}
|
||||
getCodeFixesAtPosition(): ts.CodeAction[] {
|
||||
throw new Error("Not supported on the shim.");
|
||||
}
|
||||
|
||||
@@ -176,6 +176,7 @@ namespace ts.server {
|
||||
CommandNames.Definition,
|
||||
CommandNames.DefinitionFull,
|
||||
CommandNames.DefinitionAndBoundSpan,
|
||||
CommandNames.DefinitionAndBoundSpanFull,
|
||||
CommandNames.Implementation,
|
||||
CommandNames.ImplementationFull,
|
||||
CommandNames.Exit,
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -1411,6 +1411,20 @@ namespace ts {
|
||||
return GoToDefinition.getDefinitionAtPosition(program, getValidSourceFile(fileName), position);
|
||||
}
|
||||
|
||||
function getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan {
|
||||
const definitions = getDefinitionAtPosition(fileName, position);
|
||||
|
||||
if (!definitions) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const sourceFile = getValidSourceFile(fileName);
|
||||
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocComment*/ true);
|
||||
const textSpan = createTextSpan(node.getStart(), node.getWidth());
|
||||
|
||||
return { definitions, textSpan };
|
||||
}
|
||||
|
||||
function getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] {
|
||||
synchronizeHostData();
|
||||
return GoToDefinition.getTypeDefinitionAtPosition(program.getTypeChecker(), getValidSourceFile(fileName), position);
|
||||
@@ -1807,15 +1821,6 @@ namespace ts {
|
||||
return range && createTextSpanFromRange(range);
|
||||
}
|
||||
|
||||
function getSpanForPosition(fileName: string, position: number): TextSpan {
|
||||
synchronizeHostData();
|
||||
|
||||
const sourceFile = getValidSourceFile(fileName);
|
||||
const node = getTouchingPropertyName(sourceFile, position, /*includeJsDocCcomment*/ false);
|
||||
|
||||
return createTextSpan(node.getStart(), node.getWidth());
|
||||
}
|
||||
|
||||
function getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[] {
|
||||
// Note: while getting todo comments seems like a syntactic operation, we actually
|
||||
// treat it as a semantic operation here. This is because we expect our host to call
|
||||
@@ -2018,6 +2023,7 @@ namespace ts {
|
||||
getSignatureHelpItems,
|
||||
getQuickInfoAtPosition,
|
||||
getDefinitionAtPosition,
|
||||
getDefinitionAndBoundSpan,
|
||||
getImplementationAtPosition,
|
||||
getTypeDefinitionAtPosition,
|
||||
getReferencesAtPosition,
|
||||
@@ -2041,7 +2047,6 @@ namespace ts {
|
||||
getDocCommentTemplateAtPosition,
|
||||
isValidBraceCompletionAtPosition,
|
||||
getSpanOfEnclosingComment,
|
||||
getSpanForPosition,
|
||||
getCodeFixesAtPosition,
|
||||
getEmitOutput,
|
||||
getNonBoundSourceFile,
|
||||
|
||||
@@ -245,6 +245,7 @@ namespace ts {
|
||||
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[];
|
||||
|
||||
getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
|
||||
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan;
|
||||
getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
|
||||
getImplementationAtPosition(fileName: string, position: number): ImplementationLocation[];
|
||||
|
||||
@@ -273,7 +274,6 @@ namespace ts {
|
||||
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
|
||||
|
||||
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
|
||||
getSpanForPosition(fileName: string, position: number): TextSpan;
|
||||
|
||||
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[], formatOptions: FormatCodeSettings): CodeAction[];
|
||||
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange): ApplicableRefactorInfo[];
|
||||
@@ -549,6 +549,11 @@ namespace ts {
|
||||
containerName: string;
|
||||
}
|
||||
|
||||
export interface DefinitionInfoAndBoundSpan {
|
||||
definitions: ReadonlyArray<DefinitionInfo>;
|
||||
textSpan: TextSpan;
|
||||
}
|
||||
|
||||
export interface ReferencedSymbolDefinitionInfo extends DefinitionInfo {
|
||||
displayParts: SymbolDisplayPart[];
|
||||
}
|
||||
|
||||
@@ -3922,6 +3922,7 @@ declare namespace ts {
|
||||
getRenameInfo(fileName: string, position: number): RenameInfo;
|
||||
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[];
|
||||
getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
|
||||
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan;
|
||||
getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
|
||||
getImplementationAtPosition(fileName: string, position: number): ImplementationLocation[];
|
||||
getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[];
|
||||
@@ -3942,7 +3943,6 @@ declare namespace ts {
|
||||
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion;
|
||||
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
|
||||
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
|
||||
getSpanForPosition(fileName: string, position: number): TextSpan;
|
||||
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[], formatOptions: FormatCodeSettings): CodeAction[];
|
||||
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange): ApplicableRefactorInfo[];
|
||||
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string): RefactorEditInfo | undefined;
|
||||
@@ -4174,6 +4174,10 @@ declare namespace ts {
|
||||
containerKind: ScriptElementKind;
|
||||
containerName: string;
|
||||
}
|
||||
interface DefinitionInfoAndBoundSpan {
|
||||
definitions: ReadonlyArray<DefinitionInfo>;
|
||||
textSpan: TextSpan;
|
||||
}
|
||||
interface ReferencedSymbolDefinitionInfo extends DefinitionInfo {
|
||||
displayParts: SymbolDisplayPart[];
|
||||
}
|
||||
@@ -4793,6 +4797,7 @@ declare namespace ts.server.protocol {
|
||||
CompileOnSaveEmitFile = "compileOnSaveEmitFile",
|
||||
Configure = "configure",
|
||||
Definition = "definition",
|
||||
DefinitionAndBoundSpan = "definitionAndBoundSpan",
|
||||
Implementation = "implementation",
|
||||
Exit = "exit",
|
||||
Format = "format",
|
||||
@@ -5298,6 +5303,10 @@ declare namespace ts.server.protocol {
|
||||
*/
|
||||
file: string;
|
||||
}
|
||||
interface DefinitionInfoAndBoundSpan {
|
||||
definitions: ReadonlyArray<FileSpan>;
|
||||
textSpan: TextSpan;
|
||||
}
|
||||
/**
|
||||
* Definition response message. Gives text range for definition.
|
||||
*/
|
||||
@@ -6855,6 +6864,9 @@ declare namespace ts.server {
|
||||
private convertToDiagnosticsWithLinePosition(diagnostics, scriptInfo);
|
||||
private getDiagnosticsWorker(args, isSemantic, selector, includeLinePosition);
|
||||
private getDefinition(args, simplifiedResult);
|
||||
private getDefinitionAndBoundSpan(args, simplifiedResult);
|
||||
private getSimplifiedDefinition(definitions, project);
|
||||
private getSimplifiedTextSpan(textSpan, scriptInfo);
|
||||
private getTypeDefinition(args);
|
||||
private getImplementation(args, simplifiedResult);
|
||||
private getOccurrences(args);
|
||||
@@ -6888,7 +6900,6 @@ declare namespace ts.server {
|
||||
private getNameOrDottedNameSpan(args);
|
||||
private isValidBraceCompletion(args);
|
||||
private getQuickInfoWorker(args, simplifiedResult);
|
||||
private getSpanForLocation(args);
|
||||
private getFormattingEditsForRange(args);
|
||||
private getFormattingEditsForRangeFull(args);
|
||||
private getFormattingEditsForDocumentFull(args);
|
||||
|
||||
@@ -3922,6 +3922,7 @@ declare namespace ts {
|
||||
getRenameInfo(fileName: string, position: number): RenameInfo;
|
||||
findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[];
|
||||
getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
|
||||
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan;
|
||||
getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[];
|
||||
getImplementationAtPosition(fileName: string, position: number): ImplementationLocation[];
|
||||
getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[];
|
||||
@@ -3942,7 +3943,6 @@ declare namespace ts {
|
||||
getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion;
|
||||
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
|
||||
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
|
||||
getSpanForPosition(fileName: string, position: number): TextSpan;
|
||||
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[], formatOptions: FormatCodeSettings): CodeAction[];
|
||||
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange): ApplicableRefactorInfo[];
|
||||
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string): RefactorEditInfo | undefined;
|
||||
@@ -4174,6 +4174,10 @@ declare namespace ts {
|
||||
containerKind: ScriptElementKind;
|
||||
containerName: string;
|
||||
}
|
||||
interface DefinitionInfoAndBoundSpan {
|
||||
definitions: ReadonlyArray<DefinitionInfo>;
|
||||
textSpan: TextSpan;
|
||||
}
|
||||
interface ReferencedSymbolDefinitionInfo extends DefinitionInfo {
|
||||
displayParts: SymbolDisplayPart[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user