@@ -9,6 +9,7 @@ import fs from 'node:fs';
99import { FineCodeActionsProvider , ActionTreeNode , FinecodeGetActionsResponse } from "./action-tree-provider" ;
1010import { createOutputChannel } from './logging' ;
1111import * as lsProtocol from "vscode-languageserver-protocol" ;
12+ import { createTestController } from "./test-controller" ;
1213
1314
1415let lsClient : LanguageClient | undefined ;
@@ -77,12 +78,14 @@ export async function activate(context: vscode.ExtensionContext) {
7778 outputChannel . info ( 'Starting workspace manager...' ) ;
7879 await runWorkspaceManager ( outputChannel , actionsProvider ) ;
7980
81+ createTestController ( context , getLSClient ) ;
82+
8083 outputChannel . info ( 'Registering commands and providers...' ) ;
8184 context . subscriptions . push (
8285 vscode . window . registerTreeDataProvider ( "fineCodeActions" , actionsProvider ) ,
8386 vscode . commands . registerCommand ( 'finecode.restartWorkspaceManager' , async ( ) => {
8487 outputChannel . info ( 'Restarting workspace manager' ) ;
85- stopWorkspaceManager ( ) ;
88+ await stopWorkspaceManager ( ) ;
8689 runWorkspaceManager ( outputChannel , actionsProvider ) ;
8790 } ) ,
8891 vscode . commands . registerCommand ( "finecode.refreshActions" , ( ) =>
@@ -143,7 +146,7 @@ export async function activate(context: vscode.ExtensionContext) {
143146}
144147
145148export async function deactivate ( ) {
146- await stopWorkspaceManager ( ) ;
149+ await disconnectFromWorkspaceManager ( ) ;
147150}
148151
149152const runWorkspaceManager = async ( outputChannel : vscode . LogOutputChannel , actionsProvider : FineCodeActionsProvider ) => {
@@ -177,20 +180,14 @@ const runWorkspaceManager = async (outputChannel: vscode.LogOutputChannel, actio
177180 }
178181
179182 const finecodeCmdSplit = ( devWorkspacePythonPath as string ) . split ( ' ' ) ;
180- const wmArgs = [ 'start-api' , '--trace' ] ;
183+ const logLevel = vscode . workspace . getConfiguration ( 'finecode' ) . get < string > ( 'logLevel' , 'INFO' ) ;
184+ const wmArgs = [ 'start-lsp' , `--log-level=${ logLevel } ` ] ;
181185 if ( process . env . FINECODE_DEBUG ) {
182186 wmArgs . push ( '--debug' ) ;
183187 }
184188 const serverOptions : ServerOptions = {
185189 command : finecodeCmdSplit [ 0 ] ,
186190 args : [ ...finecodeCmdSplit . slice ( 1 ) , '-m' , 'finecode.cli' , ...wmArgs ] ,
187- // detach from IDE to provide enough time after shutdown to gracefully exit
188- // and avoid not stopped running processes. Workspace Manager is responsible to
189- // exit the process as soon in possible after shutdown signal in any case.
190- //
191- // detached doesn't work as expected:
192- // https://github.com/microsoft/vscode-languageserver-node/issues/1595
193- // temporary detach extension runners instead of workspace manager
194191 options : { cwd : wsDir , detached : false , shell : false } ,
195192 transport : TransportKind . stdio
196193 } ;
@@ -262,8 +259,20 @@ const runWorkspaceManager = async (outputChannel: vscode.LogOutputChannel, actio
262259} ;
263260
264261
262+ const disconnectFromWorkspaceManager = async ( ) => {
263+ if ( lsClient ) {
264+ await lsClient . stop ( ) ;
265+ lsClient = undefined ;
266+ }
267+ } ;
268+
265269const stopWorkspaceManager = async ( ) => {
266270 if ( lsClient ) {
271+ try {
272+ await lsClient . sendRequest ( 'server/shutdown' , { } ) ;
273+ } catch ( error ) {
274+ console . log ( 'Error sending shutdown request to language server:' , error ) ;
275+ }
267276 await lsClient . stop ( ) ;
268277 lsClient = undefined ;
269278 }
0 commit comments