Skip to content

Commit

Permalink
fix: improve extension logging and path detection (#1665)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman authored Jun 5, 2024
1 parent 71fde02 commit 6fa96d7
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 44 deletions.
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions extensions/vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Configure the FTL extension by setting the following options in your Visual Stud
}
```

- `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.
- `ftl.automaticallyStartServer`: 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"
"ftl.automaticallyStartServer": "always"
}
```
6 changes: 3 additions & 3 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publisher": "ftl",
"description": "VSCode extension for FTL",
"icon": "images/icon.png",
"version": "0.0.5",
"version": "0.0.6",
"repository": {
"type": "git",
"url": "https://github.com/TBD54566975/ftl-vscode"
Expand Down Expand Up @@ -37,14 +37,14 @@
},
"description": "Flags to pass to the FTL executable when starting ftl dev"
},
"ftl.startClientOption": {
"ftl.automaticallyStartServer": {
"type": "string",
"enum": [
"always",
"never"
],
"default": null,
"description": "Control if and when to automatically start the FTL client."
"description": "Control if and when to automatically start the FTL dev server."
}
}
},
Expand Down
9 changes: 0 additions & 9 deletions extensions/vscode/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ export const getProjectOrWorkspaceRoot = async (): Promise<string> => {
return ""
}

// Check each folder for the 'ftl-project.toml' file
for (const folder of workspaceFolders) {
const workspaceRootPath = folder.uri.fsPath
const ftlProjectPath = await findFileInWorkspace(workspaceRootPath, 'ftl-project.toml')
if (ftlProjectPath) {
return ftlProjectPath.replace('ftl-project.toml', '')
}
}

return workspaceFolders[0].uri.fsPath
}

Expand Down
40 changes: 22 additions & 18 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let statusBarItem: vscode.StatusBarItem
let outputChannel: vscode.OutputChannel

export async function activate(context: ExtensionContext) {
console.log('"ftl" extension activated')
outputChannel = vscode.window.createOutputChannel("FTL", 'log')
outputChannel.appendLine("FTL extension activated")

let restartCmd = vscode.commands.registerCommand(
`${clientId}.restart`,
Expand Down Expand Up @@ -106,14 +107,17 @@ async function FTLPreflightCheck(ftlPath: string) {

async function promptStartClient(context: vscode.ExtensionContext) {
const configuration = vscode.workspace.getConfiguration('ftl')
const startClientOption = configuration.get<string>('startClientOption')
outputChannel.appendLine(`FTL configuration: ${JSON.stringify(configuration)}`)
const automaticallyStartServer = configuration.get<string>('automaticallyStartServer')

FTLStatus.disabled(statusBarItem)
FTLStatus.stopped(statusBarItem)

if (startClientOption === 'always') {
if (automaticallyStartServer === 'always') {
outputChannel.appendLine(`FTL development server automatically started`)
await startClient(context)
return
} else if (startClientOption === 'never') {
} else if (automaticallyStartServer === 'never') {
outputChannel.appendLine(`FTL development server not started ('automaticallyStartServer' set to 'never' in settings.json)`)
return
}

Expand All @@ -124,54 +128,55 @@ async function promptStartClient(context: vscode.ExtensionContext) {
).then(async (result) => {
switch (result) {
case 'Always':
configuration.update('startClientOption', 'always', vscode.ConfigurationTarget.Global)
configuration.update('automaticallyStartServer', 'always', vscode.ConfigurationTarget.Global)
await startClient(context)
break
case 'Yes':
await startClient(context)
break
case 'No':
FTLStatus.disabled(statusBarItem)
outputChannel.appendLine('FTL development server disabled')
FTLStatus.stopped(statusBarItem)
break
case 'Never':
configuration.update('startClientOption', 'never', vscode.ConfigurationTarget.Global)
FTLStatus.disabled(statusBarItem)
outputChannel.appendLine('FTL development server set to never auto start')
configuration.update('automaticallyStartServer', 'never', vscode.ConfigurationTarget.Global)
FTLStatus.stopped(statusBarItem)
break
}
})
}

async function startClient(context: ExtensionContext) {
console.log("Starting client")
outputChannel.appendLine("Starting lsp client")
FTLStatus.starting(statusBarItem)

const ftlConfig = vscode.workspace.getConfiguration("ftl")

const workspaceRootPath = await getProjectOrWorkspaceRoot()
const resolvedFtlPath = resolveFtlPath(workspaceRootPath, ftlConfig)

console.log('ftl path', resolvedFtlPath)
outputChannel.appendLine(`VSCode workspace root path: ${workspaceRootPath}`)
outputChannel.appendLine(`FTL path: ${resolvedFtlPath}`)

const ftlOK = await FTLPreflightCheck(resolvedFtlPath)
if (!ftlOK) {
FTLStatus.disabled(statusBarItem)
FTLStatus.stopped(statusBarItem)
return
}

outputChannel = vscode.window.createOutputChannel("FTL", 'log')

const userFlags = ftlConfig.get<string[]>("devCommandFlags") ?? []

const flags = ["--lsp", ...userFlags]
const flags = [...userFlags, "--lsp"]
let serverOptions: ServerOptions = {
run: {
command: `${resolvedFtlPath}`,
args: ["dev", ".", ...flags],
args: ["dev", ...flags],
options: { cwd: workspaceRootPath }
},
debug: {
command: `${resolvedFtlPath}`,
args: ["dev", ".", ...flags],
args: ["dev", ...flags],
options: { cwd: workspaceRootPath }
},
}
Expand All @@ -194,7 +199,6 @@ async function startClient(context: ExtensionContext) {
clientOptions
)

console.log("Starting client")
context.subscriptions.push(client)

client.start().then(
Expand Down
6 changes: 0 additions & 6 deletions extensions/vscode/src/status.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import * as vscode from "vscode"

export namespace FTLStatus {
export const disabled = (statusBarItem: vscode.StatusBarItem) => {
statusBarItem.text = `$(circle-slash) FTL`
statusBarItem.tooltip =
"FTL is disabled because it requires an 'ftl-project.toml' or 'ftl.toml' file in the workspace."
}

export const starting = (statusBarItem: vscode.StatusBarItem) => {
statusBarItem.text = `$(sync~spin) FTL`
statusBarItem.tooltip = "FTL is starting..."
Expand Down
3 changes: 0 additions & 3 deletions ftl-project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@ ftl-min-version = ""
[modules.echo.configuration]
default = "inline://ImFub255bW91cyI"

[executables]
ftl = ""

[commands]
startup = ["echo 'FTL startup command ⚡️'"]

0 comments on commit 6fa96d7

Please sign in to comment.