Skip to content

Commit

Permalink
🤖 Pick PR #60488 (Stub out copilotRelated command) into release-5.7 (#…
Browse files Browse the repository at this point in the history
…60495)

Co-authored-by: Nathan Shively-Sanders <[email protected]>
  • Loading branch information
typescript-bot and sandersn authored Nov 13, 2024
1 parent c1216de commit 3140dbb
Show file tree
Hide file tree
Showing 17 changed files with 5 additions and 290 deletions.
1 change: 0 additions & 1 deletion src/harness/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,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 @@ -4639,28 +4639,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: 1 addition & 12 deletions src/server/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export const enum CommandTypes {
ProvideInlayHints = "provideInlayHints",
WatchChange = "watchChange",
MapCode = "mapCode",
/** @internal */
CopilotRelated = "copilotRelated",
}

Expand Down Expand Up @@ -2407,18 +2408,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
10 changes: 4 additions & 6 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
};
}

Expand Down Expand Up @@ -3801,8 +3799,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());
},
}));

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 @@ -3367,18 +3364,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 @@ -3453,7 +3438,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 @@ -697,7 +697,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
11 changes: 0 additions & 11 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 @@ -1831,16 +1830,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
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.

15 changes: 0 additions & 15 deletions tests/cases/fourslash/getImportsOneJs.ts

This file was deleted.

15 changes: 0 additions & 15 deletions tests/cases/fourslash/getImportsReexport.ts

This file was deleted.

Loading

0 comments on commit 3140dbb

Please sign in to comment.