Added DefinitionAndBoundSpan command
This commit is contained in:
parent
d940cdadfe
commit
1cb2d24c5d
9 changed files with 58 additions and 18 deletions
|
@ -490,6 +490,9 @@ 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.");
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ namespace ts.server {
|
|||
body: undefined
|
||||
});
|
||||
});
|
||||
it ("should handle literal types in request", () => {
|
||||
it("should handle literal types in request", () => {
|
||||
const configureRequest: protocol.ConfigureRequest = {
|
||||
command: CommandNames.Configure,
|
||||
seq: 0,
|
||||
|
@ -175,6 +175,7 @@ namespace ts.server {
|
|||
CommandNames.Configure,
|
||||
CommandNames.Definition,
|
||||
CommandNames.DefinitionFull,
|
||||
CommandNames.DefinitionAndBoundSpan,
|
||||
CommandNames.Implementation,
|
||||
CommandNames.ImplementationFull,
|
||||
CommandNames.Exit,
|
||||
|
@ -341,7 +342,7 @@ namespace ts.server {
|
|||
session.addProtocolHandler(command, () => resp);
|
||||
|
||||
expect(() => session.addProtocolHandler(command, () => resp))
|
||||
.to.throw(`Protocol handler already exists for command "${command}"`);
|
||||
.to.throw(`Protocol handler already exists for command "${command}"`);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ namespace ts.server {
|
|||
}
|
||||
|
||||
getSyntacticDiagnostics(file: string): Diagnostic[] {
|
||||
const args: protocol.SyntacticDiagnosticsSyncRequestArgs = { file, includeLinePosition: true };
|
||||
const args: protocol.SyntacticDiagnosticsSyncRequestArgs = { file, includeLinePosition: true };
|
||||
|
||||
const request = this.processRequest<protocol.SyntacticDiagnosticsSyncRequest>(CommandNames.SyntacticDiagnosticsSync, args);
|
||||
const response = this.processResponse<protocol.SyntacticDiagnosticsSyncResponse>(request);
|
||||
|
@ -531,6 +531,10 @@ 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,6 +21,8 @@ namespace ts.server.protocol {
|
|||
Definition = "definition",
|
||||
/* @internal */
|
||||
DefinitionFull = "definition-full",
|
||||
/* @internal */
|
||||
DefinitionAndBoundSpan = "definitionAndBoundSpan",
|
||||
Implementation = "implementation",
|
||||
/* @internal */
|
||||
ImplementationFull = "implementation-full",
|
||||
|
|
|
@ -167,7 +167,7 @@ namespace ts.server {
|
|||
private timerHandle: any;
|
||||
private immediateId: number | undefined;
|
||||
|
||||
constructor(private readonly operationHost: MultistepOperationHost) {}
|
||||
constructor(private readonly operationHost: MultistepOperationHost) { }
|
||||
|
||||
public startNew(action: (next: NextStep) => void) {
|
||||
this.complete();
|
||||
|
@ -579,7 +579,7 @@ namespace ts.server {
|
|||
|
||||
private getDiagnosticsWorker(
|
||||
args: protocol.FileRequestArgs, isSemantic: boolean, selector: (project: Project, file: string) => ReadonlyArray<Diagnostic>, includeLinePosition: boolean
|
||||
): ReadonlyArray<protocol.DiagnosticWithLinePosition> | ReadonlyArray<protocol.Diagnostic> {
|
||||
): ReadonlyArray<protocol.DiagnosticWithLinePosition> | ReadonlyArray<protocol.Diagnostic> {
|
||||
const { project, file } = this.getFileAndProject(args);
|
||||
if (isSemantic && isDeclarationFileInJSOnlyNonConfiguredProject(project, file)) {
|
||||
return emptyArray;
|
||||
|
@ -1081,6 +1081,13 @@ 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);
|
||||
|
@ -1707,6 +1714,15 @@ namespace ts.server {
|
|||
[CommandNames.DefinitionFull]: (request: protocol.DefinitionRequest) => {
|
||||
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
|
||||
});
|
||||
},
|
||||
[CommandNames.TypeDefinition]: (request: protocol.FileLocationRequest) => {
|
||||
return this.requiredResponse(this.getTypeDefinition(request.arguments));
|
||||
},
|
||||
|
|
|
@ -724,9 +724,9 @@ namespace ts {
|
|||
|
||||
case SyntaxKind.BinaryExpression:
|
||||
if (getSpecialPropertyAssignmentKind(node as BinaryExpression) !== SpecialPropertyAssignmentKind.None) {
|
||||
addDeclaration(node as BinaryExpression);
|
||||
addDeclaration(node as BinaryExpression);
|
||||
}
|
||||
// falls through
|
||||
// falls through
|
||||
|
||||
default:
|
||||
forEachChild(node, visit);
|
||||
|
@ -1807,6 +1807,15 @@ 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
|
||||
|
@ -2032,6 +2041,7 @@ namespace ts {
|
|||
getDocCommentTemplateAtPosition,
|
||||
isValidBraceCompletionAtPosition,
|
||||
getSpanOfEnclosingComment,
|
||||
getSpanForPosition,
|
||||
getCodeFixesAtPosition,
|
||||
getEmitOutput,
|
||||
getNonBoundSourceFile,
|
||||
|
|
|
@ -273,6 +273,7 @@ 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[];
|
||||
|
|
|
@ -44,9 +44,9 @@ declare namespace ts {
|
|||
value: T;
|
||||
done: false;
|
||||
} | {
|
||||
value: never;
|
||||
done: true;
|
||||
};
|
||||
value: never;
|
||||
done: true;
|
||||
};
|
||||
}
|
||||
/** Array that is only intended to be pushed to, never read. */
|
||||
interface Push<T> {
|
||||
|
@ -3942,6 +3942,7 @@ 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;
|
||||
|
@ -4609,12 +4610,12 @@ declare namespace ts.server {
|
|||
module: {};
|
||||
error: undefined;
|
||||
} | {
|
||||
module: undefined;
|
||||
error: {
|
||||
stack?: string;
|
||||
message?: string;
|
||||
module: undefined;
|
||||
error: {
|
||||
stack?: string;
|
||||
message?: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
interface ServerHost extends System {
|
||||
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout(timeoutId: any): void;
|
||||
|
@ -6887,6 +6888,7 @@ 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);
|
||||
|
|
|
@ -44,9 +44,9 @@ declare namespace ts {
|
|||
value: T;
|
||||
done: false;
|
||||
} | {
|
||||
value: never;
|
||||
done: true;
|
||||
};
|
||||
value: never;
|
||||
done: true;
|
||||
};
|
||||
}
|
||||
/** Array that is only intended to be pushed to, never read. */
|
||||
interface Push<T> {
|
||||
|
@ -3942,6 +3942,7 @@ 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;
|
||||
|
|
Loading…
Reference in a new issue