-
Notifications
You must be signed in to change notification settings - Fork 13k
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 14 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,21 @@ export function createLanguageService( | |
); | ||
} | ||
|
||
function getImports(fileName: string): readonly string[] { | ||
synchronizeHostData(); | ||
sandersn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) { | ||
if (!imports) imports = new Set(); | ||
imports.add(name); | ||
} | ||
sandersn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return imports ? arrayFrom(imports) : []; | ||
sandersn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const ls: LanguageService = { | ||
dispose, | ||
cleanupSemanticCache, | ||
|
@@ -3418,6 +3436,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', []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this supposed to be?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Project-related information for copilot like module, lib, target, etc; not implemented in this PR, but coming soon. (and already implemented by the C# extension and I think C++ as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But do we know how the structure will look like. May be add this when we actually set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not going to change substantially, although it may add some optional properties -- I believe there's a PR from the C++ team to do so. I'm going to start returning some project information as traits quite soon and C# is already doing so. So I'd like to add it now, and I can add any optional properties that we use then.