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

Register Copilot relatedFilesProvider for C# #7578

Merged
merged 3 commits into from
Sep 20, 2024
Merged

Conversation

genlu
Copy link
Member

@genlu genlu commented Sep 18, 2024

registerRelatedFilesProvider is a new method on the copilot extension. RelatedDocumentsHandler is implemented here in Roslyn language server.

@genlu genlu requested a review from a team as a code owner September 18, 2024 23:50
}
await ext.activate();
const relatedAPI = ext.exports as
| {
Copy link
Member

Choose a reason for hiding this comment

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

Can you create a separate type definition for this? It's a little hard to read inline

| undefined;
if (!relatedAPI) {
channel.appendLine(
'Incompatible GitHub Copilot extension installed. Skipping call to `registerRelatedFilesProvider`'
Copy link
Member

Choose a reason for hiding this comment

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

It is possible to show a notification asking the user to upgrade to a new version if you think it would be valuable. But I'd only do that if the extension is already installed

export async function registerCopilotExtension(languageServer: RoslynLanguageServer, channel: vscode.OutputChannel) {
const ext = vscode.extensions.getExtension('github.copilot');
if (!ext) {
channel.appendLine('GitHub Copilot extension not installed. Skipping call to `registerRelatedFilesProvider`');
Copy link
Member

Choose a reason for hiding this comment

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

These are technically user visible strings. Consider making it more evident want this actually means in terms of feature set

Copy link
Member Author

@genlu genlu Sep 19, 2024

Choose a reason for hiding this comment

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

hmm, maybe I should move this to the trace log. This is intended to provide additional context implicitly (i.e. no user facing option to turn it on and off)

Copy link
Member

Choose a reason for hiding this comment

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

Also fine with this being written when trace logging is enabled. I would still write to the C# output window though

e.g. https://github.com/dotnet/vscode-csharp/blob/main/src/lsptoolshost/roslynLanguageServer.ts#L614

src/lsptoolshost/copilot.ts Outdated Show resolved Hide resolved
src/lsptoolshost/copilot.ts Outdated Show resolved Hide resolved

relatedAPI.registerRelatedFilesProvider(id, async (uri) => {
const writeOutput = (output: CopilotRelatedDocumentsReport[], builder: vscode.Uri[] | null) => {
if (output) {
Copy link
Member

Choose a reason for hiding this comment

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

If the output is actually nullable, it probably should be output?: CopilotRelatedDocumentsReport[]. Otherwise this check should be removed.

The client response type is defined as non-null in roslynProtocol, but the server defines the response as nullable -https://github.com/dotnet/roslyn/pull/74918/files#diff-0b28133c769dc0e92c52213acbee40648526328ab9cec6c7c0e2a9b5a43fa76bR70

It doesn't look like the server ever returns null though - so potentially the server annotation needs to be updated?

src/lsptoolshost/copilot.ts Outdated Show resolved Hide resolved
}
);

await responsePromise.then(
Copy link
Member

Choose a reason for hiding this comment

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

I suspect the other places using languageServer.sendRequestWithProgress need to be updated - but I think it should be fine to just await it directly (in a try catch if you want to handle errors).

src/lsptoolshost/roslynProtocol.ts Outdated Show resolved Hide resolved
@genlu
Copy link
Member Author

genlu commented Sep 19, 2024

@dibarbet Could you please take another look? (also I think this doesn't require dotnet/roslyn#75176 to work, since the protocol is still compatible with change in this PR, pls correct me if I was wrong)

Copy link
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

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

@dibarbet Could you please take another look? (also I think this doesn't require dotnet/roslyn#75176 to work, since the protocol is still compatible with change in this PR, pls correct me if I was wrong)

I believe so, since it was optional.

@@ -1036,6 +1037,7 @@ export async function activateRoslynLanguageServer(
);

registerLanguageStatusItems(context, languageServer, languageServerEvents);
await registerCopilotExtensionAsync(languageServer, _traceChannel);
Copy link
Member

Choose a reason for hiding this comment

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

I'd recommend not using the trace channel - that is generally just for LSP trace logs. What it should do is write to the normal output channel only when trace logging is enabled

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

src/lsptoolshost/copilot.ts Outdated Show resolved Hide resolved
@genlu genlu merged commit 9d10433 into dotnet:main Sep 20, 2024
16 checks passed
@genlu genlu deleted the relatedFiles branch September 20, 2024 17:04
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.

2 participants