Skip to content

Commit 5c01423

Browse files
committed
Rework command and extension activation conditions
- early registration of `open output command`. Fixes #914 - activate extension when .classpath is found at the root - only activate some commands in the palette if the server is started - removed extension activation by commands needing the server to be started in the 1st place - fixed check for non-existing server log, in the `open server log` command Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 5bc3ebc commit 5c01423

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,9 @@
2727
],
2828
"activationEvents": [
2929
"onLanguage:java",
30-
"onCommand:java.show.references",
31-
"onCommand:java.show.implementations",
32-
"onCommand:java.open.output",
33-
"onCommand:java.open.serverLog",
34-
"onCommand:java.execute.workspaceCommand",
35-
"onCommand:java.projectConfiguration.update",
3630
"workspaceContains:pom.xml",
37-
"workspaceContains:build.gradle"
31+
"workspaceContains:build.gradle",
32+
"workspaceContains:.classpath"
3833
],
3934
"main": "./dist/extension",
4035
"contributes": {
@@ -439,6 +434,18 @@
439434
}
440435
],
441436
"commandPalette": [
437+
{
438+
"command": "java.projectConfiguration.update",
439+
"when": "javaLSReady"
440+
},
441+
{
442+
"command": "java.workspace.compile",
443+
"when": "javaLSReady"
444+
},
445+
{
446+
"command": "java.project.listSourcePaths",
447+
"when": "javaLSReady"
448+
},
442449
{
443450
"command": "java.project.updateSourceAttachment",
444451
"when": "false"

src/extension.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
105105
// Create the language client and start the client.
106106
languageClient = new LanguageClient('java', 'Language Support for Java', serverOptions, clientOptions);
107107
languageClient.registerProposedFeatures();
108+
108109
languageClient.onReady().then(() => {
109110
languageClient.onNotification(StatusNotification.type, (report) => {
110111
switch (report.type) {
@@ -186,9 +187,6 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
186187
return commands.executeCommand(params.command, ...params.arguments);
187188
});
188189

189-
context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => {
190-
languageClient.outputChannel.show(ViewColumn.Three);
191-
}));
192190
context.subscriptions.push(commands.registerCommand(Commands.SHOW_JAVA_REFERENCES, (uri: string, position: LSPosition, locations: LSLocation[]) => {
193191
commands.executeCommand(Commands.SHOW_REFERENCES, Uri.parse(uri), languageClient.protocol2CodeConverter.asPosition(position), locations.map(languageClient.protocol2CodeConverter.asLocation));
194192
}));
@@ -319,6 +317,9 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
319317

320318
languageClient.start();
321319
// Register commands here to make it available even when the language client fails
320+
321+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => languageClient.outputChannel.show(ViewColumn.Three)));
322+
322323
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, () => openServerLogFile(workspacePath)));
323324

324325
const extensionPath = context.extensionPath;
@@ -481,7 +482,7 @@ function deleteDirectory(dir) {
481482

482483
function openServerLogFile(workspacePath): Thenable<boolean> {
483484
const serverLogFile = path.join(workspacePath, '.metadata', '.log');
484-
if (!serverLogFile) {
485+
if (!fs.existsSync(serverLogFile)) {
485486
return window.showWarningMessage('Java Language Server has not started logging.').then(() => false);
486487
}
487488

0 commit comments

Comments
 (0)