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

update to new registerRelatedFilesProvider API #7605

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 52 additions & 50 deletions src/lsptoolshost/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { languageServerOptions } from '../shared/options';
interface CopilotRelatedFilesProviderRegistration {
registerRelatedFilesProvider(
providerId: { extensionId: string; languageId: string },
callback: (uri: vscode.Uri) => Promise<{ entries: vscode.Uri[]; traits?: { name: string; value: string }[] }>
): void;
callback: (
uri: vscode.Uri,
cancellationToken?: vscode.CancellationToken
) => Promise<{ entries: vscode.Uri[]; traits?: { name: string; value: string }[] }>
): vscode.Disposable;
}

export async function registerCopilotExtensionAsync(
languageServer: RoslynLanguageServer,
channel: vscode.OutputChannel
) {
export function registerCopilotExtension(languageServer: RoslynLanguageServer, channel: vscode.OutputChannel) {
const isTraceLogLevel =
languageServerOptions.logLevel &&
(languageServerOptions.logLevel === 'Trace' || languageServerOptions.logLevel === 'Debug');
Expand All @@ -35,58 +35,60 @@ export async function registerCopilotExtensionAsync(
}
return;
}
await ext.activate();
const relatedAPI = ext.exports as CopilotRelatedFilesProviderRegistration | undefined;
if (!relatedAPI) {
if (isTraceLogLevel) {
channel.appendLine(
'Incompatible GitHub Copilot extension installed. Skip registeration of C# related files provider.'
);
ext.activate().then(() => {
const relatedAPI = ext.exports as CopilotRelatedFilesProviderRegistration | undefined;
if (!relatedAPI) {
genlu marked this conversation as resolved.
Show resolved Hide resolved
if (isTraceLogLevel) {
channel.appendLine(
'Incompatible GitHub Copilot extension installed. Skip registeration of C# related files provider.'
);
}
return;
}
return;
}

if (isTraceLogLevel) {
channel.appendLine('registeration of C# related files provider for GitHub Copilot extension succeeded.');
}
if (isTraceLogLevel) {
channel.appendLine('registration of C# related files provider for GitHub Copilot extension succeeded.');
}

const id = {
extensionId: CSharpExtensionId,
languageId: 'csharp',
};
const id = {
extensionId: CSharpExtensionId,
languageId: 'csharp',
};

relatedAPI.registerRelatedFilesProvider(id, async (uri) => {
const buildResult = (reports: CopilotRelatedDocumentsReport[], builder?: vscode.Uri[]) => {
if (reports) {
for (const report of reports) {
if (report._vs_file_paths) {
for (const filePath of report._vs_file_paths) {
builder?.push(vscode.Uri.file(filePath));
relatedAPI.registerRelatedFilesProvider(id, async (uri, token) => {
const buildResult = (reports: CopilotRelatedDocumentsReport[], builder?: vscode.Uri[]) => {
if (reports) {
for (const report of reports) {
if (report._vs_file_paths) {
for (const filePath of report._vs_file_paths) {
builder?.push(vscode.Uri.file(filePath));
}
}
}
}
}
};
const relatedFiles: vscode.Uri[] = [];
const uriString = UriConverter.serialize(uri);
const textDocument = TextDocumentIdentifier.create(uriString);
try {
await languageServer.sendRequestWithProgress(
CopilotRelatedDocumentsRequest.type,
{
_vs_textDocument: textDocument,
position: {
line: 0,
character: 0,
};
const relatedFiles: vscode.Uri[] = [];
const uriString = UriConverter.serialize(uri);
const textDocument = TextDocumentIdentifier.create(uriString);
try {
await languageServer.sendRequestWithProgress(
CopilotRelatedDocumentsRequest.type,
{
_vs_textDocument: textDocument,
position: {
line: 0,
character: 0,
},
},
},
async (r) => buildResult(r, relatedFiles)
);
} catch (e) {
if (e instanceof Error) {
channel.appendLine(e.message);
async (r) => buildResult(r, relatedFiles),
token
);
} catch (e) {
if (e instanceof Error) {
channel.appendLine(e.message);
}
}
}
return { entries: relatedFiles };
return { entries: relatedFiles };
});
});
}
4 changes: 2 additions & 2 deletions src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { registerLanguageStatusItems } from './languageStatusBar';
import { ProjectContextService } from './services/projectContextService';
import { ProvideDynamicFileResponse } from '../razor/src/dynamicFile/provideDynamicFileResponse';
import { ProvideDynamicFileParams } from '../razor/src/dynamicFile/provideDynamicFileParams';
import { registerCopilotExtensionAsync } from './copilot';
import { registerCopilotExtension } from './copilot';
import {
ActionOption,
CommandOption,
Expand Down Expand Up @@ -1052,7 +1052,7 @@ export async function activateRoslynLanguageServer(
);

registerLanguageStatusItems(context, languageServer, languageServerEvents);
await registerCopilotExtensionAsync(languageServer, _channel);
registerCopilotExtension(languageServer, _channel);

// Register any commands that need to be handled by the extension.
registerCommands(context, languageServer, hostExecutableResolver, _channel);
Expand Down
Loading