-
Notifications
You must be signed in to change notification settings - Fork 685
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
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
import { CSharpExtensionId } from '../constants/csharpExtensionId'; | ||
import { CopilotRelatedDocumentsReport, CopilotRelatedDocumentsRequest } from './roslynProtocol'; | ||
import { RoslynLanguageServer } from './roslynLanguageServer'; | ||
import { UriConverter } from './uriConverter'; | ||
import { TextDocumentIdentifier } from 'vscode-languageserver-protocol'; | ||
|
||
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`'); | ||
return; | ||
} | ||
await ext.activate(); | ||
const relatedAPI = ext.exports as | ||
| { | ||
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. Can you create a separate type definition for this? It's a little hard to read inline |
||
registerRelatedFilesProvider( | ||
providerId: { extensionId: string; languageId: string }, | ||
callback: ( | ||
uri: vscode.Uri | ||
) => Promise<{ entries: vscode.Uri[]; traits?: { name: string; value: string }[] }> | ||
): void; | ||
} | ||
| undefined; | ||
if (!relatedAPI) { | ||
channel.appendLine( | ||
'Incompatible GitHub Copilot extension installed. Skipping call to `registerRelatedFilesProvider`' | ||
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 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 |
||
); | ||
return; | ||
} | ||
channel.appendLine('registerRelatedFilesProvider succeeded.'); | ||
genlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const id = { | ||
extensionId: CSharpExtensionId, | ||
languageId: 'csharp', | ||
}; | ||
|
||
relatedAPI.registerRelatedFilesProvider(id, async (uri) => { | ||
const writeOutput = (output: CopilotRelatedDocumentsReport[], builder: vscode.Uri[] | null) => { | ||
genlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (output) { | ||
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. If the output is actually nullable, it probably should be The client response type is defined as non-null in It doesn't look like the server ever returns null though - so potentially the server annotation needs to be updated? |
||
for (const report of output) { | ||
if (report._vs_file_paths) { | ||
for (const filePath of report._vs_file_paths) { | ||
channel.appendLine('found related file: ' + filePath); | ||
genlu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
builder?.push(vscode.Uri.file(filePath)); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const relatedFiles: vscode.Uri[] = []; | ||
const uriString = UriConverter.serialize(uri); | ||
const textDocument = TextDocumentIdentifier.create(uriString); | ||
const responsePromise = languageServer.sendRequestWithProgress( | ||
CopilotRelatedDocumentsRequest.type, | ||
{ | ||
_vs_textDocument: textDocument, | ||
position: { | ||
line: 0, | ||
character: 0, | ||
}, | ||
}, | ||
async (p) => { | ||
writeOutput(p, relatedFiles); | ||
} | ||
); | ||
|
||
await responsePromise.then( | ||
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. I suspect the other places using |
||
(result) => { | ||
writeOutput(result, null); | ||
return; | ||
}, | ||
(err) => { | ||
channel.appendLine(err); | ||
return; | ||
} | ||
); | ||
|
||
return { | ||
entries: relatedFiles, | ||
}; | ||
}); | ||
} |
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.
These are technically user visible strings. Consider making it more evident want this actually means in terms of feature 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.
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)
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.
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