Skip to content

Commit

Permalink
chore(lint): add biomejs to vscode extension (#2475)
Browse files Browse the repository at this point in the history
wesbillman authored Aug 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 02b5eeb commit 549b493
Showing 9 changed files with 271 additions and 1,165 deletions.
64 changes: 0 additions & 64 deletions extensions/vscode/.eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion extensions/vscode/.vscodeignore
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ src/**
webpack.config.js
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/*.map
**/*.ts
**/.vscode-test.*
45 changes: 45 additions & 0 deletions extensions/vscode/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
"organizeImports": {
"enabled": true,
"ignore": ["./node_modules", "./dist"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"a11y": {
"useKeyWithClickEvents": "off"
},
"correctness": {
"useExhaustiveDependencies": "off"
},
"suspicious": {
"noArrayIndexKey": "off"
}
},
"include": ["src/**/*.ts"],
"ignore": ["./node_modules", "./dist"]
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 160,
"include": ["src/**/*.ts"],
"ignore": ["./node_modules", "./dist"]
},
"javascript": {
"formatter": {
"semicolons": "asNeeded",
"indentStyle": "space",
"quoteStyle": "single",
"jsxQuoteStyle": "single"
}
},
"json": {
"formatter": {
"indentStyle": "space",
"indentWidth": 2
}
}
}
1,143 changes: 149 additions & 994 deletions extensions/vscode/package-lock.json

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions extensions/vscode/package.json
Original file line number Diff line number Diff line change
@@ -80,22 +80,21 @@
"compile-tests": "tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"lint": "biome check .",
"lint:fix": "biome format . --write",
"test": "vscode-test"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@types/mocha": "^10.0.6",
"@types/node": "20.x",
"@types/semver": "^7.5.8",
"@types/vscode": "^1.87.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@vscode/test-cli": "^0.0.10",
"@vscode/test-electron": "^2.3.9",
"eslint": "^8.57.0",
"@vscode/vsce": "^3.0.0",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"@vscode/vsce": "^3.0.0",
"webpack": "^5.90.3",
"webpack-cli": "^5.1.4"
},
45 changes: 18 additions & 27 deletions extensions/vscode/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as vscode from 'vscode'
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
State,
} from 'vscode-languageclient/node'
import type * as vscode from 'vscode'
import { LanguageClient, type LanguageClientOptions, type ServerOptions, State } from 'vscode-languageclient/node'
import { FTLStatus } from './status'

export class FTLClient {
@@ -35,12 +30,12 @@ export class FTLClient {
run: {
command: `${ftlPath}`,
args: ['dev', ...flags],
options: { cwd: cwd }
options: { cwd: cwd },
},
debug: {
command: `${ftlPath}`,
args: ['dev', ...flags],
options: { cwd: cwd }
options: { cwd: cwd },
},
}

@@ -52,14 +47,9 @@ export class FTLClient {
outputChannel: this.outputChannel,
}

this.client = new LanguageClient(
this.clientId,
this.clientName,
serverOptions,
clientOptions
)
this.client = new LanguageClient(this.clientId, this.clientName, serverOptions, clientOptions)

const options = (this.client.isInDebugMode) ? serverOptions.debug : serverOptions.run
const options = this.client.isInDebugMode ? serverOptions.debug : serverOptions.run
this.outputChannel.appendLine(`Running ${ftlPath} ${options.args?.join(' ')}`)
console.log(options)

@@ -69,11 +59,11 @@ export class FTLClient {
console.log('Build status', message)
const state = message.state

if (state == 'building') {
if (state === 'building') {
FTLStatus.buildRunning(this.statusBarItem)
} else if (state == 'success') {
} else if (state === 'success') {
FTLStatus.buildOK(this.statusBarItem)
} else if (state == 'failure') {
} else if (state === 'failure') {
FTLStatus.buildError(this.statusBarItem, message.error)
} else {
FTLStatus.ftlError(this.statusBarItem, 'Unknown build status from FTL LSP server')
@@ -131,24 +121,25 @@ export class FTLClient {

const timeout = 10000 // 10 seconds
if (this.isClientStarting) {
this.outputChannel.appendLine(`Waiting for client to complete startup before stopping`)
this.outputChannel.appendLine('Waiting for client to complete startup before stopping')
const startWaitTime = Date.now()
while (this.isClientStarting) {
await new Promise(resolve => setTimeout(resolve, 100))
await new Promise((resolve) => setTimeout(resolve, 100))
if (Date.now() - startWaitTime > timeout) {
this.outputChannel.appendLine(`Timeout waiting for client to start`)
this.outputChannel.appendLine('Timeout waiting for client to start')
break
}
}
}

console.log('Stopping client')
const serverProcess = this.client!['_serverProcess']
// biome-ignore lint/complexity/useLiteralKeys: we need this :)
const serverProcess = this.client?.['_serverProcess']
this.isExpectingStop = true

try {
await this.client!.stop()
await this.client!.dispose()
await this.client?.stop()
await this.client?.dispose()
this.client = undefined
console.log('Client stopped')
} catch (error) {
@@ -160,7 +151,7 @@ export class FTLClient {
try {
process.kill(serverProcess.pid, 'SIGTERM')
// Wait a bit to see if the process terminates
await new Promise(resolve => setTimeout(resolve, 1000))
await new Promise((resolve) => setTimeout(resolve, 1000))

if (!serverProcess.killed) {
console.log('Server process did not terminate with SIGTERM, trying SIGKILL')
@@ -177,7 +168,7 @@ export class FTLClient {
console.log('Failed to kill server process', killError)
}
}
} else if (serverProcess && serverProcess.killed) {
} else if (serverProcess?.killed) {
console.log('Server process was already killed')
}
}
10 changes: 5 additions & 5 deletions extensions/vscode/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as vscode from 'vscode'
import * as path from 'path'
import { exec } from 'child_process'
import { promisify } from 'util'
import semver from 'semver'
import { exec } from 'node:child_process'
import * as path from 'node:path'
import { promisify } from 'node:util'
import { lookpath } from 'lookpath'
import semver from 'semver'
import * as vscode from 'vscode'

export const MIN_FTL_VERSION = '0.169.0'

107 changes: 44 additions & 63 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ExtensionContext } from 'vscode'
import type { ExtensionContext } from 'vscode'

import * as vscode from 'vscode'
import { FTLStatus } from './status'
import { MIN_FTL_VERSION, checkMinimumVersion, getFTLVersion, getProjectOrWorkspaceRoot, isFTLRunning, resolveFtlPath } from './config'
import { FTLClient } from './client'
import { MIN_FTL_VERSION, checkMinimumVersion, getFTLVersion, getProjectOrWorkspaceRoot, isFTLRunning, resolveFtlPath } from './config'
import { FTLStatus } from './status'

const extensionId = 'ftl'
let client: FTLClient
@@ -14,30 +14,21 @@ export const activate = async (context: ExtensionContext) => {
outputChannel = vscode.window.createOutputChannel('FTL', 'log')
outputChannel.appendLine('FTL extension activated')

statusBarItem = vscode.window.createStatusBarItem(
vscode.StatusBarAlignment.Right,
100
)
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100)
statusBarItem.command = 'ftl.statusItemClicked'
statusBarItem.show()

client = new FTLClient(statusBarItem, outputChannel)

const restartCmd = vscode.commands.registerCommand(
`${extensionId}.restart`,
async () => {
console.log('Restarting FTL client')
await client.stop()
console.log('FTL client stopped')
await startClient(context)
console.log('FTL client started')
}
)

const stopCmd = vscode.commands.registerCommand(
`${extensionId}.stop`,
async () => client.stop()
)
const restartCmd = vscode.commands.registerCommand(`${extensionId}.restart`, async () => {
console.log('Restarting FTL client')
await client.stop()
console.log('FTL client stopped')
await startClient(context)
console.log('FTL client started')
})

const stopCmd = vscode.commands.registerCommand(`${extensionId}.stop`, async () => client.stop())

const showLogsCommand = vscode.commands.registerCommand('ftl.showLogs', () => {
outputChannel.show()
@@ -50,7 +41,7 @@ export const activate = async (context: ExtensionContext) => {
{ label: 'FTL: Show Logs', command: 'ftl.showLogs' },
]

vscode.window.showQuickPick(ftlCommands, { placeHolder: 'Select an FTL command' }).then(selected => {
vscode.window.showQuickPick(ftlCommands, { placeHolder: 'Select an FTL command' }).then((selected) => {
if (selected) {
vscode.commands.executeCommand(selected.command)
}
@@ -59,40 +50,30 @@ export const activate = async (context: ExtensionContext) => {

promptStartClient(context)

context.subscriptions.push(
restartCmd,
stopCmd,
statusBarItem,
showCommands,
showLogsCommand
)
context.subscriptions.push(restartCmd, stopCmd, statusBarItem, showCommands, showLogsCommand)
}

export const deactivate = async () => client.stop()

const FTLPreflightCheck = async (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.'
)
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)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
} 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}.`
)
vscode.window.showErrorMessage(`FTL version ${version} is not supported. Please upgrade to at least ${MIN_FTL_VERSION}.`)
return false
}

@@ -101,7 +82,7 @@ const FTLPreflightCheck = async (ftlPath: string) => {

const AUTOMATICALLY_START_SERVER_VAR = 'automaticallyStartServer' as const
const PROMPT_OPTIONS = ['Always', 'Yes', 'No', 'Never'] as const
type PromptOption = typeof PROMPT_OPTIONS[number]
type PromptOption = (typeof PROMPT_OPTIONS)[number]
type AutoStartOption = 'always' | 'never' | 'prompt'

const promptStartClient = async (context: vscode.ExtensionContext) => {
@@ -112,37 +93,37 @@ const promptStartClient = async (context: vscode.ExtensionContext) => {
FTLStatus.ftlStopped(statusBarItem)

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

vscode.window.showInformationMessage(
'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(AUTOMATICALLY_START_SERVER_VAR, 'always', vscode.ConfigurationTarget.Workspace)
await startClient(context)
break
case 'Yes':
await startClient(context)
break
case 'No':
outputChannel.appendLine('FTL development server disabled')
FTLStatus.ftlStopped(statusBarItem)
break
case 'Never':
outputChannel.appendLine('FTL development server set to never auto start')
configuration.update(AUTOMATICALLY_START_SERVER_VAR, 'never', vscode.ConfigurationTarget.Workspace)
FTLStatus.ftlStopped(statusBarItem)
break
}
})
vscode.window
.showInformationMessage('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(AUTOMATICALLY_START_SERVER_VAR, 'always', vscode.ConfigurationTarget.Workspace)
await startClient(context)
break
case 'Yes':
await startClient(context)
break
case 'No':
outputChannel.appendLine('FTL development server disabled')
FTLStatus.ftlStopped(statusBarItem)
break
case 'Never':
outputChannel.appendLine('FTL development server set to never auto start')
configuration.update(AUTOMATICALLY_START_SERVER_VAR, 'never', vscode.ConfigurationTarget.Workspace)
FTLStatus.ftlStopped(statusBarItem)
break
}
})
}

const startClient = async (context: ExtensionContext) => {
12 changes: 6 additions & 6 deletions extensions/vscode/src/status.ts
Original file line number Diff line number Diff line change
@@ -18,32 +18,32 @@ const loadingColors = (statusBarItem: vscode.StatusBarItem) => {
export const FTLStatus = {
ftlStarting: (statusBarItem: vscode.StatusBarItem) => {
loadingColors(statusBarItem)
statusBarItem.text = `$(sync~spin) FTL`
statusBarItem.text = '$(sync~spin) FTL'
statusBarItem.tooltip = 'FTL is starting...'
},
ftlStopped: (statusBarItem: vscode.StatusBarItem) => {
resetColors(statusBarItem)
statusBarItem.text = `$(primitive-square) FTL`
statusBarItem.text = '$(primitive-square) FTL'
statusBarItem.tooltip = 'FTL is stopped.'
},
ftlError: (statusBarItem: vscode.StatusBarItem, message: string) => {
errorColors(statusBarItem)
statusBarItem.text = `$(error) FTL`
statusBarItem.text = '$(error) FTL'
statusBarItem.tooltip = message
},
buildRunning: (statusBarItem: vscode.StatusBarItem) => {
loadingColors(statusBarItem)
statusBarItem.text = `$(gear~spin) FTL`
statusBarItem.text = '$(gear~spin) FTL'
statusBarItem.tooltip = 'FTL project building...'
},
buildOK: (statusBarItem: vscode.StatusBarItem) => {
resetColors(statusBarItem)
statusBarItem.text = `$(zap) FTL`
statusBarItem.text = '$(zap) FTL'
statusBarItem.tooltip = 'FTL project is successfully built.'
},
buildError: (statusBarItem: vscode.StatusBarItem, message: string) => {
errorColors(statusBarItem)
statusBarItem.text = `$(error) FTL`
statusBarItem.text = '$(error) FTL'
statusBarItem.tooltip = message
},
}

0 comments on commit 549b493

Please sign in to comment.