generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: forcefully shutdown ftl from extension (#1672)
- Loading branch information
1 parent
c9d63f8
commit 3608866
Showing
9 changed files
with
273 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: ['.eslintrc.{js,cjs}'], | ||
parserOptions: { | ||
sourceType: 'script', | ||
}, | ||
}, | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint'], | ||
rules: { | ||
'semi': ['error', 'never'], | ||
'quotes': ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': true }], | ||
'jsx-quotes': ['error', 'prefer-single'], | ||
'no-trailing-spaces': 'error', | ||
'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0, 'maxBOF': 0 }], | ||
'eol-last': ['error', 'always'], | ||
'max-len': ['error', { 'code': 120, 'tabWidth': 4, 'ignoreUrls': true, 'ignoreComments': false, 'ignoreRegExpLiterals': true, 'ignoreStrings': true, 'ignoreTemplateLiterals': true }], | ||
'func-style': ['error', 'expression'], | ||
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'], | ||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }], | ||
'@typescript-eslint/ban-ts-comment': [ | ||
2, | ||
{ | ||
'ts-ignore': 'allow-with-description', | ||
}, | ||
], | ||
'indent': ['error', 2, { | ||
'SwitchCase': 1, | ||
'VariableDeclarator': 1, | ||
'outerIIFEBody': 1, | ||
'MemberExpression': 1, | ||
'FunctionDeclaration': { | ||
'parameters': 1, | ||
'body': 1 | ||
}, | ||
'FunctionExpression': { | ||
'parameters': 1, | ||
'body': 1 | ||
}, | ||
'CallExpression': { | ||
'arguments': 1 | ||
}, | ||
'ArrayExpression': 1, | ||
'ObjectExpression': 1, | ||
'ImportDeclaration': 1, | ||
'flatTernaryExpressions': false, | ||
'ignoreComments': false | ||
}], | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
import * as vscode from 'vscode' | ||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
} from 'vscode-languageclient/node' | ||
import { FTLStatus } from './status' | ||
|
||
export class FTLClient { | ||
private clientName = 'ftl languge server' | ||
private clientId = 'ftl' | ||
|
||
private statusBarItem: vscode.StatusBarItem | ||
private outputChannel: vscode.OutputChannel | ||
private client: LanguageClient | undefined | ||
private isClientStarting = false | ||
|
||
constructor(statusBar: vscode.StatusBarItem, output: vscode.OutputChannel) { | ||
this.statusBarItem = statusBar | ||
this.outputChannel = output | ||
} | ||
|
||
public async start(ftlPath: string, cwd: string, flags: string[], context: vscode.ExtensionContext) { | ||
if (this.client || this.isClientStarting) { | ||
this.outputChannel.appendLine('FTL client already running or starting') | ||
return | ||
} | ||
this.isClientStarting = true | ||
|
||
this.outputChannel.appendLine('FTL extension activated') | ||
|
||
const serverOptions: ServerOptions = { | ||
run: { | ||
command: `${ftlPath}`, | ||
args: ['dev', ...flags], | ||
options: { cwd: cwd } | ||
}, | ||
debug: { | ||
command: `${ftlPath}`, | ||
args: ['dev', ...flags], | ||
options: { cwd: cwd } | ||
}, | ||
} | ||
|
||
this.outputChannel.appendLine(`Running ${ftlPath} with flags: ${flags.join(' ')}`) | ||
console.log(serverOptions.debug.args) | ||
|
||
const clientOptions: LanguageClientOptions = { | ||
documentSelector: [ | ||
{ scheme: 'file', language: 'kotlin' }, | ||
{ scheme: 'file', language: 'go' }, | ||
], | ||
outputChannel: this.outputChannel, | ||
} | ||
|
||
this.client = new LanguageClient( | ||
this.clientId, | ||
this.clientName, | ||
serverOptions, | ||
clientOptions | ||
) | ||
|
||
context.subscriptions.push(this.client) | ||
|
||
this.outputChannel.appendLine('Starting lsp client') | ||
try { | ||
await this.client.start() | ||
this.outputChannel.appendLine('Client started') | ||
console.log(`${this.clientName} started`) | ||
FTLStatus.started(this.statusBarItem) | ||
} catch (error) { | ||
console.error(`Error starting ${this.clientName}: ${error}`) | ||
FTLStatus.error(this.statusBarItem, `Error starting ${this.clientName}: ${error}`) | ||
this.outputChannel.appendLine(`Error starting ${this.clientName}: ${error}`) | ||
} | ||
|
||
this.isClientStarting = false | ||
} | ||
|
||
public async stop() { | ||
if (!this.client && !this.isClientStarting) { | ||
return | ||
} | ||
|
||
const timeout = 10000 // 10 seconds | ||
if (this.isClientStarting) { | ||
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)) | ||
if (Date.now() - startWaitTime > timeout) { | ||
this.outputChannel.appendLine(`Timeout waiting for client to start`) | ||
break | ||
} | ||
} | ||
} | ||
|
||
console.log('Stopping client') | ||
const serverProcess = this.client!['_serverProcess'] | ||
|
||
try { | ||
await this.client!.stop() | ||
await this.client!.dispose() | ||
this.client = undefined | ||
console.log('Client stopped') | ||
} catch (error) { | ||
console.error('Error stopping client', error) | ||
} | ||
|
||
console.log('Stopping server process') | ||
if (serverProcess && !serverProcess.killed) { | ||
try { | ||
process.kill(serverProcess.pid, 'SIGTERM') | ||
// Wait a bit to see if the process terminates | ||
await new Promise(resolve => setTimeout(resolve, 1000)) | ||
|
||
if (!serverProcess.killed) { | ||
console.log('Server process did not terminate with SIGTERM, trying SIGKILL') | ||
process.kill(serverProcess.pid, 'SIGKILL') | ||
console.log('Server process terminated with SIGKILL') | ||
} | ||
} catch (error) { | ||
console.log('SIGTERM failed, trying SIGKILL', error) | ||
try { | ||
// Forcefully terminate if SIGTERM fails | ||
process.kill(serverProcess.pid, 'SIGKILL') | ||
console.log('Server process terminiated with SIGKILL') | ||
} catch (killError) { | ||
console.log('Failed to kill server process', killError) | ||
} | ||
} | ||
} else if (serverProcess && serverProcess.killed) { | ||
console.log('Server process was already killed') | ||
} | ||
|
||
FTLStatus.stopped(this.statusBarItem) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.