Skip to content

Revert "Add CopilotRelated command (#59963)" #60486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 0 additions & 22 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions src/harness/fourslashInterfaceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -2051,8 +2047,3 @@ export interface RenameOptions {
readonly providePrefixAndSuffixTextForRename?: boolean;
readonly quotePreference?: "auto" | "double" | "single";
}

export interface VerifyGetImportsOptions {
fileName: string;
imports: string[];
}
13 changes: 0 additions & 13 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ export const enum CommandTypes {
ProvideInlayHints = "provideInlayHints",
WatchChange = "watchChange",
MapCode = "mapCode",
CopilotRelated = "copilotRelated",
}

/**
Expand Down Expand Up @@ -2417,18 +2416,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.
*/
Expand Down
13 changes: 1 addition & 12 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,6 @@ const invalidPartialSemanticModeCommands: readonly protocol.CommandTypes[] = [
protocol.CommandTypes.ProvideCallHierarchyIncomingCalls,
protocol.CommandTypes.ProvideCallHierarchyOutgoingCalls,
protocol.CommandTypes.GetPasteEdits,
protocol.CommandTypes.CopilotRelated,
];

const invalidSyntacticModeCommands: readonly protocol.CommandTypes[] = [
Expand Down Expand Up @@ -2032,6 +2031,7 @@ export class Session<TMessage = string> implements EventSender {
};
});
}

private mapCode(args: protocol.MapCodeRequestArgs): protocol.FileCodeEdits[] {
const formatOptions = this.getHostFormatOptions();
const preferences = this.getHostPreferences();
Expand All @@ -2052,14 +2052,6 @@ export class Session<TMessage = string> implements EventSender {
return this.mapTextChangesToCodeEdits(changes);
}

private getCopilotRelatedInfo(args: protocol.FileRequestArgs): protocol.CopilotRelatedItems {
const { file, project } = this.getFileAndProject(args);

return {
relatedFiles: project.getLanguageService().getImports(file),
};
}

private setCompilerOptionsForInferredProjects(args: protocol.SetCompilerOptionsForInferredProjectsArgs): void {
this.projectService.setCompilerOptionsForInferredProjects(args.options, args.projectRootPath);
}
Expand Down Expand Up @@ -3802,9 +3794,6 @@ 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));
},
}));

public addProtocolHandler(command: string, handler: (request: protocol.Request) => HandlerResponse): void {
Expand Down
16 changes: 0 additions & 16 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
__String,
ApplicableRefactorInfo,
ApplyCodeActionCommandResult,
arrayFrom,
AssignmentDeclarationKind,
BaseType,
BinaryExpression,
Expand Down Expand Up @@ -234,7 +233,6 @@ import {
Node,
NodeArray,
NodeFlags,
nodeIsSynthesized,
noop,
normalizePath,
normalizeSpans,
Expand Down Expand Up @@ -1604,7 +1602,6 @@ const invalidOperationsInPartialSemanticMode: readonly (keyof LanguageService)[]
"provideInlayHints",
"getSupportedCodeFixes",
"getPasteEdits",
"getImports",
];

const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -3467,7 +3452,6 @@ export function createLanguageService(
preparePasteEditsForFile,
getPasteEdits,
mapCode,
getImports,
};

switch (languageServiceMode) {
Expand Down
1 change: 0 additions & 1 deletion src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ declare namespace ts {
ProvideInlayHints = "provideInlayHints",
WatchChange = "watchChange",
MapCode = "mapCode",
CopilotRelated = "copilotRelated",
}
/**
* A TypeScript Server message
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -3534,7 +3523,6 @@ declare namespace ts {
private getDocumentHighlights;
private provideInlayHints;
private mapCode;
private getCopilotRelatedInfo;
private setCompilerOptionsForInferredProjects;
private getProjectInfo;
private getProjectInfoWorker;
Expand Down
1 change: 0 additions & 1 deletion tests/cases/fourslash/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,6 @@ declare namespace FourSlashInterface {
}
}): void;
baselineMapCode(ranges: Range[][], changes: string[]): void;
getImports(fileName: string, imports: string[]): void;
}
class edit {
caretPosition(): Marker;
Expand Down
16 changes: 0 additions & 16 deletions tests/cases/fourslash/getImportsDuplicate.ts

This file was deleted.

12 changes: 0 additions & 12 deletions tests/cases/fourslash/getImportsDynamic.ts

This file was deleted.

108 changes: 0 additions & 108 deletions tests/cases/fourslash/getImportsJSXFactory.ts

This file was deleted.

12 changes: 0 additions & 12 deletions tests/cases/fourslash/getImportsNone.ts

This file was deleted.

14 changes: 0 additions & 14 deletions tests/cases/fourslash/getImportsOne.ts

This file was deleted.

Loading