diff --git a/extensions/vscode/README.md b/extensions/vscode/README.md index 46d4ea4dc7..f247686e62 100644 --- a/extensions/vscode/README.md +++ b/extensions/vscode/README.md @@ -16,25 +16,34 @@ provides support for 3. Open any FTL project with a `ftl-project.toml` or `ftl.toml` file. -4. The extension will automatically activate and provide support for FTL projects. +4. The extension will prompt to start the FTL development server. -> [!IMPORTANT] -> If you have installed FTL with hermit (or other dependency management tools), you may need to specify the path to the FTL binary in the extension settings. +## Settings -Example: +Configure the FTL extension by setting the following options in your Visual Studio Code settings.json: -```json -{ - "ftl.executablePath": "bin/ftl" -} -``` +- `ftl.executablePath`: Specifies the path to the FTL executable. The default is "ftl", which uses the system's PATH to find the executable. -You can also configure additional command line arguments for the FTL binary in the settings. + > [!IMPORTANT] + > If you have installed FTL with hermit (or other dependency management tools), you may need to specify the path to the FTL binary in the extension settings. -Example: + ```json + { + "ftl.executablePath": "bin/ftl"` + } + ``` -```json -{ - "ftl.devCommandFlags": ["--recreate", "--parallelism=4"] -} -``` +- `ftl.devCommandFlags`: Defines flags to pass to the FTL executable when starting the development environment. The default is ["--recreate"]. + + ```json + { + "ftl.devCommandFlags": ["--recreate", "--parallelism=4"] + } + ``` + +- `ftl.startClientOption`: Controls if and when to automatically start the FTL development server. Available options are "always" and "never". If not set, the extension will prompt to start the server when opening a FTL project. + ```json + { + "ftl.startClientOption": "always" + } + ``` diff --git a/extensions/vscode/images/icon.png b/extensions/vscode/images/icon.png new file mode 100644 index 0000000000..9b140a44c6 Binary files /dev/null and b/extensions/vscode/images/icon.png differ diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index c3575c34cd..2afeb54ded 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "ftl", - "version": "0.0.3", + "version": "0.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ftl", - "version": "0.0.3", + "version": "0.0.5", "dependencies": { "semver": "^7.6.0", "vscode-languageclient": "^9.0.1" diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index f55978a299..60b9588341 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -3,7 +3,8 @@ "displayName": "FTL", "publisher": "ftl", "description": "VSCode extension for FTL", - "version": "0.0.3", + "icon": "images/icon.png", + "version": "0.0.5", "repository": { "type": "git", "url": "https://github.com/TBD54566975/ftl-vscode" @@ -36,6 +37,15 @@ "type": "string" }, "description": "Flags to pass to the FTL executable when starting ftl dev" + }, + "ftl.startClientOption": { + "type": "string", + "enum": [ + "always", + "never" + ], + "default": null, + "description": "Control if and when to automatically start the FTL client." } } }, diff --git a/extensions/vscode/src/extension.ts b/extensions/vscode/src/extension.ts index ee7ea46f6c..0a2b012a73 100644 --- a/extensions/vscode/src/extension.ts +++ b/extensions/vscode/src/extension.ts @@ -61,7 +61,7 @@ export async function activate(context: ExtensionContext) { statusBarItem.command = "ftl.statusItemClicked" statusBarItem.show() - await startClient(context) + await promptStartClient(context) context.subscriptions.push( restartCmd, @@ -76,6 +76,71 @@ export async function deactivate() { await stopClient() } +async function FTLPreflightCheck(ftlPath: string) { + const ftlRunning = await isFTLRunning(ftlPath) + if (ftlRunning) { + vscode.window.showErrorMessage( + "FTL is already running. Please stop the other instance and restart the service." + ) + return false + } + + let version: string + try { + version = await getFTLVersion(ftlPath) + } catch (error: any) { + vscode.window.showErrorMessage(`${error.message}`) + return false + } + + const versionOK = checkMinimumVersion(version, MIN_FTL_VERSION) + if (!versionOK) { + vscode.window.showErrorMessage( + `FTL version ${version} is not supported. Please upgrade to at least ${MIN_FTL_VERSION}.` + ) + return false + } + + return true +} + +async function promptStartClient(context: vscode.ExtensionContext): Promise { + const configuration = vscode.workspace.getConfiguration('ftl') + const startClientOption = configuration.get('startClientOption') + + if (startClientOption === 'always') { + await startClient(context) + return + } else if (startClientOption === 'never') { + FTLStatus.disabled(statusBarItem) + return + } + + + const options = ['Always', 'Yes', 'No', 'Never'] + const result = await vscode.window.showInformationMessage( + 'FTL project detected. Would you like to start the FTL development server?', + ...options + ) + + switch (result) { + case 'Always': + configuration.update('startClientOption', 'always', vscode.ConfigurationTarget.Global) + await startClient(context) + break + case 'Yes': + await startClient(context) + break + case 'No': + FTLStatus.disabled(statusBarItem) + break + case 'Never': + configuration.update('startClientOption', 'never', vscode.ConfigurationTarget.Global) + FTLStatus.disabled(statusBarItem) + break + } +} + async function startClient(context: ExtensionContext) { console.log("Starting client") @@ -150,6 +215,7 @@ async function stopClient() { } console.log("Disposing client") + client.diagnostics?.clear() if (client["_serverProcess"]) { process.kill(client["_serverProcess"].pid, "SIGINT") } @@ -162,31 +228,3 @@ async function stopClient() { console.log("Output channel disposed") FTLStatus.stopped(statusBarItem) } - -async function FTLPreflightCheck(ftlPath: string) { - const ftlRunning = await isFTLRunning(ftlPath) - if (ftlRunning) { - vscode.window.showErrorMessage( - "FTL is already running. Please stop the other instance and restart the service." - ) - return false - } - - let version: string - try { - version = await getFTLVersion(ftlPath) - } catch (error: any) { - vscode.window.showErrorMessage(`${error.message}`) - return false - } - - const versionOK = checkMinimumVersion(version, MIN_FTL_VERSION) - if (!versionOK) { - vscode.window.showErrorMessage( - `FTL version ${version} is not supported. Please upgrade to at least ${MIN_FTL_VERSION}.` - ) - return false - } - - return true -}