From c427a793e6e50a8eefa5aea65cb32b7435b05259 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 20 Jan 2023 17:13:55 -0800 Subject: [PATCH] Remove long deprecated occurrences request --- src/harness/client.ts | 13 - src/harness/fourslashImpl.ts | 11 +- src/harness/harnessLanguageService.ts | 3 - src/server/protocol.ts | 29 -- src/server/session.ts | 22 -- src/services/services.ts | 15 -- src/services/shims.ts | 14 - src/services/types.ts | 3 - .../unittests/tsserver/cancellationToken.ts | 6 +- .../unittests/tsserver/occurences.ts | 18 +- src/testRunner/unittests/tsserver/projects.ts | 7 +- .../reference/api/tsserverlibrary.d.ts | 29 -- tests/baselines/reference/api/typescript.d.ts | 2 - ...ould-be-marked-if-only-on-string-values.js | 254 +++++++++--------- ...-and-closed-affecting-multiple-projects.js | 7 +- 15 files changed, 164 insertions(+), 269 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index 435c367e4e7be..6939b8309440e 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -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.CommandTypes.Occurrences, args); - const response = this.processResponse(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 }; diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index c389edc28ab21..a59275f5c9d42 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -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(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) { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 71c6935260a6e..258d86e49bae6 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -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))); } diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 1ac6e1f495df0..50546bb8dce8f 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -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 diff --git a/src/server/session.ts b/src/server/session.ts index 762469e1f601d..a449b25ae5f24 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -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, ]; @@ -1762,24 +1761,6 @@ export class Session 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(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) { @@ -3380,9 +3361,6 @@ export class Session 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)); }, diff --git a/src/services/services.ts b/src/services/services.ts index ee3bb8e2be579..df57d45e59822 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -121,7 +121,6 @@ import { hasStaticModifier, hasSyntacticModifier, hasTabstop, - HighlightSpanKind, HostCancellationToken, hostGetCanonicalFileName, hostUsesCaseSensitiveFileNames, @@ -1531,7 +1530,6 @@ const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [ "getTypeDefinitionAtPosition", "getReferencesAtPosition", "findReferences", - "getOccurrencesAtPosition", "getDocumentHighlights", "getNavigateToItems", "getRenameInfo", @@ -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(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, diff --git a/src/services/shims.ts b/src/services/shims.ts index 0a9116c6dfc65..23c069de9669a 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -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})`, diff --git a/src/services/types.ts b/src/services/types.ts index ff726ff0663c7..246a0dd5733bd 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -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; diff --git a/src/testRunner/unittests/tsserver/cancellationToken.ts b/src/testRunner/unittests/tsserver/cancellationToken.ts index 4fb05770c6d6b..d50f95e9c234f 100644 --- a/src/testRunner/unittests/tsserver/cancellationToken.ts +++ b/src/testRunner/unittests/tsserver/cancellationToken.ts @@ -51,9 +51,9 @@ describe("unittests:: tsserver:: cancellationToken", () => { }); expectedRequestId = session.getNextSeq(); - session.executeCommandSeq({ - command: ts.server.protocol.CommandTypes.Occurrences, - arguments: { file: f1.path, line: 1, offset: 6 } + session.executeCommandSeq({ + command: ts.server.protocol.CommandTypes.DocumentHighlights, + arguments: { file: f1.path, line: 1, offset: 6, filesToSearch: [f1.path] } }); expectedRequestId = 2; diff --git a/src/testRunner/unittests/tsserver/occurences.ts b/src/testRunner/unittests/tsserver/occurences.ts index ea5ce71a038e0..07fe3c34c33d6 100644 --- a/src/testRunner/unittests/tsserver/occurences.ts +++ b/src/testRunner/unittests/tsserver/occurences.ts @@ -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({ - command: ts.server.protocol.CommandTypes.Occurrences, - arguments: { file: file1.path, line: 1, offset: 11 } + session.executeCommandSeq({ + command: ts.server.protocol.CommandTypes.DocumentHighlights, + arguments: { file: file1.path, line: 1, offset: 11, filesToSearch: [file1.path] } }); - session.executeCommandSeq({ - command: ts.server.protocol.CommandTypes.Occurrences, - arguments: { file: file1.path, line: 3, offset: 13 } + session.executeCommandSeq({ + command: ts.server.protocol.CommandTypes.DocumentHighlights, + arguments: { file: file1.path, line: 3, offset: 13, filesToSearch: [file1.path] } }); - session.executeCommandSeq({ - command: ts.server.protocol.CommandTypes.Occurrences, - arguments: { file: file1.path, line: 4, offset: 14 } + session.executeCommandSeq({ + 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); }); diff --git a/src/testRunner/unittests/tsserver/projects.ts b/src/testRunner/unittests/tsserver/projects.ts index a30f2704c1a26..45d8a7ad73c70 100644 --- a/src/testRunner/unittests/tsserver/projects.ts +++ b/src/testRunner/unittests/tsserver/projects.ts @@ -1113,12 +1113,13 @@ describe("unittests:: tsserver:: Projects", () => { }); // Actions on file1 would result in assert - session.executeCommandSeq({ - command: ts.server.protocol.CommandTypes.Occurrences, + session.executeCommandSeq({ + 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], } }); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index d37896300e8f8..9c7b27fae5ee1 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -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; @@ -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; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index c9eeb8a00a1a5..b14a19f8b3d6d 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -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; diff --git a/tests/baselines/reference/tsserver/occurences/should-be-marked-if-only-on-string-values.js b/tests/baselines/reference/tsserver/occurences/should-be-marked-if-only-on-string-values.js index df24c55ee11b9..9b53b5b65ddc2 100644 --- a/tests/baselines/reference/tsserver/occurences/should-be-marked-if-only-on-string-values.js +++ b/tests/baselines/reference/tsserver/occurences/should-be-marked-if-only-on-string-values.js @@ -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 diff --git a/tests/baselines/reference/tsserver/projects/files-opened-and-closed-affecting-multiple-projects.js b/tests/baselines/reference/tsserver/projects/files-opened-and-closed-affecting-multiple-projects.js index cf0cef9d2629b..7d03ca3f98323 100644 --- a/tests/baselines/reference/tsserver/projects/files-opened-and-closed-affecting-multiple-projects.js +++ b/tests/baselines/reference/tsserver/projects/files-opened-and-closed-affecting-multiple-projects.js @@ -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"