Skip to content

Commit

Permalink
Activation trigger should be more selective.
Browse files Browse the repository at this point in the history
- Fixes #497
- Only start language server(s) and contribute extension functionality
  if a Quarkus project is detected

Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
  • Loading branch information
rgrunber committed Sep 8, 2022
1 parent 5b882c7 commit 69e6afa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,26 @@ import { generateProjectWizard } from "../wizards/generateProject/generationWiza
const NOT_A_QUARKUS_PROJECT = new Error('No Quarkus projects were detected in this folder');
const STANDARD_MODE_REQUEST_FAILED = new Error('Error occurred while requesting standard mode from the Java language server');


export function registerVSCodeClientCommands(context: ExtensionContext): void {
/**
* Command for creating a Quarkus project
*/
registerCommandWithTelemetry(context, VSCodeCommands.CREATE_PROJECT, generateProjectWizard, true);

/**
* Command for displaying welcome page
*/
registerCommandWithTelemetry(context, VSCodeCommands.QUARKUS_WELCOME, async () => { WelcomeWebview.createOrShow(context); });
}

/**
* Register the vscode-quarkus commands
*
* @param context the extension context
*/
export function registerVSCodeCommands(context: ExtensionContext): void {

/**
* Command for creating a Quarkus project
*/
registerCommandWithTelemetry(context, VSCodeCommands.CREATE_PROJECT, generateProjectWizard, true);

/**
* Command for adding Quarkus extensions to current Quarkus Maven project
*/
Expand All @@ -36,11 +44,6 @@ export function registerVSCodeCommands(context: ExtensionContext): void {
registerCommandWithTelemetry(context, VSCodeCommands.DEBUG_QUARKUS_PROJECT, withStandardMode(startDebugging, "Debugging the extension"));
registerCommandWithTelemetry(context, VSCodeCommands.DEBUG_QUARKUS_PROJECT + VSCodeCommands.SHORT_SUFFIX, withStandardMode(startDebugging, "Debugging the extension"));

/**
* Command for displaying welcome page
*/
registerCommandWithTelemetry(context, VSCodeCommands.QUARKUS_WELCOME, async () => { WelcomeWebview.createOrShow(context); });

/**
* Command for deploying current Quarkus project to OpenShift with OpenShift Connector
*/
Expand Down
35 changes: 33 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
*/
import * as path from 'path';
import { commands, Disposable, ExtensionContext, extensions, Terminal, TextDocument, window, workspace } from 'vscode';
import { registerVSCodeCommands } from './commands/registerCommands';
import { QuarkusPropertiesLanguageMismatch, QuarkusConfig } from './QuarkusConfig';
import { registerVSCodeClientCommands, registerVSCodeCommands } from './commands/registerCommands';
import { QuarkusConfig, QuarkusPropertiesLanguageMismatch } from './QuarkusConfig';
import { QuarkusContext } from './QuarkusContext';
import quarkusProjectListener from './QuarkusProjectListener';
import { connectToQuteLS } from './qute/languageServer/client';
import { terminalCommandRunner } from './terminal/terminalCommandRunner';
import { tryToForceLanguageId } from './utils/languageMismatch';
import { JAVA_EXTENSION_ID } from './utils/requestStandardMode';
import { initTelemetryService } from './utils/telemetryUtils';
import { getFilePathsFromWorkspace } from './utils/workspaceUtils';
import { WelcomeWebview } from './webviews/WelcomeWebview';
import { createTerminateDebugListener } from './wizards/debugging/terminateProcess';

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

QuarkusContext.setContext(context);

registerVSCodeClientCommands(context);
// Check if activation occured due to a 'java' language document
const onLanguageJavaWasActivated = workspace.textDocuments.some(doc => doc.languageId === 'java');
if (onLanguageJavaWasActivated) {
/* Consider duplicating activationEvents above to avoid re-checking when
an activation event should be sufficient */
// Check if Java project is also a Quarkus project
const shouldActivate = await isQuarkusProject();
if (shouldActivate) {
doActivate(context);
}
} else {
doActivate(context);
}
}

async function doActivate(context: ExtensionContext) {
displayWelcomePageIfNeeded(context);
commands.executeCommand('setContext', 'quarkusProjectExistsOrLightWeight', true);

Expand Down Expand Up @@ -124,3 +143,15 @@ export async function getJavaExtensionAPI(): Promise<JavaExtensionAPI> {
const api = await vscodeJava.activate();
return Promise.resolve(api);
}
async function isQuarkusProject(): Promise<boolean> {
for (const ws of workspace.workspaceFolders) {
const buildFileUris = await getFilePathsFromWorkspace(ws, "**/{pom.xml,build.gradle}");
for (const uri of buildFileUris) {
const doc = await workspace.openTextDocument(uri);
if (doc.getText().search("io.quarkus") > 0) {
return true;
}
}
}
return false;
}

0 comments on commit 69e6afa

Please sign in to comment.