Skip to content

Commit

Permalink
Merge pull request #7605 from genlu/fixInterface
Browse files Browse the repository at this point in the history
update to new registerRelatedFilesProvider API
  • Loading branch information
genlu authored Sep 26, 2024
2 parents 771d166 + dd4e612 commit 14f6abd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 52 deletions.
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) {
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

0 comments on commit 14f6abd

Please sign in to comment.