Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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'));
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this also need to be gated on the TS server version?

Copy link
Member Author

Choose a reason for hiding this comment

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

I expect it to ship in 5.7. Gating it is a good idea. How do I do that? I saw a lot of // @ts-expect-error until ts 5.6 in the code base, accompanied by if (event.body.entries) kinds of checks. Is that the right way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, the language features are gated on API.v560 (for example). Is it OK to add API.v570?

for (const languageId of jsTsLanguageModes) {
const id = {
extensionId: 'vscode.typescript-language-features',
languageId
};
relatedAPI.registerRelatedFilesProvider(id, async uri => {
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);
if (response.type !== 'response' || !response.body) {
return [];
}
return response.body.map(vscode.Uri.file);
});
}
}
else {
vscode.window.showErrorMessage(vscode.l10n.t('Could not find github.copilot extension'));
}
});

this.client.onTsServerStarted(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ interface StandardTsServerRequests {
'getMoveToRefactoringFileSuggestions': [Proto.GetMoveToRefactoringFileSuggestionsRequestArgs, Proto.GetMoveToRefactoringFileSuggestions];
'linkedEditingRange': [Proto.FileLocationRequestArgs, Proto.LinkedEditingRangeResponse];
'mapCode': [Proto.MapCodeRequestArgs, Proto.MapCodeResponse];
'copilotRelated': [Proto.FileRequestArgs, Proto.CopilotRelatedResponse];
'getPasteEdits': [Proto.GetPasteEditsRequestArgs, Proto.GetPasteEditsResponse];
}

Expand Down