Skip to content
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

Merged
merged 18 commits into from
Sep 26, 2024
Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Sep 13, 2024

Add a command to provide information about a file for copilot.

Associated VSCode PR: microsoft/vscode#228610

  • I'm not sure what to name this yet. I expect this will be a catch-all command to provide information about a file.
  • I'm also not 100% sure this is going to get all the imports. @andrewbranch I expect you are the best person to ask about that.

@genlu you were interested in seeing this.

Add a command to provide information about a file for copilot.
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 13, 2024
@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @mjbvz, @zkat, and @joj for you. Feel free to loop in other consumers/maintainers if necessary.

src/services/services.ts Show resolved Hide resolved
src/server/session.ts Outdated Show resolved Hide resolved
@sandersn sandersn marked this pull request as ready for review September 20, 2024 16:03
@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

I couldn't come up with a test for JSX implicit import base, so that
code may be incorrect.
I also wonder whether it's necessary to explicitly only skip tslib and
jsx implicit import bases. Probably either all implicit imports or none
of them should be skipped.

In fact, if the content of synthetic imports usually varies, it would be
better to include them. If they're the same, the LLM will have already
seen them many times.
The code is a lot simpler now.
src/harness/fourslashInterfaceImpl.ts Outdated Show resolved Hide resolved
@sandersn sandersn enabled auto-merge (squash) September 24, 2024 17:42

export interface CopilotRelatedItems {
relatedFiles: readonly string[];
traits: { name: string; value: string; }[];
Copy link
Member

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?

Copy link
Member Author

@sandersn sandersn Sep 25, 2024

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)

Copy link
Member

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?

Copy link
Member Author

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.

specifiers = specifiers.slice(specifiers.findIndex(nodeIsSynthesized) + 1);
if (specifiers.length === 0) return [];
for (const specifier of specifiers) {
const name = program.getResolvedModuleFromModuleSpecifier(specifier, file)?.resolvedModule?.resolvedFileName;
Copy link
Member

Choose a reason for hiding this comment

The 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 ?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

src/services/services.ts Outdated Show resolved Hide resolved
src/services/services.ts Outdated Show resolved Hide resolved
const imports: Set<string> = new Set();
let specifiers = file.imports;
specifiers = specifiers.slice(specifiers.findIndex(nodeIsSynthesized) + 1);
if (specifiers.length === 0) return [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return emptyArray

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought emptyArray was slower than []. Also, what happens if somebody mutates the array returned from getImports? Is that a concern for services?

src/services/services.ts Outdated Show resolved Hide resolved
src/services/services.ts Outdated Show resolved Hide resolved
sandersn and others added 2 commits September 25, 2024 15:34
Use emptyArray instead of []

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
Inline init of lazily constructed Set

Co-authored-by: Sheetal Nandi <shkamat@microsoft.com>
@sandersn sandersn merged commit 52c59db into microsoft:main Sep 26, 2024
32 checks passed
@sandersn sandersn deleted the add-copilotrelated-command branch September 27, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants