Stub out copilotRelated command (#60488)

This commit is contained in:
Nathan Shively-Sanders 2024-11-13 08:33:00 -08:00 коммит произвёл GitHub
Родитель b58ac4abf2
Коммит 79ea5a5b35
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
17 изменённых файлов: 5 добавлений и 290 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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.
*/

Просмотреть файл

@ -2052,11 +2052,9 @@ export class Session<TMessage = string> 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<TMessage = string> 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());
},
}));

Просмотреть файл

@ -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<string> | 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) {

Просмотреть файл

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

11
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.
*/

Просмотреть файл

@ -472,7 +472,6 @@ declare namespace FourSlashInterface {
}
}): void;
baselineMapCode(ranges: Range[][], changes: string[]): void;
getImports(fileName: string, imports: string[]): void;
}
class edit {
caretPosition(): Marker;

Просмотреть файл

@ -1,16 +0,0 @@
///<reference path="fourslash.ts"/>
// @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'])

Просмотреть файл

@ -1,12 +0,0 @@
///<reference path="fourslash.ts"/>
// @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'])

Просмотреть файл

@ -1,108 +0,0 @@
///<reference path="fourslash.ts"/>
// @strict: true
// @jsx: react-jsx
// @jsxImportSource: preact
// @filename: /node_modules/preact/index.d.ts
//// type Defaultize<Props, Defaults> =
//// // Distribute over unions
//// Props extends any // Make any properties included in Default optional
//// ? Partial<Pick<Props, Extract<keyof Props, keyof Defaults>>> &
//// // Include the remaining properties from Props
//// Pick<Props, Exclude<keyof Props, keyof Defaults>>
//// : never;
//// export namespace JSXInternal {
//// interface HTMLAttributes<T = {}> { }
//// interface SVGAttributes<T = {}> { }
//// type LibraryManagedAttributes<Component, Props> = Component extends {
//// defaultProps: infer Defaults;
//// }
//// ? Defaultize<Props, Defaults>
//// : Props;
////
//// interface IntrinsicAttributes {
//// key?: any;
//// }
////
//// interface Element extends VNode<any> { }
////
//// interface ElementClass extends Component<any, any> { }
////
//// interface ElementAttributesProperty {
//// props: any;
//// }
////
//// interface ElementChildrenAttribute {
//// children: any;
//// }
////
//// interface IntrinsicElements {
//// div: HTMLAttributes;
//// }
//// }
//// export const Fragment: unique symbol;
//// export type ComponentType<T = {}> = {};
//// export type ComponentChild = {};
//// export type ComponentChildren = {};
//// export type VNode<T = {}> = {};
//// export type Attributes = {};
//// export type Component<T = {}, U = {}> = {};
// @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<string, any> & { children?: ComponentChild },
//// key?: string
//// ): VNode<any>;
//// export function jsx<P>(
//// type: ComponentType<P>,
//// props: Attributes & P & { children?: ComponentChild },
//// key?: string
//// ): VNode<any>;
////
////
//// export function jsxs(
//// type: string,
//// props: JSXInternal.HTMLAttributes &
//// JSXInternal.SVGAttributes &
//// Record<string, any> & { children?: ComponentChild[] },
//// key?: string
//// ): VNode<any>;
//// export function jsxs<P>(
//// type: ComponentType<P>,
//// props: Attributes & P & { children?: ComponentChild[] },
//// key?: string
//// ): VNode<any>;
////
////
//// export function jsxDEV(
//// type: string,
//// props: JSXInternal.HTMLAttributes &
//// JSXInternal.SVGAttributes &
//// Record<string, any> & { children?: ComponentChildren },
//// key?: string
//// ): VNode<any>;
//// export function jsxDEV<P>(
//// type: ComponentType<P>,
//// props: Attributes & P & { children?: ComponentChildren },
//// key?: string
//// ): VNode<any>;
////
//// export import JSX = JSXInternal;
////
// @filename: /index.tsx
//// export const Comp = () => <div></div>;
verify.noErrors()
verify.getImports('/index.tsx', [])

Просмотреть файл

@ -1,12 +0,0 @@
///<reference path="fourslash.ts"/>
// @Filename: /index.ts
//// function foo() {
//// return 1;
//// }
//// function bar() {
//// return 2;
//// }
////
verify.getImports('/index.ts', [])

Просмотреть файл

@ -1,14 +0,0 @@
///<reference path="fourslash.ts"/>
// @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'])

Просмотреть файл

@ -1,15 +0,0 @@
///<reference path="fourslash.ts"/>
// @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'])

Просмотреть файл

@ -1,15 +0,0 @@
///<reference path="fourslash.ts"/>
// @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'])

Просмотреть файл

@ -1,19 +0,0 @@
///<reference path="fourslash.ts"/>
// @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'])