-
Notifications
You must be signed in to change notification settings - Fork 37.6k
TS extension: register call to CopilotRelated with copilot extension #228610
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
Changes from 2 commits
21b3f66
91024a3
afce6a1
3ae48ff
3d5329a
d133bfe
eac80c5
b4a1d8c
c022f8e
a5ba473
c847b76
23508ef
8da7a18
3916183
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 |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ import TypingsStatus, { AtaProgressReporter } from './ui/typingsStatus'; | |
| import { VersionStatus } from './ui/versionStatus'; | ||
| import { coalesce } from './utils/arrays'; | ||
| import { Disposable } from './utils/dispose'; | ||
| import { jsTsLanguageModes, isSupportedLanguageMode } from './configuration/languageIds'; | ||
|
|
||
| // Style check diagnostics that can be reported as warnings | ||
| const styleCheckDiagnostics = new Set([ | ||
|
|
@@ -119,7 +120,7 @@ export default class TypeScriptServiceClientHost extends Disposable { | |
| this._register(module.register(this.client, allModeIds))); | ||
|
|
||
| this.client.ensureServiceStarted(); | ||
| this.client.onReady(() => { | ||
| this.client.onReady(async () => { | ||
| const languages = new Set<string>(); | ||
| for (const plugin of services.pluginManager.plugins) { | ||
| if (plugin.configNamespace && plugin.languages.length) { | ||
|
|
@@ -150,6 +151,60 @@ export default class TypeScriptServiceClientHost extends Disposable { | |
| standardFileExtensions: [], | ||
| }, onCompletionAccepted); | ||
| } | ||
| // 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')); | ||
sandersn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
| await ext.activate(); | ||
| const relatedAPI = ext.exports as { | ||
| registerRelatedFilesProvider( | ||
| providerId: { extensionId: string; languageId: string }, | ||
| callback: (uri: vscode.Uri) => Promise<{ entries: vscode.Uri[]; traits?: { name: string; value: string }[] }> | ||
| ): void; | ||
| } | undefined; | ||
| if (relatedAPI) { | ||
|
||
| for (const languageId of jsTsLanguageModes) { | ||
| const id = { | ||
| extensionId: 'vscode.typescript-language-features', | ||
| languageId | ||
| }; | ||
| relatedAPI.registerRelatedFilesProvider(id, async uri => { | ||
sandersn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let document; | ||
| try { | ||
| document = await vscode.workspace.openTextDocument(uri); | ||
| } catch { | ||
| if (!vscode.window.activeTextEditor) { | ||
| vscode.window.showErrorMessage(vscode.l10n.t("Go to Source Definition failed. No resource provided.")); | ||
| return []; | ||
| } | ||
| // something is REALLY wrong if you can't open the active text editor's document, so don't catch that | ||
| document = await vscode.workspace.openTextDocument(vscode.window.activeTextEditor.document.uri); | ||
| } | ||
|
|
||
| if (!isSupportedLanguageMode(document)) { | ||
| vscode.window.showErrorMessage(vscode.l10n.t("Go to Source Definition failed. Unsupported file type.")); | ||
| return []; | ||
| } | ||
|
|
||
| const file = this.client.toOpenTsFilePath(document); | ||
| if (!file) { | ||
| return []; | ||
| } | ||
| // 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); | ||
sandersn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (response.type !== 'response' || !response.body) { | ||
| return []; | ||
| } | ||
| return response.body.map(vscode.Uri.file); | ||
sandersn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
| } | ||
| else { | ||
| vscode.window.showErrorMessage(vscode.l10n.t('Could not find github.copilot extension')); | ||
| } | ||
| }); | ||
|
|
||
| this.client.onTsServerStarted(() => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.