@@ -178,8 +178,11 @@ function connectClient(
178178 client : ExtendedLSPClient ,
179179 transport : Transport ,
180180 initializationOptions ?: Record < string , unknown > ,
181+ rootUri ?: string | null ,
181182) : void {
182- if ( ! initializationOptions || ! Object . keys ( initializationOptions ) . length ) {
183+ const hasInitializationOptions =
184+ ! ! initializationOptions && Object . keys ( initializationOptions ) . length > 0 ;
185+ if ( ! hasInitializationOptions && ! rootUri ) {
183186 client . connect ( transport ) ;
184187 return ;
185188 }
@@ -199,7 +202,14 @@ function connectClient(
199202 if ( method === "initialize" && isPlainObject ( params ) ) {
200203 params = {
201204 ...params ,
202- initializationOptions,
205+ ...( hasInitializationOptions ? { initializationOptions } : { } ) ,
206+ ...( rootUri
207+ ? {
208+ workspaceFolders : [
209+ { uri : rootUri , name : workspaceName ( rootUri ) } ,
210+ ] ,
211+ }
212+ : { } ) ,
203213 } as Params ;
204214 }
205215 return originalRequestInner < Params , Result > ( method , params , mapped ) ;
@@ -212,6 +222,16 @@ function connectClient(
212222 }
213223}
214224
225+ function workspaceName ( rootUri : string ) : string {
226+ const trimmed = rootUri . replace ( / \/ + $ / , "" ) ;
227+ const encodedName = trimmed . slice ( trimmed . lastIndexOf ( "/" ) + 1 ) ;
228+ try {
229+ return decodeURIComponent ( encodedName ) || "workspace" ;
230+ } catch {
231+ return encodedName || "workspace" ;
232+ }
233+ }
234+
215235interface BuiltinExtensionsResult {
216236 extensions : Extension [ ] ;
217237 diagnosticsExtension : Extension | LSPClientExtension | null ;
@@ -764,6 +784,7 @@ export class LspClientManager {
764784 } ,
765785 workspace : {
766786 configuration : true ,
787+ workspaceFolders : true ,
767788 } ,
768789 } ,
769790 } ;
@@ -1010,7 +1031,12 @@ export class LspClientManager {
10101031 await waitForInitialization ( transportHandle . ready , signal , server . id ) ;
10111032 client = new LSPClient ( clientConfig ) as ExtendedLSPClient ;
10121033 client . __acodeServerId = server . id ;
1013- connectClient ( client , transportHandle . transport , initializationOptions ) ;
1034+ connectClient (
1035+ client ,
1036+ transportHandle . transport ,
1037+ initializationOptions ,
1038+ server . useWorkspaceFolders ? null : normalizedRootUri ,
1039+ ) ;
10141040 await waitForInitialization ( client . initializing , signal , server . id ) ;
10151041 if ( ! client . __acodeLoggedInfo ) {
10161042 // Log root URI info to console
@@ -1032,7 +1058,13 @@ export class LspClientManager {
10321058 ) ;
10331059 }
10341060 logLspInfo ( `[LSP:${ server . id } ] initialized` ) ;
1035- addLspLog ( server . id , "info" , "Initialized" ) ;
1061+ addLspLog (
1062+ server . id ,
1063+ "info" ,
1064+ normalizedRootUri
1065+ ? `Initialized workspace ${ normalizedRootUri } `
1066+ : "Initialized without a workspace root" ,
1067+ ) ;
10361068 client . __acodeLoggedInfo = true ;
10371069 }
10381070 } catch ( error ) {
0 commit comments