forked from redhat-developer/vscode-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POC for avoiding waiting on vscode-microprofile
Work in progress. Instead of directly depending on vscode-microprofile, send the user a notification with a button to install the extension. The user can reject the installation. They will be free to use: * qute syntax highlight * properties file highlight * project generator but no new language features will appear, and they will be prompted to install vscode-microprofile when attempting to run commands that require it. Since vscode-quarkus doesn't wait on vscode-microprofile starting anymore, it can start the project generator without starting vscode-microprofile or even vscode-java. This allows for it to work in rootless mode. Closes redhat-developer#323 Signed-off-by: David Thompson <[email protected]>
- Loading branch information
Showing
8 changed files
with
192 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright 2021 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { extensions, window } from "vscode"; | ||
import { QuarkusContext } from "../QuarkusContext"; | ||
import { installExtension, isExtensionInstalled } from "../utils/extensionInstallationUtils"; | ||
|
||
const TOOLS_FOR_MICRO_PROFILE_EXT = 'redhat.vscode-microprofile'; | ||
|
||
const STARTUP_INSTALL_MEMO = 'mpExtInstallOnStartup.isIgnored'; | ||
|
||
/** | ||
* Prompts the user to install Tools for MicroProfile if they don't have it installed | ||
* | ||
* Allows the user to silence this prompt in the future by clicking on a button. | ||
* Warns the user that only some functionality is available if they choose not to install vscode-microprofile. | ||
* | ||
* @returns when the user has installed Tools for MicroProfile, | ||
* or the user has chosen not to install Tools for MicroProfile, | ||
* or its detected that they've silenced this popup | ||
*/ | ||
export async function installMPExtOnStartup(): Promise<void> { | ||
if (isExtensionInstalled(TOOLS_FOR_MICRO_PROFILE_EXT)) { | ||
return; | ||
} | ||
const installOnStartupIsIgnored = QuarkusContext.getExtensionContext().globalState.get(STARTUP_INSTALL_MEMO, false); | ||
if (installOnStartupIsIgnored) { | ||
return; | ||
} | ||
const YES = 'Install'; | ||
const NO = 'Don\'t install'; | ||
const NOT_AGAIN = 'Don\'t ask me again'; | ||
const result = await window.showWarningMessage('vscode-quarkus depends on Tools for MicroProfile for many of its features, ' | ||
+ 'but can provide some functionality without it. ' | ||
+ 'Install Tools for MicroProfile now? ' | ||
+ 'You will need to reload the window after the installation.', YES, NO, NOT_AGAIN); | ||
if (result === YES) { | ||
try { | ||
await installExtension(TOOLS_FOR_MICRO_PROFILE_EXT); | ||
} catch (e) { | ||
window.showErrorMessage(e); | ||
} | ||
} else if (result === NOT_AGAIN) { | ||
QuarkusContext.getExtensionContext().globalState.update(STARTUP_INSTALL_MEMO, true); | ||
limitedFunctionalityWarning(); | ||
} else { | ||
limitedFunctionalityWarning(); | ||
} | ||
} | ||
|
||
/** | ||
* Installs Tools for MicroProfile with the user's permission, in order to use a given command | ||
* | ||
* @param commandDescription description of the command that requires Tools for MicroProfile in order to be used | ||
* @returns when the user refuses to install, | ||
* or when the install succeeds, | ||
* or when the install fails | ||
*/ | ||
export async function installMPExtForCommand(commandDescription: string) { | ||
const YES = 'Install'; | ||
const NO = `Cancel ${commandDescription}`; | ||
const result = await window.showWarningMessage(`${commandDescription} requires Tools for MicroProfile. Install it now? ` | ||
+ 'You will need to reload the window after the installation.', | ||
YES, NO); | ||
if (result === YES) { | ||
try { | ||
await installExtension(TOOLS_FOR_MICRO_PROFILE_EXT); | ||
} catch (e) { | ||
window.showErrorMessage(e); | ||
} | ||
} else { | ||
window.showErrorMessage(`${commandDescription} requires Tools for MicroProfile, so it can't be run.`); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if Tools for MicroProfile is installed, and false otherwise | ||
* | ||
* @returns true if Tools for MicroProfile is installed, and false otherwise | ||
*/ | ||
export function isToolsForMicroProfileInstalled(): boolean { | ||
return isExtensionInstalled(TOOLS_FOR_MICRO_PROFILE_EXT); | ||
} | ||
|
||
/** | ||
* Returns when Tools for MicroProfile has started | ||
* | ||
* @returns when Tools for MicroProfile has started | ||
*/ | ||
export async function microProfileToolsStarted(): Promise<void> { | ||
await extensions.getExtension(TOOLS_FOR_MICRO_PROFILE_EXT).activate(); | ||
} | ||
|
||
async function limitedFunctionalityWarning(): Promise<void> { | ||
await window.showInformationMessage('vscode-quarkus will run with limited functionality'); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright 2021 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { commands, Disposable, extensions } from "vscode"; | ||
|
||
export const EXT_DOWNLOAD_TIMEOUT_ERROR = new Error('Extension installation is taking a while'); | ||
|
||
const DOWNLOAD_TIMEOUT = 60000; | ||
|
||
/** | ||
* Installs the extension with the given id | ||
* | ||
* @param extensionId the id (`"${publisher}.${name}"`) of the extension to check | ||
* @returns when the extension is installed | ||
* @throws `EXT_DOWNLOAD_TIMEOUT_ERROR` when the extension installation takes a while, | ||
* or the extension installation fails | ||
*/ | ||
export async function installExtension(extensionId: string): Promise<void> { | ||
let installListenerDisposable: Disposable; | ||
return new Promise<void>((resolve, reject) => { | ||
installListenerDisposable = extensions.onDidChange(() => { | ||
if (isExtensionInstalled(extensionId)) { | ||
resolve(); | ||
} | ||
}); | ||
commands.executeCommand("workbench.extensions.installExtension", extensionId) | ||
.then((_unused: any) => { }, reject); | ||
setTimeout(reject, DOWNLOAD_TIMEOUT, EXT_DOWNLOAD_TIMEOUT_ERROR); | ||
}).finally(() => { | ||
installListenerDisposable.dispose(); | ||
}); | ||
} | ||
|
||
/** | ||
* Returns true if the extension is installed and false otherwise | ||
* | ||
* @param extensionId the id (`"${publisher}.${name}"`) of the extension to check | ||
* @returns true if the extension is installed and false otherwise | ||
*/ | ||
export function isExtensionInstalled(extensionId: string): boolean { | ||
return !!extensions.getExtension(extensionId); | ||
} |
This file contains 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 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