Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework command and extension activation conditions #915

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,9 @@
],
"activationEvents": [
"onLanguage:java",
"onCommand:java.show.references",
"onCommand:java.show.implementations",
"onCommand:java.open.output",
"onCommand:java.open.serverLog",
"onCommand:java.execute.workspaceCommand",
"onCommand:java.projectConfiguration.update",
"workspaceContains:pom.xml",
"workspaceContains:build.gradle"
"workspaceContains:build.gradle",
"workspaceContains:.classpath"
],
"main": "./dist/extension",
"contributes": {
Expand Down Expand Up @@ -439,6 +434,18 @@
}
],
"commandPalette": [
{
"command": "java.projectConfiguration.update",
"when": "javaLSReady"
},
{
"command": "java.workspace.compile",
"when": "javaLSReady"
},
{
"command": "java.project.listSourcePaths",
"when": "javaLSReady"
},
{
"command": "java.project.updateSourceAttachment",
"when": "false"
Expand Down
9 changes: 5 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
// Create the language client and start the client.
languageClient = new LanguageClient('java', 'Language Support for Java', serverOptions, clientOptions);
languageClient.registerProposedFeatures();

languageClient.onReady().then(() => {
languageClient.onNotification(StatusNotification.type, (report) => {
switch (report.type) {
Expand Down Expand Up @@ -186,9 +187,6 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
return commands.executeCommand(params.command, ...params.arguments);
});

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

languageClient.start();
// Register commands here to make it available even when the language client fails

context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => languageClient.outputChannel.show(ViewColumn.Three)));

context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, () => openServerLogFile(workspacePath)));

const extensionPath = context.extensionPath;
Expand Down Expand Up @@ -481,7 +482,7 @@ function deleteDirectory(dir) {

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

Expand Down