Skip to content

Commit dcc766f

Browse files
authored
Remove long deprecated occurrences request (#52347)
1 parent 080f9c1 commit dcc766f

File tree

15 files changed

+164
-269
lines changed

15 files changed

+164
-269
lines changed

src/harness/client.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -682,19 +682,6 @@ export class SessionClient implements LanguageService {
682682
return { items, applicableSpan, selectedItemIndex, argumentIndex, argumentCount };
683683
}
684684

685-
getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] {
686-
const args = this.createFileLocationRequestArgs(fileName, position);
687-
688-
const request = this.processRequest<protocol.OccurrencesRequest>(protocol.CommandTypes.Occurrences, args);
689-
const response = this.processResponse<protocol.OccurrencesResponse>(request);
690-
691-
return response.body!.map(entry => ({ // TODO: GH#18217
692-
fileName: entry.file,
693-
textSpan: this.decodeSpan(entry),
694-
isWriteAccess: entry.isWriteAccess,
695-
}));
696-
}
697-
698685
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] {
699686
const args: protocol.DocumentHighlightsRequestArgs = { ...this.createFileLocationRequestArgs(fileName, position), filesToSearch };
700687

src/harness/fourslashImpl.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3557,7 +3557,16 @@ export class TestState {
35573557
}
35583558

35593559
private getOccurrencesAtCurrentPosition() {
3560-
return this.languageService.getOccurrencesAtPosition(this.activeFile.fileName, this.currentCaretPosition);
3560+
return ts.flatMap(
3561+
this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, [this.activeFile.fileName]),
3562+
entry => entry.highlightSpans.map<ts.ReferenceEntry>(highlightSpan => ({
3563+
fileName: entry.fileName,
3564+
textSpan: highlightSpan.textSpan,
3565+
isWriteAccess: highlightSpan.kind === ts.HighlightSpanKind.writtenReference,
3566+
...highlightSpan.isInString && { isInString: true },
3567+
...highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan }
3568+
}))
3569+
);
35613570
}
35623571

35633572
public verifyOccurrencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) {

src/harness/harnessLanguageService.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,6 @@ class LanguageServiceShimProxy implements ts.LanguageService {
551551
getFileReferences(fileName: string): ts.ReferenceEntry[] {
552552
return unwrapJSONCallResult(this.shim.getFileReferences(fileName));
553553
}
554-
getOccurrencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] {
555-
return unwrapJSONCallResult(this.shim.getOccurrencesAtPosition(fileName, position));
556-
}
557554
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): ts.DocumentHighlights[] {
558555
return unwrapJSONCallResult(this.shim.getDocumentHighlights(fileName, position, JSON.stringify(filesToSearch)));
559556
}

src/server/protocol.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ export const enum CommandTypes {
7777
NavtoFull = "navto-full",
7878
NavTree = "navtree",
7979
NavTreeFull = "navtree-full",
80-
/** @deprecated */
81-
Occurrences = "occurrences",
8280
DocumentHighlights = "documentHighlights",
8381
/** @internal */
8482
DocumentHighlightsFull = "documentHighlights-full",
@@ -1103,33 +1101,6 @@ export interface JsxClosingTagResponse extends Response {
11031101
readonly body: TextInsertion;
11041102
}
11051103

1106-
/**
1107-
* @deprecated
1108-
* Get occurrences request; value of command field is
1109-
* "occurrences". Return response giving spans that are relevant
1110-
* in the file at a given line and column.
1111-
*/
1112-
export interface OccurrencesRequest extends FileLocationRequest {
1113-
command: CommandTypes.Occurrences;
1114-
}
1115-
1116-
/** @deprecated */
1117-
export interface OccurrencesResponseItem extends FileSpanWithContext {
1118-
/**
1119-
* True if the occurrence is a write location, false otherwise.
1120-
*/
1121-
isWriteAccess: boolean;
1122-
1123-
/**
1124-
* True if the occurrence is in a string, undefined otherwise;
1125-
*/
1126-
isInString?: true;
1127-
}
1128-
1129-
/** @deprecated */
1130-
export interface OccurrencesResponse extends Response {
1131-
body?: OccurrencesResponseItem[];
1132-
}
11331104

11341105
/**
11351106
* Get document highlights request; value of command field is

src/server/session.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,6 @@ const invalidSyntacticModeCommands: readonly protocol.CommandTypes[] = [
913913
protocol.CommandTypes.SignatureHelpFull,
914914
protocol.CommandTypes.Navto,
915915
protocol.CommandTypes.NavtoFull,
916-
protocol.CommandTypes.Occurrences,
917916
protocol.CommandTypes.DocumentHighlights,
918917
protocol.CommandTypes.DocumentHighlightsFull,
919918
];
@@ -1768,24 +1767,6 @@ export class Session<TMessage = string> implements EventSender {
17681767
implementations.map(Session.mapToOriginalLocation);
17691768
}
17701769

1771-
private getOccurrences(args: protocol.FileLocationRequestArgs): readonly protocol.OccurrencesResponseItem[] {
1772-
const { file, project } = this.getFileAndProject(args);
1773-
const position = this.getPositionInFile(args, file);
1774-
const occurrences = project.getLanguageService().getOccurrencesAtPosition(file, position);
1775-
return occurrences ?
1776-
occurrences.map<protocol.OccurrencesResponseItem>(occurrence => {
1777-
const { fileName, isWriteAccess, textSpan, isInString, contextSpan } = occurrence;
1778-
const scriptInfo = project.getScriptInfo(fileName)!;
1779-
return {
1780-
...toProtocolTextSpanWithContext(textSpan, contextSpan, scriptInfo),
1781-
file: fileName,
1782-
isWriteAccess,
1783-
...(isInString ? { isInString } : undefined)
1784-
};
1785-
}) :
1786-
emptyArray;
1787-
}
1788-
17891770
private getSyntacticDiagnosticsSync(args: protocol.SyntacticDiagnosticsSyncRequestArgs) {
17901771
const { configFile } = this.getConfigFileAndProject(args);
17911772
if (configFile) {
@@ -3386,9 +3367,6 @@ export class Session<TMessage = string> implements EventSender {
33863367
[protocol.CommandTypes.NavTreeFull]: (request: protocol.FileRequest) => {
33873368
return this.requiredResponse(this.getNavigationTree(request.arguments, /*simplifiedResult*/ false));
33883369
},
3389-
[protocol.CommandTypes.Occurrences]: (request: protocol.FileLocationRequest) => {
3390-
return this.requiredResponse(this.getOccurrences(request.arguments));
3391-
},
33923370
[protocol.CommandTypes.DocumentHighlights]: (request: protocol.DocumentHighlightsRequest) => {
33933371
return this.requiredResponse(this.getDocumentHighlights(request.arguments, /*simplifiedResult*/ true));
33943372
},

src/services/services.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ import {
119119
hasStaticModifier,
120120
hasSyntacticModifier,
121121
hasTabstop,
122-
HighlightSpanKind,
123122
HostCancellationToken,
124123
hostGetCanonicalFileName,
125124
hostUsesCaseSensitiveFileNames,
@@ -1529,7 +1528,6 @@ const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [
15291528
"getTypeDefinitionAtPosition",
15301529
"getReferencesAtPosition",
15311530
"findReferences",
1532-
"getOccurrencesAtPosition",
15331531
"getDocumentHighlights",
15341532
"getNavigateToItems",
15351533
"getRenameInfo",
@@ -2108,18 +2106,6 @@ export function createLanguageService(
21082106
}
21092107

21102108
/// References and Occurrences
2111-
function getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined {
2112-
return flatMap(
2113-
getDocumentHighlights(fileName, position, [fileName]),
2114-
entry => entry.highlightSpans.map<ReferenceEntry>(highlightSpan => ({
2115-
fileName: entry.fileName,
2116-
textSpan: highlightSpan.textSpan,
2117-
isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference,
2118-
...highlightSpan.isInString && { isInString: true },
2119-
...highlightSpan.contextSpan && { contextSpan: highlightSpan.contextSpan }
2120-
}))
2121-
);
2122-
}
21232109

21242110
function getDocumentHighlights(fileName: string, position: number, filesToSearch: readonly string[]): DocumentHighlights[] | undefined {
21252111
const normalizedFileName = normalizePath(fileName);
@@ -3004,7 +2990,6 @@ export function createLanguageService(
30042990
getReferencesAtPosition,
30052991
findReferences,
30062992
getFileReferences,
3007-
getOccurrencesAtPosition,
30082993
getDocumentHighlights,
30092994
getNameOrDottedNameSpan,
30102995
getBreakpointStatementAtPosition,

src/services/shims.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -300,13 +300,6 @@ export interface LanguageServiceShim extends Shim {
300300
*/
301301
getFileReferences(fileName: string): string;
302302

303-
/**
304-
* @deprecated
305-
* Returns a JSON-encoded value of the type:
306-
* { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[]
307-
*/
308-
getOccurrencesAtPosition(fileName: string, position: number): string;
309-
310303
/**
311304
* Returns a JSON-encoded value of the type:
312305
* { fileName: string; highlights: { start: number; length: number }[] }[]
@@ -1021,13 +1014,6 @@ class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim
10211014
);
10221015
}
10231016

1024-
public getOccurrencesAtPosition(fileName: string, position: number): string {
1025-
return this.forwardJSONCall(
1026-
`getOccurrencesAtPosition('${fileName}', ${position})`,
1027-
() => this.languageService.getOccurrencesAtPosition(fileName, position)
1028-
);
1029-
}
1030-
10311017
public getDocumentHighlights(fileName: string, position: number, filesToSearch: string): string {
10321018
return this.forwardJSONCall(
10331019
`getDocumentHighlights('${fileName}', ${position})`,

src/services/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,6 @@ export interface LanguageService {
580580
getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[] | undefined;
581581
getFileReferences(fileName: string): ReferenceEntry[];
582582

583-
/** @deprecated */
584-
getOccurrencesAtPosition(fileName: string, position: number): readonly ReferenceEntry[] | undefined;
585-
586583
getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[];
587584
getNavigationBarItems(fileName: string): NavigationBarItem[];
588585
getNavigationTree(fileName: string): NavigationTree;

src/testRunner/unittests/tsserver/cancellationToken.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ describe("unittests:: tsserver:: cancellationToken", () => {
5151
});
5252

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

5959
expectedRequestId = 2;

src/testRunner/unittests/tsserver/occurences.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ describe("unittests:: tsserver:: occurrence highlight on string", () => {
2020
const host = createServerHost([file1]);
2121
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
2222
openFilesForSession([file1], session);
23-
session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
24-
command: ts.server.protocol.CommandTypes.Occurrences,
25-
arguments: { file: file1.path, line: 1, offset: 11 }
23+
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
24+
command: ts.server.protocol.CommandTypes.DocumentHighlights,
25+
arguments: { file: file1.path, line: 1, offset: 11, filesToSearch: [file1.path] }
2626
});
2727

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

33-
session.executeCommandSeq<ts.server.protocol.FileLocationRequest>({
34-
command: ts.server.protocol.CommandTypes.Occurrences,
35-
arguments: { file: file1.path, line: 4, offset: 14 }
33+
session.executeCommandSeq<ts.server.protocol.DocumentHighlightsRequest>({
34+
command: ts.server.protocol.CommandTypes.DocumentHighlights,
35+
arguments: { file: file1.path, line: 4, offset: 14, filesToSearch: [file1.path] }
3636
});
3737
baselineTsserverLogs("occurences", "should be marked if only on string values", session);
3838
});

0 commit comments

Comments
 (0)