Skip to content

Commit 69e6afa

Browse files
committed
Activation trigger should be more selective.
- Fixes #497 - Only start language server(s) and contribute extension functionality if a Quarkus project is detected Signed-off-by: Roland Grunberg <[email protected]>
1 parent 5b882c7 commit 69e6afa

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/commands/registerCommands.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ import { generateProjectWizard } from "../wizards/generateProject/generationWiza
1313
const NOT_A_QUARKUS_PROJECT = new Error('No Quarkus projects were detected in this folder');
1414
const STANDARD_MODE_REQUEST_FAILED = new Error('Error occurred while requesting standard mode from the Java language server');
1515

16+
17+
export function registerVSCodeClientCommands(context: ExtensionContext): void {
18+
/**
19+
* Command for creating a Quarkus project
20+
*/
21+
registerCommandWithTelemetry(context, VSCodeCommands.CREATE_PROJECT, generateProjectWizard, true);
22+
23+
/**
24+
* Command for displaying welcome page
25+
*/
26+
registerCommandWithTelemetry(context, VSCodeCommands.QUARKUS_WELCOME, async () => { WelcomeWebview.createOrShow(context); });
27+
}
28+
1629
/**
1730
* Register the vscode-quarkus commands
1831
*
1932
* @param context the extension context
2033
*/
2134
export function registerVSCodeCommands(context: ExtensionContext): void {
2235

23-
/**
24-
* Command for creating a Quarkus project
25-
*/
26-
registerCommandWithTelemetry(context, VSCodeCommands.CREATE_PROJECT, generateProjectWizard, true);
27-
2836
/**
2937
* Command for adding Quarkus extensions to current Quarkus Maven project
3038
*/
@@ -36,11 +44,6 @@ export function registerVSCodeCommands(context: ExtensionContext): void {
3644
registerCommandWithTelemetry(context, VSCodeCommands.DEBUG_QUARKUS_PROJECT, withStandardMode(startDebugging, "Debugging the extension"));
3745
registerCommandWithTelemetry(context, VSCodeCommands.DEBUG_QUARKUS_PROJECT + VSCodeCommands.SHORT_SUFFIX, withStandardMode(startDebugging, "Debugging the extension"));
3846

39-
/**
40-
* Command for displaying welcome page
41-
*/
42-
registerCommandWithTelemetry(context, VSCodeCommands.QUARKUS_WELCOME, async () => { WelcomeWebview.createOrShow(context); });
43-
4447
/**
4548
* Command for deploying current Quarkus project to OpenShift with OpenShift Connector
4649
*/

src/extension.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
*/
1616
import * as path from 'path';
1717
import { commands, Disposable, ExtensionContext, extensions, Terminal, TextDocument, window, workspace } from 'vscode';
18-
import { registerVSCodeCommands } from './commands/registerCommands';
19-
import { QuarkusPropertiesLanguageMismatch, QuarkusConfig } from './QuarkusConfig';
18+
import { registerVSCodeClientCommands, registerVSCodeCommands } from './commands/registerCommands';
19+
import { QuarkusConfig, QuarkusPropertiesLanguageMismatch } from './QuarkusConfig';
2020
import { QuarkusContext } from './QuarkusContext';
2121
import quarkusProjectListener from './QuarkusProjectListener';
2222
import { connectToQuteLS } from './qute/languageServer/client';
2323
import { terminalCommandRunner } from './terminal/terminalCommandRunner';
2424
import { tryToForceLanguageId } from './utils/languageMismatch';
2525
import { JAVA_EXTENSION_ID } from './utils/requestStandardMode';
2626
import { initTelemetryService } from './utils/telemetryUtils';
27+
import { getFilePathsFromWorkspace } from './utils/workspaceUtils';
2728
import { WelcomeWebview } from './webviews/WelcomeWebview';
2829
import { createTerminateDebugListener } from './wizards/debugging/terminateProcess';
2930

@@ -35,6 +36,24 @@ export async function activate(context: ExtensionContext) {
3536
await initTelemetryService(context);
3637

3738
QuarkusContext.setContext(context);
39+
40+
registerVSCodeClientCommands(context);
41+
// Check if activation occured due to a 'java' language document
42+
const onLanguageJavaWasActivated = workspace.textDocuments.some(doc => doc.languageId === 'java');
43+
if (onLanguageJavaWasActivated) {
44+
/* Consider duplicating activationEvents above to avoid re-checking when
45+
an activation event should be sufficient */
46+
// Check if Java project is also a Quarkus project
47+
const shouldActivate = await isQuarkusProject();
48+
if (shouldActivate) {
49+
doActivate(context);
50+
}
51+
} else {
52+
doActivate(context);
53+
}
54+
}
55+
56+
async function doActivate(context: ExtensionContext) {
3857
displayWelcomePageIfNeeded(context);
3958
commands.executeCommand('setContext', 'quarkusProjectExistsOrLightWeight', true);
4059

@@ -124,3 +143,15 @@ export async function getJavaExtensionAPI(): Promise<JavaExtensionAPI> {
124143
const api = await vscodeJava.activate();
125144
return Promise.resolve(api);
126145
}
146+
async function isQuarkusProject(): Promise<boolean> {
147+
for (const ws of workspace.workspaceFolders) {
148+
const buildFileUris = await getFilePathsFromWorkspace(ws, "**/{pom.xml,build.gradle}");
149+
for (const uri of buildFileUris) {
150+
const doc = await workspace.openTextDocument(uri);
151+
if (doc.getText().search("io.quarkus") > 0) {
152+
return true;
153+
}
154+
}
155+
}
156+
return false;
157+
}

0 commit comments

Comments
 (0)