-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add CopilotRelated command #59963
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
Add CopilotRelated command #59963
Changes from all commits
19e027e
4db82ed
1851522
cb4ad45
7fddaaf
303b54a
ecfeaad
f09256e
4a188f7
5f1fb94
6d5ad47
2ad23d4
0608b78
fad24b5
da7748c
b1def98
8c4caee
6e27eea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { | |
__String, | ||
ApplicableRefactorInfo, | ||
ApplyCodeActionCommandResult, | ||
arrayFrom, | ||
AssignmentDeclarationKind, | ||
BaseType, | ||
BinaryExpression, | ||
|
@@ -233,6 +234,7 @@ import { | |
Node, | ||
NodeArray, | ||
NodeFlags, | ||
nodeIsSynthesized, | ||
noop, | ||
normalizePath, | ||
normalizeSpans, | ||
|
@@ -1593,6 +1595,7 @@ const invalidOperationsInPartialSemanticMode: readonly (keyof LanguageService)[] | |
"provideInlayHints", | ||
"getSupportedCodeFixes", | ||
"getPasteEdits", | ||
"getImports", | ||
]; | ||
|
||
const invalidOperationsInSyntacticMode: readonly (keyof LanguageService)[] = [ | ||
|
@@ -3345,6 +3348,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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it may happen that we have resolvedFileName = say "module.js" but its not part of program. Is this ok to send back that file name ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, files that are not part of the program are fine; we don't expect to get information from Typescript about them -- they are fine if they exist on disk. |
||
if (name) (imports ??= new Set()).add(name); | ||
} | ||
return imports ? arrayFrom(imports) : emptyArray; | ||
} | ||
|
||
const ls: LanguageService = { | ||
dispose, | ||
cleanupSemanticCache, | ||
|
@@ -3418,6 +3433,7 @@ export function createLanguageService( | |
getSupportedCodeFixes, | ||
getPasteEdits, | ||
mapCode, | ||
getImports, | ||
}; | ||
|
||
switch (languageServiceMode) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
///<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']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
///<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']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
///<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', []) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
///<reference path="fourslash.ts"/> | ||
|
||
// @Filename: /index.ts | ||
//// function foo() { | ||
//// return 1; | ||
//// } | ||
//// function bar() { | ||
//// return 2; | ||
//// } | ||
//// | ||
|
||
verify.getImports('/index.ts', []) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
///<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']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
///<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']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
///<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']) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
///<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']) |
Uh oh!
There was an error while loading. Please reload this page.