Skip to content

Commit

Permalink
fix: Wait for JLS ready event (#347)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Mar 28, 2023
1 parent 168a0a9 commit d89c90f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) jdneo. All rights reserved.
// Licensed under the GNU LGPLv3 license.

import { ConfigurationChangeEvent, ExtensionContext, FileSystemWatcher, languages, Uri, workspace } from 'vscode';
import { ConfigurationChangeEvent, Extension, ExtensionContext, extensions, FileSystemWatcher, languages, Uri, workspace } from 'vscode';
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation, instrumentOperationAsVsCodeCommand } from 'vscode-extension-telemetry-wrapper';
import { checkstyleChannel } from './checkstyleChannel';
import { checkstyleConfigurationManager } from './checkstyleConfigurationManager';
Expand All @@ -25,6 +25,8 @@ export async function deactivate(): Promise<void> {
}

async function doActivate(_operationId: string, context: ExtensionContext): Promise<void> {
await waitForLsReady();

checkstyleDiagnosticManager.initialize(context);
await checkstyleConfigurationManager.initialize(context);

Expand Down Expand Up @@ -52,3 +54,17 @@ async function doActivate(_operationId: string, context: ExtensionContext): Prom
instrumentOperationAsVsCodeCommand(CheckstyleExtensionCommands.FIX_CHECKSTYLE_VIOLATIONS, async (uri: Uri, offsets: number[], sourceNames: string[]) => await fixCheckstyleViolations(uri, offsets, sourceNames)),
);
}

async function waitForLsReady(): Promise<void> {
const javaLanguageSupport: Extension<any> | undefined = extensions.getExtension('redhat.java');
if (javaLanguageSupport?.isActive) {
const extensionApi: any = javaLanguageSupport.exports;
if (!extensionApi) {
throw new Error('Failed to get the extension API from redhat.java');
}

return extensionApi.serverReady();
}

throw new Error('redhat.java is not installed or activated');
}

0 comments on commit d89c90f

Please sign in to comment.