Add CopilotRelated command (#59963)

This commit is contained in:
Nathan Shively-Sanders
2024-09-26 16:10:41 -07:00
committed by GitHub
parent da1fb07db0
commit 52c59dbcbe
17 changed files with 298 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import {
__String,
ApplicableRefactorInfo,
ApplyCodeActionCommandResult,
arrayFrom,
AssignmentDeclarationKind,
BaseType,
BinaryExpression,
@@ -233,6 +234,7 @@ import {
Node,
NodeArray,
NodeFlags,
nodeIsSynthesized,
noop,
normalizePath,
normalizeSpans,
@@ -1602,6 +1604,7 @@ const invalidOperationsInPartialSemanticMode: readonly (keyof LanguageService)[]
"provideInlayHints",
"getSupportedCodeFixes",
"getPasteEdits",
"getImports",
];
const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [
@@ -3364,6 +3367,18 @@ 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,
@@ -3438,6 +3453,7 @@ export function createLanguageService(
preparePasteEditsForFile,
getPasteEdits,
mapCode,
getImports,
};
switch (languageServiceMode) {

View File

@@ -697,6 +697,7 @@ 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;