Skip to content
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

fix: add startup prompt to extension #1301

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions extensions/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the trailing `

}
```

```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"
}
```
Binary file added extensions/vscode/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions extensions/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."
}
}
},
Expand Down
96 changes: 67 additions & 29 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<void> {
const configuration = vscode.workspace.getConfiguration('ftl')
const startClientOption = configuration.get<string>('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")

Expand Down Expand Up @@ -150,6 +215,7 @@ async function stopClient() {
}
console.log("Disposing client")

client.diagnostics?.clear()
if (client["_serverProcess"]) {
process.kill(client["_serverProcess"].pid, "SIGINT")
}
Expand All @@ -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
}