From 8137fd7fc7df196275af2790833fdf51cca98a61 Mon Sep 17 00:00:00 2001 From: gak Date: Tue, 2 Jul 2024 07:57:23 +1000 Subject: [PATCH] feat: start server workspace setting. (#1917) Fixes #1853 * Clean visx files before build. * Type safe string consts. --- Justfile | 3 +-- extensions/vscode/src/extension.ts | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Justfile b/Justfile index 70ae697691..a21d8e5530 100644 --- a/Justfile +++ b/Justfile @@ -78,11 +78,10 @@ build-frontend: npm-install # Rebuild VSCode extension build-extension: npm-install - @mk {{EXTENSION_OUT}} : extensions/vscode/src -- "cd extensions/vscode && npm run compile" + @mk {{EXTENSION_OUT}} : extensions/vscode/src -- "cd extensions/vscode && rm -f ftl-*.vsix && npm run compile" # Install development version of VSCode extension install-extension: build-extension - @mk {{EXTENSION_OUT}} : extensions/vscode/src -- "cd extensions/vscode && npm run compile" @cd extensions/vscode && vsce package && code --install-extension ftl-*.vsix # Build and package the VSCode extension diff --git a/extensions/vscode/src/extension.ts b/extensions/vscode/src/extension.ts index 502c9d6042..9e8088f6c7 100644 --- a/extensions/vscode/src/extension.ts +++ b/extensions/vscode/src/extension.ts @@ -99,10 +99,15 @@ const FTLPreflightCheck = async (ftlPath: string) => { return true } +const AUTOMATICALLY_START_SERVER_VAR = 'automaticallyStartServer' as const +const PROMPT_OPTIONS = ['Always', 'Yes', 'No', 'Never'] as const +type PromptOption = typeof PROMPT_OPTIONS[number] +type AutoStartOption = 'always' | 'never' | 'prompt' + const promptStartClient = async (context: vscode.ExtensionContext) => { const configuration = vscode.workspace.getConfiguration('ftl') outputChannel.appendLine(`FTL configuration: ${JSON.stringify(configuration)}`) - const automaticallyStartServer = configuration.get('automaticallyStartServer') + const automaticallyStartServer = configuration.get(AUTOMATICALLY_START_SERVER_VAR) FTLStatus.ftlStopped(statusBarItem) @@ -111,18 +116,17 @@ const promptStartClient = async (context: vscode.ExtensionContext) => { await startClient(context) return } else if (automaticallyStartServer === 'never') { - outputChannel.appendLine(`FTL development server not started ('automaticallyStartServer' set to 'never' in settings.json)`) + outputChannel.appendLine(`FTL development server not started ('${AUTOMATICALLY_START_SERVER_VAR}' set to 'never' in workspace settings.json)`) return } - const options = ['Always', 'Yes', 'No', 'Never'] vscode.window.showInformationMessage( - 'FTL project detected. Would you like to start the FTL development server?', - ...options - ).then(async (result) => { + 'FTL project detected. Would you like to start the FTL development server for this workspace?', + ...PROMPT_OPTIONS + ).then(async (result: PromptOption | undefined) => { switch (result) { case 'Always': - configuration.update('automaticallyStartServer', 'always', vscode.ConfigurationTarget.Global) + configuration.update(AUTOMATICALLY_START_SERVER_VAR, 'always', vscode.ConfigurationTarget.Workspace) await startClient(context) break case 'Yes': @@ -134,7 +138,7 @@ const promptStartClient = async (context: vscode.ExtensionContext) => { break case 'Never': outputChannel.appendLine('FTL development server set to never auto start') - configuration.update('automaticallyStartServer', 'never', vscode.ConfigurationTarget.Global) + configuration.update(AUTOMATICALLY_START_SERVER_VAR, 'never', vscode.ConfigurationTarget.Workspace) FTLStatus.ftlStopped(statusBarItem) break }