Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dweizhe committed Sep 5, 2022
1 parent d17726f commit 72cab0e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { URI } from 'vscode-uri';
import { Command, CommandManager } from '../commands/commandManager';
import type * as Proto from '../protocol';
import * as PConst from '../protocol.const';
Expand Down Expand Up @@ -192,19 +193,33 @@ class MyCompletionItem extends vscode.CompletionItem {
} : this.tsEntry.name
]
};
const response = await client.interruptGetErr(() => client.execute('completionEntryDetails', args, requestToken.token));
if (response.type !== 'response' || !response.body || !response.body.length) {
const { completionEntryDetails, definition } = await client.interruptGetErr(async () => {
const completionEntryDetails = client.execute('completionEntryDetails', args, requestToken.token);
const definition = client.execute('definition', args, requestToken.token);
return {
completionEntryDetails: await completionEntryDetails,
definition: await definition
};
});

if (completionEntryDetails.type !== 'response' || !completionEntryDetails.body || !completionEntryDetails.body.length) {
return undefined;
}

const detail = response.body[0];
const detail = completionEntryDetails.body[0];

const newItemDetails = this.getDetails(client, detail);
if (newItemDetails) {
this.detail = newItemDetails;
}

this.documentation = this.getDocumentation(client, detail, this.document.uri);
let baseUri = this.document.uri;
if (definition.type === 'response' && definition.body && definition.body.length) {
const firstDefinitionFile = definition.body?.[0].file;
baseUri = URI.revive(vscode.Uri.file(firstDefinitionFile));
}

this.documentation = this.getDocumentation(client, detail, baseUri);

const codeAction = this.getCodeActions(detail, filepath);
const commands: vscode.Command[] = [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
import { URI } from 'vscode-uri';
import type * as Proto from '../protocol';
import { ClientCapability, ITypeScriptServiceClient, ServerType } from '../typescriptService';
import { conditionalRegistration, requireSomeCapability } from '../utils/dependentRegistration';
Expand Down Expand Up @@ -33,26 +34,34 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
return undefined;
}

const response = await this.client.interruptGetErr(async () => {
const { quickinfo, definition } = await this.client.interruptGetErr(async () => {
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);

const args = typeConverters.Position.toFileLocationRequestArgs(filepath, position);
return this.client.execute('quickinfo', args, token);
const quickinfo = await this.client.execute('quickinfo', args, token);
const definition = await this.client.execute('definition', args, token);
return { quickinfo, definition };
});

if (response.type !== 'response' || !response.body) {
if (quickinfo.type !== 'response' || !quickinfo.body) {
return undefined;
}

let resource = document.uri;
if (definition.type === 'response' && definition.body) {
const firstDefinitionFile = definition.body?.[0].file;
resource = URI.revive(vscode.Uri.file(firstDefinitionFile));
}

return new vscode.Hover(
this.getContents(document.uri, response.body, response._serverType),
typeConverters.Range.fromTextSpan(response.body));
this.getContents(resource, quickinfo.body, quickinfo._serverType),
typeConverters.Range.fromTextSpan(quickinfo.body));
}

private getContents(
resource: vscode.Uri,
data: Proto.QuickInfoResponseBody,
source: ServerType | undefined,
source: ServerType | undefined
) {
const parts: vscode.MarkdownString[] = [];

Expand Down

0 comments on commit 72cab0e

Please sign in to comment.