Skip to content

Commit

Permalink
Add (loading...) prefix to hovers while TS Server is starting up
Browse files Browse the repository at this point in the history
Fixes #104859
  • Loading branch information
mjbvz committed Aug 18, 2020
1 parent 9fcefcd commit 650f768
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
Expand Up @@ -5,7 +5,8 @@

import * as vscode from 'vscode';
import type * as Proto from '../protocol';
import { ClientCapability, ITypeScriptServiceClient } from '../typescriptService';
import { localize } from '../tsServer/versionProvider';
import { ClientCapability, ITypeScriptServiceClient, ServerType } from '../typescriptService';
import { conditionalRegistration, requireSomeCapability } from '../utils/dependentRegistration';
import { DocumentSelector } from '../utils/documentSelector';
import { markdownDocumentation } from '../utils/previewer';
Expand Down Expand Up @@ -35,17 +36,30 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
}

return new vscode.Hover(
TypeScriptHoverProvider.getContents(response.body),
this.getContents(response.body, response._serverType),
typeConverters.Range.fromTextSpan(response.body));
}

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

if (data.displayString) {
parts.push({ language: 'typescript', value: data.displayString });
const displayParts: string[] = [];

if (source === ServerType.Syntax && this.client.capabilities.has(ClientCapability.Semantic)) {
displayParts.push(
localize({
key: 'loadingPrefix',
comment: ['Prefix displayed for hover entries while the server is still loading']
}, "(loading...)"));
}

displayParts.push(data.displayString);

parts.push({ language: 'typescript', value: displayParts.join(' ') });
}
parts.push(markdownDocumentation(data.documentation, data.tags));
return parts;
Expand Down
10 changes: 10 additions & 0 deletions extensions/typescript-language-features/src/protocol.d.ts
@@ -1,2 +1,12 @@
import * as Proto from 'typescript/lib/protocol';
export = Proto;

declare enum ServerType {
Syntax = 'syntax',
Semantic = 'semantic',
}
declare module 'typescript/lib/protocol' {
interface Response {
readonly _serverType?: ServerType;
}
}
Expand Up @@ -9,6 +9,7 @@ import * as stream from 'stream';
import type * as Proto from '../protocol';
import { NodeRequestCanceller } from '../tsServer/cancellation.electron';
import { ProcessBasedTsServer, TsServerProcess } from '../tsServer/server';
import { ServerType } from '../typescriptService';
import { nulToken } from '../utils/cancellation';
import { Logger } from '../utils/logger';
import { TelemetryReporter } from '../utils/telemetry';
Expand Down Expand Up @@ -64,7 +65,7 @@ suite('Server', () => {

test('should send requests with increasing sequence numbers', async () => {
const process = new FakeServerProcess();
const server = new ProcessBasedTsServer('semantic', process, undefined, new NodeRequestCanceller('semantic', tracer), undefined!, NoopTelemetryReporter, tracer);
const server = new ProcessBasedTsServer('semantic', ServerType.Semantic, process, undefined, new NodeRequestCanceller('semantic', tracer), undefined!, NoopTelemetryReporter, tracer);

const onWrite1 = process.onWrite();
server.executeImpl('geterr', {}, { isAsync: false, token: nulToken, expectsResult: true });
Expand Down
12 changes: 10 additions & 2 deletions extensions/typescript-language-features/src/tsServer/server.ts
Expand Up @@ -9,7 +9,7 @@ import { EventName } from '../protocol.const';
import { CallbackMap } from '../tsServer/callbackMap';
import { RequestItem, RequestQueue, RequestQueueingType } from '../tsServer/requestQueue';
import { TypeScriptServerError } from '../tsServer/serverError';
import { ServerResponse, TypeScriptRequests } from '../typescriptService';
import { ServerResponse, ServerType, TypeScriptRequests } from '../typescriptService';
import { TypeScriptServiceConfiguration } from '../utils/configuration';
import { Disposable } from '../utils/dispose';
import { TelemetryReporter } from '../utils/telemetry';
Expand Down Expand Up @@ -77,6 +77,7 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe

constructor(
private readonly _serverId: string,
private readonly _serverSource: ServerType,
private readonly _process: TsServerProcess,
private readonly _tsServerLogFile: string | undefined,
private readonly _requestCanceller: OngoingRequestCanceller,
Expand Down Expand Up @@ -130,7 +131,14 @@ export class ProcessBasedTsServer extends Disposable implements ITypeScriptServe
try {
switch (message.type) {
case 'response':
this.dispatchResponse(message as Proto.Response);
if (this._serverSource) {
this.dispatchResponse({
...(message as Proto.Response),
_serverType: this._serverSource
});
} else {
this.dispatchResponse(message as Proto.Response);
}
break;

case 'event':
Expand Down
16 changes: 15 additions & 1 deletion extensions/typescript-language-features/src/tsServer/spawner.ts
Expand Up @@ -6,7 +6,7 @@
import * as path from 'path';
import * as vscode from 'vscode';
import { OngoingRequestCancellerFactory } from '../tsServer/cancellation';
import { ClientCapabilities, ClientCapability } from '../typescriptService';
import { ClientCapabilities, ClientCapability, ServerType } from '../typescriptService';
import API from '../utils/api';
import { SeparateSyntaxServerConfiguration, TsServerLogLevel, TypeScriptServiceConfiguration } from '../utils/configuration';
import { Logger } from '../utils/logger';
Expand Down Expand Up @@ -143,6 +143,7 @@ export class TypeScriptServerSpawner {

return new ProcessBasedTsServer(
kind,
this.kindToServerType(kind),
process!,
tsServerLogFile,
canceller,
Expand All @@ -151,6 +152,19 @@ export class TypeScriptServerSpawner {
this._tracer);
}

private kindToServerType(kind: TsServerProcessKind): ServerType {
switch (kind) {
case TsServerProcessKind.Syntax:
return ServerType.Syntax;

case TsServerProcessKind.Main:
case TsServerProcessKind.Semantic:
case TsServerProcessKind.Diagnostics:
default:
return ServerType.Semantic;
}
}

private getTsServerArgs(
kind: TsServerProcessKind,
configuration: TypeScriptServiceConfiguration,
Expand Down
Expand Up @@ -13,6 +13,11 @@ import { TypeScriptServiceConfiguration } from './utils/configuration';
import { PluginManager } from './utils/plugins';
import { TelemetryReporter } from './utils/telemetry';

export enum ServerType {
Syntax = 'syntax',
Semantic = 'semantic',
}

export namespace ServerResponse {

export class Cancelled {
Expand Down

0 comments on commit 650f768

Please sign in to comment.