Skip to content

Commit

Permalink
Return the API before importing the projects
Browse files Browse the repository at this point in the history
This also has the side effect that extensions that depend on vscode-java
can start up sooner.

Fixes #2900

Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Jan 27, 2023
1 parent 2cdb0ce commit 3e25759
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
18 changes: 10 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,16 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
};

apiManager.initialize(requirements, serverMode);
resolve(apiManager.getApiInstance());
// the promise is resolved
// no need to pass `resolve` into any code past this point,
// since `resolve` is a no-op from now on

if (requireSyntaxServer) {
if (process.env['SYNTAXLS_CLIENT_PORT']) {
syntaxClient.initialize(requirements, clientOptions, resolve);
syntaxClient.initialize(requirements, clientOptions);
} else {
syntaxClient.initialize(requirements, clientOptions, resolve, prepareExecutable(requirements, syntaxServerWorkspacePath, getJavaConfig(requirements.java_home), context, true));
syntaxClient.initialize(requirements, clientOptions, prepareExecutable(requirements, syntaxServerWorkspacePath, getJavaConfig(requirements.java_home), context, true));
}
syntaxClient.start();
serverStatusBarProvider.showLightWeightStatus();
Expand Down Expand Up @@ -347,7 +351,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
}

if (choice === "Yes") {
await startStandardServer(context, requirements, clientOptions, workspacePath, resolve);
await startStandardServer(context, requirements, clientOptions, workspacePath);
}
});

Expand All @@ -372,18 +376,16 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
const importOnStartup = config.get(importOnStartupSection);
if (importOnStartup === "disabled" ||
env.uiKind === UIKind.Web && env.appName.includes("Visual Studio Code")) {
syntaxClient.resolveApi(resolve);
requireStandardServer = false;
} else if (importOnStartup === "interactive" && await workspaceContainsBuildFiles()) {
syntaxClient.resolveApi(resolve);
requireStandardServer = await promptUserForStandardServer(config);
} else {
requireStandardServer = true;
}
}

if (requireStandardServer) {
await startStandardServer(context, requirements, clientOptions, workspacePath, resolve);
await startStandardServer(context, requirements, clientOptions, workspacePath);
}

const onDidGrantWorkspaceTrust = (workspace as any).onDidGrantWorkspaceTrust;
Expand Down Expand Up @@ -411,7 +413,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
});
}

async function startStandardServer(context: ExtensionContext, requirements: requirements.RequirementsData, clientOptions: LanguageClientOptions, workspacePath: string, resolve: (value?: ExtensionAPI | PromiseLike<ExtensionAPI>) => void) {
async function startStandardServer(context: ExtensionContext, requirements: requirements.RequirementsData, clientOptions: LanguageClientOptions, workspacePath: string) {
if (standardClient.getClientStatus() !== ClientStatus.uninitialized) {
return;
}
Expand All @@ -426,7 +428,7 @@ async function startStandardServer(context: ExtensionContext, requirements: requ
apiManager.getApiInstance().serverMode = ServerMode.hybrid;
apiManager.fireDidServerModeChange(ServerMode.hybrid);
}
await standardClient.initialize(context, requirements, clientOptions, workspacePath, jdtEventEmitter, resolve);
await standardClient.initialize(context, requirements, clientOptions, workspacePath, jdtEventEmitter);
standardClient.start();
serverStatusBarProvider.showStandardStatus();
}
Expand Down
6 changes: 2 additions & 4 deletions src/standardLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { apiManager } from "./apiManager";
import * as buildPath from './buildpath';
import { javaRefactorKinds, RefactorDocumentProvider } from "./codeActionProvider";
import { Commands } from "./commands";
import { ClientStatus, ExtensionAPI } from "./extension.api";
import { ClientStatus } from "./extension.api";
import * as fileEventHandler from './fileEventHandler';
import { gradleCodeActionMetadata, GradleCodeActionProvider } from "./gradle/gradleCodeActionProvider";
import { JavaInlayHintsProvider } from "./inlayHintsProvider";
Expand Down Expand Up @@ -56,7 +56,7 @@ export class StandardLanguageClient {
private languageClient: LanguageClient;
private status: ClientStatus = ClientStatus.uninitialized;

public async initialize(context: ExtensionContext, requirements: RequirementsData, clientOptions: LanguageClientOptions, workspacePath: string, jdtEventEmitter: EventEmitter<Uri>, resolve: (value: ExtensionAPI) => void): Promise<void> {
public async initialize(context: ExtensionContext, requirements: RequirementsData, clientOptions: LanguageClientOptions, workspacePath: string, jdtEventEmitter: EventEmitter<Uri>): Promise<void> {
if (this.status !== ClientStatus.uninitialized) {
return;
}
Expand Down Expand Up @@ -139,13 +139,11 @@ export class StandardLanguageClient {
serverStatus.updateServerStatus(ServerStatusKind.ready);
commands.executeCommand('setContext', 'javaLSReady', true);
apiManager.updateStatus(ClientStatus.started);
resolve(apiManager.getApiInstance());
break;
case 'Error':
this.status = ClientStatus.error;
serverStatus.updateServerStatus(ServerStatusKind.error);
apiManager.updateStatus(ClientStatus.error);
resolve(apiManager.getApiInstance());
break;
case 'ProjectStatus':
if (report.message === "WARNING") {
Expand Down
20 changes: 3 additions & 17 deletions src/syntaxLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { DidChangeConfigurationNotification, LanguageClientOptions } from "vscod
import { LanguageClient, ServerOptions, StreamInfo } from "vscode-languageclient/node";
import { apiManager } from "./apiManager";
import { ClientErrorHandler } from "./clientErrorHandler";
import { ClientStatus, ExtensionAPI } from "./extension.api";
import { ClientStatus } from "./extension.api";
import { logger } from "./log";
import { OutputInfoCollector } from "./outputInfoCollector";
import { StatusNotification } from "./protocol";
import { ServerMode } from "./settings";
import { RequirementsData } from "./requirements";
import { snippetCompletionProvider } from "./snippetCompletionProvider";
import { getJavaConfig } from "./utils";

Expand All @@ -19,7 +19,7 @@ export class SyntaxLanguageClient {
private languageClient: LanguageClient;
private status: ClientStatus = ClientStatus.uninitialized;

public initialize(requirements, clientOptions: LanguageClientOptions, resolve: (value: ExtensionAPI) => void, serverOptions?: ServerOptions) {
public initialize(requirements: RequirementsData, clientOptions: LanguageClientOptions, serverOptions?: ServerOptions) {
const newClientOptions: LanguageClientOptions = Object.assign({}, clientOptions, {
middleware: {
workspace: {
Expand Down Expand Up @@ -74,9 +74,6 @@ export class SyntaxLanguageClient {
default:
break;
}
if (apiManager.getApiInstance().serverMode === ServerMode.lightWeight) {
this.resolveApiOnReady(resolve);
}
});
});
}
Expand Down Expand Up @@ -111,15 +108,4 @@ export class SyntaxLanguageClient {
return this.languageClient;
}

public resolveApi(resolve: (value: ExtensionAPI) => void): void {
apiManager.getApiInstance().serverMode = ServerMode.lightWeight;
apiManager.fireDidServerModeChange(ServerMode.lightWeight);
this.resolveApiOnReady(resolve);
}

private resolveApiOnReady(resolve: (value: ExtensionAPI) => void): void {
if ([ClientStatus.started, ClientStatus.error].includes(this.status)) {
resolve(apiManager.getApiInstance());
}
}
}

0 comments on commit 3e25759

Please sign in to comment.