Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 0 additions & 13 deletions src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,19 +682,6 @@ export class SessionClient implements LanguageService {
return { items, applicableSpan, selectedItemIndex, argumentIndex, argumentCount };
}

getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] {
const args = this.createFileLocationRequestArgs(fileName, position);

const request = this.processRequest<protocol.OccurrencesRequest>(protocol.CommandTypes.Occurrences, args);
const response = this.processResponse<protocol.OccurrencesResponse>(request);

return response.body!.map(entry => ({ // TODO: GH#18217
fileName: entry.file,
textSpan: this.decodeSpan(entry),
isWriteAccess: entry.isWriteAccess,
}));
}

getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] {
const args: protocol.DocumentHighlightsRequestArgs = { ...this.createFileLocationRequestArgs(fileName, position), filesToSearch };

Expand Down
11 changes: 10 additions & 1 deletion src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,16 @@ export class TestState {
}

private getOccurrencesAtCurrentPosition() {
return this.languageService.getOccurrencesAtPosition(this.activeFile.fileName, this.currentCaretPosition);
return ts.flatMap(
this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, [this.activeFile.fileName]),
entry => entry.highlightSpans.map<ts.ReferenceEntry>(highlightSpan => ({
fileName: entry.fileName,
textSpan: highlightSpan.textSpan,
isWriteAccess: highlightSpan.kind === ts.HighlightSpanKind.writtenReference,
...highlightSpan.isInString && { isInString: true },
...highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan }
}))
);
}

public verifyOccurrencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) {
Expand Down
3 changes: 0 additions & 3 deletions src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,6 @@ class LanguageServiceShimProxy implements ts.LanguageService {
getFileReferences(fileName: string): ts.ReferenceEntry[] {
return unwrapJSONCallResult(this.shim.getFileReferences(fileName));
}
getOccurrencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] {
return unwrapJSONCallResult(this.shim.getOccurrencesAtPosition(fileName, position));
}
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): ts.DocumentHighlights[] {
return unwrapJSONCallResult(this.shim.getDocumentHighlights(fileName, position, JSON.stringify(filesToSearch)));
}
Expand Down
29 changes: 0 additions & 29 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export const enum CommandTypes {
NavtoFull = "navto-full",
NavTree = "navtree",
NavTreeFull = "navtree-full",
/** @deprecated */
Occurrences = "occurrences",
DocumentHighlights = "documentHighlights",
/** @internal */
DocumentHighlightsFull = "documentHighlights-full",
Expand Down Expand Up @@ -1103,33 +1101,6 @@ export interface JsxClosingTagResponse extends Response {
readonly body: TextInsertion;
}

/**
* @deprecated
* Get occurrences request; value of command field is
* "occurrences". Return response giving spans that are relevant
* in the file at a given line and column.
*/
export interface OccurrencesRequest extends FileLocationRequest {
command: CommandTypes.Occurrences;
}

/** @deprecated */
export interface OccurrencesResponseItem extends FileSpanWithContext {
/**
* True if the occurrence is a write location, false otherwise.
*/
isWriteAccess: boolean;

/**
* True if the occurrence is in a string, undefined otherwise;
*/
isInString?: true;
}

/** @deprecated */
export interface OccurrencesResponse extends Response {
body?: OccurrencesResponseItem[];
}

/**
* Get document highlights request; value of command field is
Expand Down
22 changes: 0 additions & 22 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,6 @@ const invalidSyntacticModeCommands: readonly protocol.CommandTypes[] = [
protocol.CommandTypes.SignatureHelpFull,
protocol.CommandTypes.Navto,
protocol.CommandTypes.NavtoFull,
protocol.CommandTypes.Occurrences,
protocol.CommandTypes.DocumentHighlights,
protocol.CommandTypes.DocumentHighlightsFull,
];
Expand Down Expand Up @@ -1762,24 +1761,6 @@ export class Session<TMessage = string> implements EventSender {
implementations.map(Session.mapToOriginalLocation);
}

private getOccurrences(args: protocol.FileLocationRequestArgs): readonly protocol.OccurrencesResponseItem[] {
const { file, project } = this.getFileAndProject(args);
const position = this.getPositionInFile(args, file);
const occurrences = project.getLanguageService().getOccurrencesAtPosition(file, position);
return occurrences ?
occurrences.map<protocol.OccurrencesResponseItem>(occurrence => {
const { fileName, isWriteAccess, textSpan, isInString, contextSpan } = occurrence;
const scriptInfo = project.getScriptInfo(fileName)!;
return {
...toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo),
file: fileName,
isWriteAccess,
...(isInString ? { isInString } : undefined)
};
}) :
emptyArray;
}

private getSyntacticDiagnosticsSync(args: protocol.SyntacticDiagnosticsSyncRequestArgs) {
const { configFile } = this.getConfigFileAndProject(args);
if (configFile) {
Expand Down Expand Up @@ -3380,9 +3361,6 @@ export class Session<TMessage = string> implements EventSender {
[protocol.CommandTypes.NavTreeFull]: (request: protocol.FileRequest) => {
return this.requiredResponse(this.getNavigationTree(request.arguments, /*simplifiedResult*/ false));
},
[protocol.CommandTypes.Occurrences]: (request: protocol.FileLocationRequest) => {
return this.requiredResponse(this.getOccurrences(request.arguments));
},
[protocol.CommandTypes.DocumentHighlights]: (request: protocol.DocumentHighlightsRequest) => {
return this.requiredResponse(this.getDocumentHighlights(request.arguments, /*simplifiedResult*/ true));
},
Expand Down
15 changes: 0 additions & 15 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ import {
hasStaticModifier,
hasSyntacticModifier,
hasTabstop,
HighlightSpanKind,
HostCancellationToken,
hostGetCanonicalFileName,
hostUsesCaseSensitiveFileNames,
Expand Down Expand Up @@ -1531,7 +1530,6 @@ const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [
"getTypeDefinitionAtPosition",
"getReferencesAtPosition",
"findReferences",
"getOccurrencesAtPosition",
"getDocumentHighlights",
"getNavigateToItems",
"getRenameInfo",
Expand Down Expand Up @@ -2109,18 +2107,6 @@ export function createLanguageService(
}

/// References and Occurrences
function getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined {
return flatMap(
getDocumentHighlights(fileName, position, [fileName]),
entry => entry.highlightSpans.map<ReferenceEntry>(highlightSpan => ({
fileName: entry.fileName,
textSpan: highlightSpan.textSpan,
isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference,
...highlightSpan.isInString && { isInString: true },
...highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan }
}))
);
}

function getDocumentHighlights(fileName: string, position: number, filesToSearch: readonly string[]): DocumentHighlights[] | undefined {
const normalizedFileName = normalizePath(fileName);
Expand Down Expand Up @@ -3004,7 +2990,6 @@ export function createLanguageService(
getReferencesAtPosition,
findReferences,
getFileReferences,
getOccurrencesAtPosition,
getDocumentHighlights,
getNameOrDottedNameSpan,
getBreakpointStatementAtPosition,
Expand Down
14 changes: 0 additions & 14 deletions src/services/shims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,6 @@ export interface LanguageServiceShim extends Shim {
*/
getFileReferences(fileName: string): string;

/**
* @deprecated
* Returns a JSON-encoded value of the type:
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
*/
getOccurrencesAtPosition(fileName: string, position: number): string;

/**
* Returns a JSON-encoded value of the type:
* { fileName: string; highlights: { start: number; length: number }[] }[]
Expand Down Expand Up @@ -1021,13 +1014,6 @@ class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim
);
}

public getOccurrencesAtPosition(fileName: string, position: number): string {
return this.forwardJSONCall(
`getOccurrencesAtPosition('${fileName}', ${position})`,
() => this.languageService.getOccurrencesAtPosition(fileName, position)
);
}

public getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string {
return this.forwardJSONCall(
`getDocumentHighlights('${fileName}', ${position})`,
Expand Down
3 changes: 0 additions & 3 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,6 @@ export interface LanguageService {
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined;
getFileReferences(fileName: string): ReferenceEntry[];

/** @deprecated */
getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined;

getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[];
getNavigationBarItems(fileName: string): NavigationBarItem[];
getNavigationTree(fileName: string): NavigationTree;
Expand Down
6 changes: 3 additions & 3 deletions src/testRunner/unittests/tsserver/cancellationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ describe("unittests:: tsserver:: cancellationToken", () => {
});

expectedRequestId = session.getNextSeq();
session.executeCommandSeq<ts.server.protocol.OccurrencesRequest>({
command: ts.server.protocol.CommandTypes.Occurrences,
arguments: { file: f1.path, line: 1, offset: 6 }
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
command: ts.server.protocol.CommandTypes.DocumentHighlights,
arguments: { file: f1.path, line: 1, offset: 6, filesToSearch: [f1.path] }
});

expectedRequestId = 2;
Expand Down
18 changes: 9 additions & 9 deletions src/testRunner/unittests/tsserver/occurences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ describe("unittests:: tsserver:: occurrence highlight on string", () => {
const host = createServerHost([file1]);
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
openFilesForSession([file1], session);
session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
command: ts.server.protocol.CommandTypes.Occurrences,
arguments: { file: file1.path, line: 1, offset: 11 }
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
command: ts.server.protocol.CommandTypes.DocumentHighlights,
arguments: { file: file1.path, line: 1, offset: 11, filesToSearch: [file1.path] }
});

session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
command: ts.server.protocol.CommandTypes.Occurrences,
arguments: { file: file1.path, line: 3, offset: 13 }
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
command: ts.server.protocol.CommandTypes.DocumentHighlights,
arguments: { file: file1.path, line: 3, offset: 13, filesToSearch: [file1.path] }
});

session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
command: ts.server.protocol.CommandTypes.Occurrences,
arguments: { file: file1.path, line: 4, offset: 14 }
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
command: ts.server.protocol.CommandTypes.DocumentHighlights,
arguments: { file: file1.path, line: 4, offset: 14, filesToSearch: [file1.path] }
});
baselineTsserverLogs("occurences", "should be marked if only on string values", session);
});
Expand Down
7 changes: 4 additions & 3 deletions src/testRunner/unittests/tsserver/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,12 +1113,13 @@ describe("unittests:: tsserver:: Projects", () => {
});

// Actions on file1 would result in assert
session.executeCommandSeq<ts.server.protocol.OccurrencesRequest>({
command: ts.server.protocol.CommandTypes.Occurrences,
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
command: ts.server.protocol.CommandTypes.DocumentHighlights,
arguments: {
file: filesFile1.path,
line: 1,
offset: filesFile1.content.indexOf("a")
offset: filesFile1.content.indexOf("a"),
filesToSearch: [filesFile1.path],
}
});

Expand Down
29 changes: 0 additions & 29 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ declare namespace ts {
Navto = "navto",
NavTree = "navtree",
NavTreeFull = "navtree-full",
/** @deprecated */
Occurrences = "occurrences",
DocumentHighlights = "documentHighlights",
Open = "open",
Quickinfo = "quickinfo",
Expand Down Expand Up @@ -879,30 +877,6 @@ declare namespace ts {
interface JsxClosingTagResponse extends Response {
readonly body: TextInsertion;
}
/**
* @deprecated
* Get occurrences request; value of command field is
* "occurrences". Return response giving spans that are relevant
* in the file at a given line and column.
*/
interface OccurrencesRequest extends FileLocationRequest {
command: CommandTypes.Occurrences;
}
/** @deprecated */
interface OccurrencesResponseItem extends FileSpanWithContext {
/**
* True if the occurrence is a write location, false otherwise.
*/
isWriteAccess: boolean;
/**
* True if the occurrence is in a string, undefined otherwise;
*/
isInString?: true;
}
/** @deprecated */
interface OccurrencesResponse extends Response {
body?: OccurrencesResponseItem[];
}
/**
* Get document highlights request; value of command field is
* "documentHighlights". Return response giving spans that are relevant
Expand Down Expand Up @@ -3874,7 +3848,6 @@ declare namespace ts {
private getTypeDefinition;
private mapImplementationLocations;
private getImplementation;
private getOccurrences;
private getSyntacticDiagnosticsSync;
private getSemanticDiagnosticsSync;
private getSuggestionDiagnosticsSync;
Expand Down Expand Up @@ -9974,8 +9947,6 @@ declare namespace ts {
findReferences(fileName: string, position: number): ReferencedSymbol[] | undefined;
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined;
getFileReferences(fileName: string): ReferenceEntry[];
/** @deprecated */
getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined;
getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[];
getNavigationBarItems(fileName: string): NavigationBarItem[];
getNavigationTree(fileName: string): NavigationTree;
Expand Down
2 changes: 0 additions & 2 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6072,8 +6072,6 @@ declare namespace ts {
findReferences(fileName: string, position: number): ReferencedSymbol[] | undefined;
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined;
getFileReferences(fileName: string): ReferenceEntry[];
/** @deprecated */
getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined;
getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[];
getNavigationBarItems(fileName: string): NavigationBarItem[];
getNavigationTree(fileName: string): NavigationTree;
Expand Down
Loading