Skip to content

Commit

Permalink
feat: start server workspace setting. (#1917)
Browse files Browse the repository at this point in the history
Fixes #1853

* Clean visx files before build.
* Type safe string consts.
  • Loading branch information
gak authored Jul 1, 2024
1 parent 3955cfa commit 8137fd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('automaticallyStartServer')
const automaticallyStartServer = configuration.get<AutoStartOption | undefined>(AUTOMATICALLY_START_SERVER_VAR)

FTLStatus.ftlStopped(statusBarItem)

Expand All @@ -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':
Expand All @@ -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
}
Expand Down

0 comments on commit 8137fd7

Please sign in to comment.