-
Notifications
You must be signed in to change notification settings - Fork 97
fix: Show the hints in Java Projects explorer properly #547
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,94 +1,114 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| import { commands, Event, Extension, extensions, Uri } from "vscode"; | ||
| import { commands, Disposable, Event, Extension, extensions, Uri } from "vscode"; | ||
| import { Commands } from "../commands"; | ||
| import { Context, ExtensionName } from "../constants"; | ||
| import { contextManager } from "../contextManager"; | ||
| import { Settings } from "../settings"; | ||
| import { syncHandler } from "../syncHandler"; | ||
| import { LanguageServerMode } from "./LanguageServerMode"; | ||
|
|
||
| class LanguageServerApiManager { | ||
| class LanguageServerApiManager implements Disposable { | ||
| /** | ||
| * undefined means a legacy version language server | ||
| * null means the JDT.LS is not activated | ||
| */ | ||
| private serverMode: LanguageServerMode | null | undefined = null; | ||
|
|
||
| public async isStandardServerReady(): Promise<boolean> { | ||
| private extensionChangeListener: Disposable; | ||
|
|
||
| public async ready(): Promise<boolean> { | ||
| await this.checkServerMode(); | ||
| // undefined serverMode indicates an older version language server | ||
| if (this.serverMode === undefined) { | ||
| return true; | ||
| } | ||
|
|
||
| if (this.serverMode !== LanguageServerMode.Standard) { | ||
| if (this.serverMode === null || this.serverMode === LanguageServerMode.LightWeight) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| public async isLightWeightMode(): Promise<boolean> { | ||
| await this.checkServerMode(); | ||
| return this.serverMode === LanguageServerMode.LightWeight; | ||
| } | ||
|
|
||
| public async awaitSwitchingServerFinished(): Promise<void> { | ||
| await this.checkServerMode(); | ||
| if (this.serverMode === LanguageServerMode.Hybrid) { | ||
| await new Promise<void>((resolve: () => void): void => { | ||
| extensions.getExtension("redhat.java")!.exports.onDidServerModeChange(resolve); | ||
|
Eskibear marked this conversation as resolved.
|
||
| }); | ||
| } | ||
| } | ||
|
|
||
| private async checkServerMode(): Promise<void> { | ||
| if (this.serverMode === null) { | ||
| await this.initializeJavaLanguageServerApi(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private async initializeJavaLanguageServerApi(): Promise<void> { | ||
| if (this.serverMode !== null) { | ||
| public async initializeJavaLanguageServerApi(forceActivate: boolean = true): Promise<void> { | ||
| if (this.isLanguageServerActivated()) { | ||
| return; | ||
| } | ||
| const extension: Extension<any> | undefined = extensions.getExtension("redhat.java"); | ||
|
|
||
| if (!this.extensionChangeListener) { | ||
| this.extensionChangeListener = extensions.onDidChange(() => { | ||
| if (this.serverMode === null) { | ||
| commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH, /* debounce = */false); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| const extension: Extension<any> | undefined = extensions.getExtension(ExtensionName.JAVA_LANGUAGE_SUPPORT); | ||
| if (extension) { | ||
| contextManager.setContextValue(Context.LANGUAGE_SUPPORT_INSTALLED, true); | ||
| if (!forceActivate) { | ||
| return; | ||
| } | ||
| await extension.activate(); | ||
| const extensionApi: any = extension.exports; | ||
| if (!extensionApi) { | ||
| return; | ||
| } | ||
|
|
||
| this.serverMode = extensionApi.serverMode; | ||
| if (this.serverMode === LanguageServerMode.Standard) { | ||
| syncHandler.updateFileWatcher(Settings.autoRefresh()); | ||
| } | ||
|
|
||
| if (extensionApi.onDidClasspathUpdate) { | ||
| const onDidClasspathUpdate: Event<Uri> = extensionApi.onDidClasspathUpdate; | ||
| contextManager.context.subscriptions.push(onDidClasspathUpdate(async () => { | ||
| await commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH, /* debounce = */true); | ||
| contextManager.context.subscriptions.push(onDidClasspathUpdate(() => { | ||
| commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH, /* debounce = */true); | ||
| syncHandler.updateFileWatcher(Settings.autoRefresh()); | ||
| })); | ||
| } | ||
|
|
||
| if (extensionApi.onDidServerModeChange) { | ||
| const onDidServerModeChange: Event<string> = extensionApi.onDidServerModeChange; | ||
| contextManager.context.subscriptions.push(onDidServerModeChange(async (mode: LanguageServerMode) => { | ||
| contextManager.context.subscriptions.push(onDidServerModeChange((mode: LanguageServerMode) => { | ||
| if (this.serverMode !== mode) { | ||
| let needRefresh: boolean = true; | ||
| if (this.serverMode === "Hybrid") { | ||
| // Explorer will await when JLS is in Hybrid mode (activating), | ||
| needRefresh = false; | ||
| } | ||
| this.serverMode = mode; | ||
| if (needRefresh) { | ||
| if (mode === LanguageServerMode.Hybrid) { | ||
| commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH, /* debounce = */false); | ||
| } else if (mode === LanguageServerMode.Standard) { | ||
| syncHandler.updateFileWatcher(Settings.autoRefresh()); | ||
| } | ||
| this.serverMode = mode; | ||
| } | ||
| })); | ||
| } | ||
|
|
||
| if (extensionApi.onDidProjectsImport) { | ||
| const onDidProjectsImport: Event<Uri[]> = extensionApi.onDidProjectsImport; | ||
| contextManager.context.subscriptions.push(onDidProjectsImport(async () => { | ||
| contextManager.context.subscriptions.push(onDidProjectsImport(() => { | ||
| commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH, /* debounce = */true); | ||
| syncHandler.updateFileWatcher(Settings.autoRefresh()); | ||
| })); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public dispose() { | ||
| this.extensionChangeListener.dispose(); | ||
| } | ||
|
|
||
| private isLanguageServerActivated(): boolean { | ||
| return this.serverMode !== null; | ||
| } | ||
|
|
||
| private async checkServerMode(): Promise<void> { | ||
| if (!this.isLanguageServerActivated()) { | ||
| await this.initializeJavaLanguageServerApi(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export const languageServerApiManager: LanguageServerApiManager = new LanguageServerApiManager(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.