From 79ea5a5b358c41aac32866737deb7e17c73005a0 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:33:00 -0800 Subject: [PATCH] Stub out copilotRelated command (#60488) --- src/harness/client.ts | 1 - src/harness/fourslashImpl.ts | 22 ---- src/harness/fourslashInterfaceImpl.ts | 9 -- src/server/protocol.ts | 13 +-- src/server/session.ts | 10 +- src/services/services.ts | 16 --- src/services/types.ts | 1 - tests/baselines/reference/api/typescript.d.ts | 11 -- tests/cases/fourslash/fourslash.ts | 1 - tests/cases/fourslash/getImportsDuplicate.ts | 16 --- tests/cases/fourslash/getImportsDynamic.ts | 12 -- tests/cases/fourslash/getImportsJSXFactory.ts | 108 ------------------ tests/cases/fourslash/getImportsNone.ts | 12 -- tests/cases/fourslash/getImportsOne.ts | 14 --- tests/cases/fourslash/getImportsOneJs.ts | 15 --- tests/cases/fourslash/getImportsReexport.ts | 15 --- tests/cases/fourslash/getImportsTslib.ts | 19 --- 17 files changed, 5 insertions(+), 290 deletions(-) delete mode 100644 tests/cases/fourslash/getImportsDuplicate.ts delete mode 100644 tests/cases/fourslash/getImportsDynamic.ts delete mode 100644 tests/cases/fourslash/getImportsJSXFactory.ts delete mode 100644 tests/cases/fourslash/getImportsNone.ts delete mode 100644 tests/cases/fourslash/getImportsOne.ts delete mode 100644 tests/cases/fourslash/getImportsOneJs.ts delete mode 100644 tests/cases/fourslash/getImportsReexport.ts delete mode 100644 tests/cases/fourslash/getImportsTslib.ts diff --git a/src/harness/client.ts b/src/harness/client.ts index 1b367d56a6b..c735ffa7f3e 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -801,7 +801,6 @@ export class SessionClient implements LanguageService { } mapCode: typeof notImplemented = notImplemented; - getImports: typeof notImplemented = notImplemented; private createFileLocationOrRangeRequestArgs(positionOrRange: number | TextRange, fileName: string): protocol.FileLocationOrRangeRequestArgs { return typeof positionOrRange === "number" diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index b2a7bf9a15b..81ffed9cd69 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -4652,28 +4652,6 @@ ${changes.join("\n// ---\n")} ${after}`; this.baseline("mapCode", baseline, ".mapCode.ts"); } - - public verifyGetImports(fileName: string, expectedImports: string[]): void { - const actualImports = this.languageService.getImports(fileName); - if (actualImports.length !== expectedImports.length) { - throw new Error(`Expected ${expectedImports.length} imports for ${fileName}, got ${actualImports.length} - Expected: -${expectedImports} - Actual: -${actualImports} -`); - } - for (let i = 0; i < expectedImports.length; i++) { - if (actualImports[i] !== expectedImports[i]) { - throw new Error(`Expected at ${fileName} index ${i}: ${expectedImports[i]}, got ${actualImports[i]} - Expected: -${expectedImports} - Actual: -${actualImports} -`); - } - } - } } function updateTextRangeForTextChanges({ pos, end }: ts.TextRange, textChanges: readonly ts.TextChange[]): ts.TextRange { diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index 530b66c733d..bb10cbf744a 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -257,10 +257,6 @@ export class VerifyNegatable { public baselineMapCode(ranges: FourSlash.Range[][], changes: string[] = []): void { this.state.baselineMapCode(ranges, changes); } - - public getImports(fileName: string, imports: string[]): void { - return this.state.verifyGetImports(fileName, imports); - } } export interface CompletionsResult { @@ -2051,8 +2047,3 @@ export interface RenameOptions { readonly providePrefixAndSuffixTextForRename?: boolean; readonly quotePreference?: "auto" | "double" | "single"; } - -export interface VerifyGetImportsOptions { - fileName: string; - imports: string[]; -} diff --git a/src/server/protocol.ts b/src/server/protocol.ts index d4e7f60bbf0..232b224786e 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -202,6 +202,7 @@ export const enum CommandTypes { ProvideInlayHints = "provideInlayHints", WatchChange = "watchChange", MapCode = "mapCode", + /** @internal */ CopilotRelated = "copilotRelated", } @@ -2417,18 +2418,6 @@ export interface MapCodeResponse extends Response { body: readonly FileCodeEdits[]; } -export interface CopilotRelatedRequest extends FileRequest { - command: CommandTypes.CopilotRelated; - arguments: FileRequestArgs; -} - -export interface CopilotRelatedItems { - relatedFiles: readonly string[]; -} - -export interface CopilotRelatedResponse extends Response { - body: CopilotRelatedItems; -} /** * Synchronous request for semantic diagnostics of one file. */ diff --git a/src/server/session.ts b/src/server/session.ts index 3be8045143f..1019a44d856 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -2052,11 +2052,9 @@ export class Session implements EventSender { return this.mapTextChangesToCodeEdits(changes); } - private getCopilotRelatedInfo(args: protocol.FileRequestArgs): protocol.CopilotRelatedItems { - const { file, project } = this.getFileAndProject(args); - + private getCopilotRelatedInfo(): { relatedFiles: never[]; } { return { - relatedFiles: project.getLanguageService().getImports(file), + relatedFiles: [], }; } @@ -3802,8 +3800,8 @@ export class Session implements EventSender { [protocol.CommandTypes.MapCode]: (request: protocol.MapCodeRequest) => { return this.requiredResponse(this.mapCode(request.arguments)); }, - [protocol.CommandTypes.CopilotRelated]: (request: protocol.CopilotRelatedRequest) => { - return this.requiredResponse(this.getCopilotRelatedInfo(request.arguments)); + [protocol.CommandTypes.CopilotRelated]: () => { + return this.requiredResponse(this.getCopilotRelatedInfo()); }, })); diff --git a/src/services/services.ts b/src/services/services.ts index c16aad81180..fb5e9a08579 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2,7 +2,6 @@ import { __String, ApplicableRefactorInfo, ApplyCodeActionCommandResult, - arrayFrom, AssignmentDeclarationKind, BaseType, BinaryExpression, @@ -234,7 +233,6 @@ import { Node, NodeArray, NodeFlags, - nodeIsSynthesized, noop, normalizePath, normalizeSpans, @@ -1604,7 +1602,6 @@ const invalidOperationsInPartialSemanticMode: readonly (keyof LanguageService)[] "provideInlayHints", "getSupportedCodeFixes", "getPasteEdits", - "getImports", ]; const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [ @@ -3381,18 +3378,6 @@ export function createLanguageService( ); } - function getImports(fileName: string): readonly string[] { - synchronizeHostData(); - const file = getValidSourceFile(fileName); - let imports: Set | undefined; - for (const specifier of file.imports) { - if (nodeIsSynthesized(specifier)) continue; - const name = program.getResolvedModuleFromModuleSpecifier(specifier, file)?.resolvedModule?.resolvedFileName; - if (name) (imports ??= new Set()).add(name); - } - return imports ? arrayFrom(imports) : emptyArray; - } - const ls: LanguageService = { dispose, cleanupSemanticCache, @@ -3467,7 +3452,6 @@ export function createLanguageService( preparePasteEditsForFile, getPasteEdits, mapCode, - getImports, }; switch (languageServiceMode) { diff --git a/src/services/types.ts b/src/services/types.ts index b8cec56bb58..39c1636fefc 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -699,7 +699,6 @@ export interface LanguageService { getSupportedCodeFixes(fileName?: string): readonly string[]; /** @internal */ mapCode(fileName: string, contents: string[], focusLocations: TextSpan[][] | undefined, formatOptions: FormatCodeSettings, preferences: UserPreferences): readonly FileTextChanges[]; - /** @internal */ getImports(fileName: string): readonly string[]; dispose(): void; preparePasteEditsForFile(fileName: string, copiedTextRanges: TextRange[]): boolean; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 4a0b8a9e151..11a12e97d4b 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -123,7 +123,6 @@ declare namespace ts { ProvideInlayHints = "provideInlayHints", WatchChange = "watchChange", MapCode = "mapCode", - CopilotRelated = "copilotRelated", } /** * A TypeScript Server message @@ -1839,16 +1838,6 @@ declare namespace ts { export interface MapCodeResponse extends Response { body: readonly FileCodeEdits[]; } - export interface CopilotRelatedRequest extends FileRequest { - command: CommandTypes.CopilotRelated; - arguments: FileRequestArgs; - } - export interface CopilotRelatedItems { - relatedFiles: readonly string[]; - } - export interface CopilotRelatedResponse extends Response { - body: CopilotRelatedItems; - } /** * Synchronous request for semantic diagnostics of one file. */ diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 54d72769910..3b07ac5a498 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -472,7 +472,6 @@ declare namespace FourSlashInterface { } }): void; baselineMapCode(ranges: Range[][], changes: string[]): void; - getImports(fileName: string, imports: string[]): void; } class edit { caretPosition(): Marker; diff --git a/tests/cases/fourslash/getImportsDuplicate.ts b/tests/cases/fourslash/getImportsDuplicate.ts deleted file mode 100644 index 1e4e069978a..00000000000 --- a/tests/cases/fourslash/getImportsDuplicate.ts +++ /dev/null @@ -1,16 +0,0 @@ -/// - -// @Filename: /first.ts -//// export function foo() { -//// return 1; -//// } -//// export function bar() { -//// return 2; -//// } - -// @Filename: /index.ts -//// import { foo } from "./first"; -//// import { bar } from './first'; -//// console.log(foo() + bar()) - -verify.getImports('/index.ts', ['/first.ts']) diff --git a/tests/cases/fourslash/getImportsDynamic.ts b/tests/cases/fourslash/getImportsDynamic.ts deleted file mode 100644 index 0a16718bdcb..00000000000 --- a/tests/cases/fourslash/getImportsDynamic.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -// @Filename: /first.ts -//// export function foo() { -//// return 1; -//// } -// @Filename: /index.ts -//// let bar: typeof import('./first').foo = function bar() { -//// return 2; -//// } - -verify.getImports('/index.ts', ['/first.ts']) diff --git a/tests/cases/fourslash/getImportsJSXFactory.ts b/tests/cases/fourslash/getImportsJSXFactory.ts deleted file mode 100644 index 2ccc885443a..00000000000 --- a/tests/cases/fourslash/getImportsJSXFactory.ts +++ /dev/null @@ -1,108 +0,0 @@ -/// - -// @strict: true -// @jsx: react-jsx -// @jsxImportSource: preact -// @filename: /node_modules/preact/index.d.ts -//// type Defaultize = -//// // Distribute over unions -//// Props extends any // Make any properties included in Default optional -//// ? Partial>> & -//// // Include the remaining properties from Props -//// Pick> -//// : never; -//// export namespace JSXInternal { -//// interface HTMLAttributes { } -//// interface SVGAttributes { } -//// type LibraryManagedAttributes = Component extends { -//// defaultProps: infer Defaults; -//// } -//// ? Defaultize -//// : Props; -//// -//// interface IntrinsicAttributes { -//// key?: any; -//// } -//// -//// interface Element extends VNode { } -//// -//// interface ElementClass extends Component { } -//// -//// interface ElementAttributesProperty { -//// props: any; -//// } -//// -//// interface ElementChildrenAttribute { -//// children: any; -//// } -//// -//// interface IntrinsicElements { -//// div: HTMLAttributes; -//// } -//// } -//// export const Fragment: unique symbol; -//// export type ComponentType = {}; -//// export type ComponentChild = {}; -//// export type ComponentChildren = {}; -//// export type VNode = {}; -//// export type Attributes = {}; -//// export type Component = {}; -// @filename: /node_modules/preact/jsx-runtime/index.d.ts -//// export { Fragment } from '..'; -//// import { -//// ComponentType, -//// ComponentChild, -//// ComponentChildren, -//// VNode, -//// Attributes -//// } from '..'; -//// import { JSXInternal } from '..'; -//// -//// export function jsx( -//// type: string, -//// props: JSXInternal.HTMLAttributes & -//// JSXInternal.SVGAttributes & -//// Record & { children?: ComponentChild }, -//// key?: string -//// ): VNode; -//// export function jsx

( -//// type: ComponentType

, -//// props: Attributes & P & { children?: ComponentChild }, -//// key?: string -//// ): VNode; -//// -//// -//// export function jsxs( -//// type: string, -//// props: JSXInternal.HTMLAttributes & -//// JSXInternal.SVGAttributes & -//// Record & { children?: ComponentChild[] }, -//// key?: string -//// ): VNode; -//// export function jsxs

( -//// type: ComponentType

, -//// props: Attributes & P & { children?: ComponentChild[] }, -//// key?: string -//// ): VNode; -//// -//// -//// export function jsxDEV( -//// type: string, -//// props: JSXInternal.HTMLAttributes & -//// JSXInternal.SVGAttributes & -//// Record & { children?: ComponentChildren }, -//// key?: string -//// ): VNode; -//// export function jsxDEV

( -//// type: ComponentType

, -//// props: Attributes & P & { children?: ComponentChildren }, -//// key?: string -//// ): VNode; -//// -//// export import JSX = JSXInternal; -//// -// @filename: /index.tsx -//// export const Comp = () =>

; - -verify.noErrors() -verify.getImports('/index.tsx', []) diff --git a/tests/cases/fourslash/getImportsNone.ts b/tests/cases/fourslash/getImportsNone.ts deleted file mode 100644 index d408cb6f14d..00000000000 --- a/tests/cases/fourslash/getImportsNone.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -// @Filename: /index.ts -//// function foo() { -//// return 1; -//// } -//// function bar() { -//// return 2; -//// } -//// - -verify.getImports('/index.ts', []) diff --git a/tests/cases/fourslash/getImportsOne.ts b/tests/cases/fourslash/getImportsOne.ts deleted file mode 100644 index 7ebf0a51f2b..00000000000 --- a/tests/cases/fourslash/getImportsOne.ts +++ /dev/null @@ -1,14 +0,0 @@ -/// - -// @Filename: /first.ts -//// export function foo() { -//// return 1; -//// } -// @Filename: /index.ts -//// import { foo } from "./first"; -//// function bar() { -//// return 2; -//// } -//// - -verify.getImports('/index.ts', ['/first.ts']) diff --git a/tests/cases/fourslash/getImportsOneJs.ts b/tests/cases/fourslash/getImportsOneJs.ts deleted file mode 100644 index 1d9157f73e9..00000000000 --- a/tests/cases/fourslash/getImportsOneJs.ts +++ /dev/null @@ -1,15 +0,0 @@ -/// - -// @checkJs: true -// @Filename: /first.ts -//// export function foo() { -//// return 1; -//// } -// @Filename: /index.js -//// const { foo } = require("./first"); -//// function bar() { -//// return 2; -//// } -//// - -verify.getImports('/index.js', ['/first.ts']) diff --git a/tests/cases/fourslash/getImportsReexport.ts b/tests/cases/fourslash/getImportsReexport.ts deleted file mode 100644 index d5832405ae3..00000000000 --- a/tests/cases/fourslash/getImportsReexport.ts +++ /dev/null @@ -1,15 +0,0 @@ -/// - -// @Filename: /first.ts -//// export function foo() { -//// return 1; -//// } -// @Filename: /index.ts -//// export { foo } from "./first"; -//// function bar() { -//// return 2; -//// } -//// - - -verify.getImports('/index.ts', ['/first.ts']) diff --git a/tests/cases/fourslash/getImportsTslib.ts b/tests/cases/fourslash/getImportsTslib.ts deleted file mode 100644 index 8f0519a3b08..00000000000 --- a/tests/cases/fourslash/getImportsTslib.ts +++ /dev/null @@ -1,19 +0,0 @@ -/// - -// @importHelpers: true -// @target: es2015 -// @lib: es2015 -// @module: commonjs -// @Filename: /node_modules/tslib/index.d.ts -//// export function __awaiter(...args: any): any; -// @Filename: /first.ts -//// export function foo() { -//// return 2 -//// } -// @Filename: /index.ts -//// export async function importer() { -//// const mod = await import("./first"); -//// } - -verify.noErrors() -verify.getImports('/index.ts', ['/first.ts'])