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

TS extension: register call to CopilotRelated with copilot extension #228610

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sandersn
Copy link
Member

registerRelatedFilesProvider is a new method on the copilot extension. CopilotRelated is a new tsserver command that provides information from tsserver to copilot. (The information is not necessarily copilot-specific, of course.)

This code is quite far from done:

  • The new code is likely not in the right place.
  • It depends on Add CopilotRelated command TypeScript#59963 to be available -- the typescript protocol doesn't include CopilotRelated yet.
  • Cancellation is not done right.
  • The whole thing needs to be tested.

However, I want to make it available so I can get comments on it.

registerRelatedFilesProvider is a new method on the copilot extension.
CopilotRelated is a new tsserver command that provides information from
tsserver to copilot. (The information is not necessarily
copilot-specific, of course.)
Copy link

@Thanksyou23 Thanksyou23 left a comment

Choose a reason for hiding this comment

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

sandersn:typescript-relatedfiles-imports

@@ -150,6 +151,60 @@ export default class TypeScriptServiceClientHost extends Disposable {
standardFileExtensions: [],
}, onCompletionAccepted);
}
// TODO: Still probably isn't the right place for this
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be registered as a language feature? That way it only gets activated when our other language features activate

// TODO: Still probably isn't the right place for this
const ext = vscode.extensions.getExtension('github.copilot');
if (!ext) {
vscode.window.showErrorMessage(vscode.l10n.t('Could not find related-files extension'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Expected so should not show a user error

}
// TODO: This compiles but will never cancel; this needs a token that somebody might actually cancel.
const cancel = new vscode.CancellationTokenSource();
const response = await this.client.execute('copilotRelated', { file, }, cancel.token);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have nulToken that you can use for this

if (response.type !== 'response' || !response.body) {
return [];
}
return response.body.map(vscode.Uri.file);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you want client.toResource instead. That will handle non file: uris

callback: (uri: vscode.Uri) => Promise<{ entries: vscode.Uri[]; traits?: { name: string; value: string }[] }>
): void;
} | undefined;
if (relatedAPI) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this also need to be gated on the TS server version?

extensionId: 'vscode.typescript-language-features',
languageId
};
relatedAPI.registerRelatedFilesProvider(id, async uri => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does copilot pass a cancellation token? If not, we should request that it does

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants