Remove long deprecated occurrences request (#52347)

This commit is contained in:
Sheetal Nandi 2023-03-01 10:59:07 -08:00 committed by GitHub
parent 080f9c1c3f
commit dcc766f2b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 164 additions and 269 deletions

View File

@ -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 };

View File

@ -3557,7 +3557,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) {

View File

@ -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)));
}

View File

@ -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",
@ -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

View File

@ -913,7 +913,6 @@ const invalidSyntacticModeCommands: readonly protocol.CommandTypes[] = [
protocol.CommandTypes.SignatureHelpFull,
protocol.CommandTypes.Navto,
protocol.CommandTypes.NavtoFull,
protocol.CommandTypes.Occurrences,
protocol.CommandTypes.DocumentHighlights,
protocol.CommandTypes.DocumentHighlightsFull,
];
@ -1768,24 +1767,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) {
@ -3386,9 +3367,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));
},

View File

@ -119,7 +119,6 @@ import {
hasStaticModifier,
hasSyntacticModifier,
hasTabstop,
HighlightSpanKind,
HostCancellationToken,
hostGetCanonicalFileName,
hostUsesCaseSensitiveFileNames,
@ -1529,7 +1528,6 @@ const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [
"getTypeDefinitionAtPosition",
"getReferencesAtPosition",
"findReferences",
"getOccurrencesAtPosition",
"getDocumentHighlights",
"getNavigateToItems",
"getRenameInfo",
@ -2108,18 +2106,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);
@ -3004,7 +2990,6 @@ export function createLanguageService(
getReferencesAtPosition,
findReferences,
getFileReferences,
getOccurrencesAtPosition,
getDocumentHighlights,
getNameOrDottedNameSpan,
getBreakpointStatementAtPosition,

View File

@ -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 }[] }[]
@ -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})`,

View File

@ -580,9 +580,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;

View File

@ -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;

View File

@ -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);
});

View File

@ -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],
}
});

View File

@ -117,8 +117,6 @@ declare namespace ts {
Navto = "navto",
NavTree = "navtree",
NavTreeFull = "navtree-full",
/** @deprecated */
Occurrences = "occurrences",
DocumentHighlights = "documentHighlights",
Open = "open",
Quickinfo = "quickinfo",
@ -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
@ -3874,7 +3848,6 @@ declare namespace ts {
private getTypeDefinition;
private mapImplementationLocations;
private getImplementation;
private getOccurrences;
private getSyntacticDiagnosticsSync;
private getSemanticDiagnosticsSync;
private getSuggestionDiagnosticsSync;
@ -9988,8 +9961,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;

View File

@ -6086,8 +6086,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;

View File

@ -63,11 +63,14 @@ Info 12 [00:00:27.000] response:
}
Info 13 [00:00:28.000] request:
{
"command": "occurrences",
"command": "documentHighlights",
"arguments": {
"file": "/a/b/file1.ts",
"line": 1,
"offset": 11
"offset": 11,
"filesToSearch": [
"/a/b/file1.ts"
]
},
"seq": 2,
"type": "request"
@ -100,75 +103,75 @@ Info 14 [00:00:29.000] response:
{
"response": [
{
"start": {
"line": 1,
"offset": 11
},
"end": {
"line": 1,
"offset": 14
},
"file": "/a/b/file1.ts",
"isWriteAccess": false,
"isInString": true
},
{
"start": {
"line": 2,
"offset": 11
},
"end": {
"line": 2,
"offset": 14
},
"file": "/a/b/file1.ts",
"isWriteAccess": false,
"isInString": true
},
{
"start": {
"line": 3,
"offset": 13
},
"end": {
"line": 3,
"offset": 16
},
"contextStart": {
"line": 3,
"offset": 12
},
"contextEnd": {
"line": 3,
"offset": 22
},
"file": "/a/b/file1.ts",
"isWriteAccess": true,
"isInString": true
},
{
"start": {
"line": 4,
"offset": 14
},
"end": {
"line": 4,
"offset": 17
},
"file": "/a/b/file1.ts",
"isWriteAccess": false,
"isInString": true
"highlightSpans": [
{
"start": {
"line": 1,
"offset": 11
},
"end": {
"line": 1,
"offset": 14
},
"kind": "reference"
},
{
"start": {
"line": 2,
"offset": 11
},
"end": {
"line": 2,
"offset": 14
},
"kind": "reference"
},
{
"start": {
"line": 3,
"offset": 13
},
"end": {
"line": 3,
"offset": 16
},
"contextStart": {
"line": 3,
"offset": 12
},
"contextEnd": {
"line": 3,
"offset": 22
},
"kind": "writtenReference"
},
{
"start": {
"line": 4,
"offset": 14
},
"end": {
"line": 4,
"offset": 17
},
"kind": "reference"
}
]
}
],
"responseRequired": true
}
Info 15 [00:00:30.000] request:
{
"command": "occurrences",
"command": "documentHighlights",
"arguments": {
"file": "/a/b/file1.ts",
"line": 3,
"offset": 13
"offset": 13,
"filesToSearch": [
"/a/b/file1.ts"
]
},
"seq": 3,
"type": "request"
@ -201,47 +204,53 @@ Info 16 [00:00:31.000] response:
{
"response": [
{
"start": {
"line": 3,
"offset": 13
},
"end": {
"line": 3,
"offset": 16
},
"contextStart": {
"line": 3,
"offset": 12
},
"contextEnd": {
"line": 3,
"offset": 22
},
"file": "/a/b/file1.ts",
"isWriteAccess": true
},
{
"start": {
"line": 4,
"offset": 14
},
"end": {
"line": 4,
"offset": 17
},
"file": "/a/b/file1.ts",
"isWriteAccess": false
"highlightSpans": [
{
"start": {
"line": 3,
"offset": 13
},
"end": {
"line": 3,
"offset": 16
},
"contextStart": {
"line": 3,
"offset": 12
},
"contextEnd": {
"line": 3,
"offset": 22
},
"kind": "writtenReference"
},
{
"start": {
"line": 4,
"offset": 14
},
"end": {
"line": 4,
"offset": 17
},
"kind": "reference"
}
]
}
],
"responseRequired": true
}
Info 17 [00:00:32.000] request:
{
"command": "occurrences",
"command": "documentHighlights",
"arguments": {
"file": "/a/b/file1.ts",
"line": 4,
"offset": 14
"offset": 14,
"filesToSearch": [
"/a/b/file1.ts"
]
},
"seq": 4,
"type": "request"
@ -274,36 +283,39 @@ Info 18 [00:00:33.000] response:
{
"response": [
{
"start": {
"line": 3,
"offset": 13
},
"end": {
"line": 3,
"offset": 16
},
"contextStart": {
"line": 3,
"offset": 12
},
"contextEnd": {
"line": 3,
"offset": 22
},
"file": "/a/b/file1.ts",
"isWriteAccess": true
},
{
"start": {
"line": 4,
"offset": 14
},
"end": {
"line": 4,
"offset": 17
},
"file": "/a/b/file1.ts",
"isWriteAccess": false
"highlightSpans": [
{
"start": {
"line": 3,
"offset": 13
},
"end": {
"line": 3,
"offset": 16
},
"contextStart": {
"line": 3,
"offset": 12
},
"contextEnd": {
"line": 3,
"offset": 22
},
"kind": "writtenReference"
},
{
"start": {
"line": 4,
"offset": 14
},
"end": {
"line": 4,
"offset": 17
},
"kind": "reference"
}
]
}
],
"responseRequired": true

View File

@ -319,11 +319,14 @@ Info 49 [00:01:42.000] response:
}
Info 50 [00:01:43.000] request:
{
"command": "occurrences",
"command": "documentHighlights",
"arguments": {
"file": "/a/b/projects/files/file1.ts",
"line": 1,
"offset": 11
"offset": 11,
"filesToSearch": [
"/a/b/projects/files/file1.ts"
]
},
"seq": 5,
"type": "request"