1- // import { Connection, createConnection, InitializeParams, InitializeResult, IPCMessageReader, IPCMessageWriter, ProposedFeatures, SocketMessageReader, SocketMessageWriter, StreamMessageReader, StreamMessageWriter } from 'vscode-languageserver/node';
1+ import * as path from 'path' ;
2+ import * as os from 'os' ;
3+ import * as net from 'net' ;
24import FishServer from '../server' ;
35import { createServerLogger , logger } from '../logger' ;
46import { config , configHandlers } from '../config' ;
5- import * as path from 'path' ;
6- import * as os from 'os' ;
77import { pathToUri } from './translation' ;
88import { PackageVersion } from './commander-cli-subcommands' ;
9-
109import { createConnection , InitializeParams , InitializeResult , StreamMessageReader , StreamMessageWriter , ProposedFeatures , Connection } from 'vscode-languageserver/node' ;
11- import * as net from 'net' ;
1210import { workspaceManager } from './workspace-manager' ;
11+ import { Workspace } from './workspace' ;
12+ import { SyncFileHelper } from './file-operations' ;
1313
1414// Define proper types for the connection options
1515export type ConnectionType = 'stdio' | 'node-ipc' | 'socket' ;
@@ -92,11 +92,6 @@ function setupServerWithConnection(connection: Connection): void {
9292 logger . log ( 'Starting FISH-LSP server' ) ;
9393 logger . log ( 'Server started with the following handlers:' , configHandlers ) ;
9494 logger . log ( 'Server started with the following config:' , config ) ;
95- // connection.onInitialized(async () => {
96- // const progress = await connection.window.createWorkDoneProgress();
97- // // progress.begin('Fish LSP', 0, 'Initializing workspace');
98- // workspaceManager.analyzePendingDocuments(progress);
99- // });
10095}
10196
10297/**
@@ -172,7 +167,10 @@ export async function timeServerStartup() {
172167 name : 'fish-lsp info --time-startup' ,
173168 version : PackageVersion ,
174169 } ,
175- initializationOptions : { } ,
170+ initializationOptions : {
171+ fish_lsp_all_indexed_paths : config . fish_lsp_all_indexed_paths ,
172+ fish_lsp_max_background_files : config . fish_lsp_max_background_files ,
173+ } ,
176174 workspaceFolders : [ ] ,
177175 capabilities : {
178176 workspace : {
@@ -183,6 +181,7 @@ export async function timeServerStartup() {
183181 ( { server } = await FishServer . create ( connection , startupParams ) ) ;
184182 connection . listen ( ) ;
185183 createServerLogger ( config . fish_lsp_log_file , connection . console ) ;
184+
186185 return server ;
187186 } , 'Server Start Time' ) ;
188187
@@ -191,17 +190,24 @@ export async function timeServerStartup() {
191190
192191 // 2. Time server initialization and background analysis
193192 await timeOperation ( async ( ) => {
194- // Create array of workspace analysis promises with timing
195- // await Promise.all(workspaces.orderedWorkspaces().map(async (workspace) => {
196- // items[workspace.path] = workspace.paths.length;
197- // all += workspace.paths.length;
198- // await server!.analyzer.analyzeWorkspace(workspace);
199- // }));
193+ // clear any existing workspaces, use the env variables if they are set,
194+ // otherwise use their default values (since there isn't a client)
195+ workspaceManager . clear ( ) ;
196+ for ( const pathLike of config . fish_lsp_all_indexed_paths ) {
197+ const fullPath = SyncFileHelper . expandEnvVars ( pathLike ) ;
198+ const workspace = Workspace . syncCreateFromUri ( pathToUri ( fullPath ) ) ;
199+ if ( ! workspace ) {
200+ logger . logToStderr ( `Failed to create workspace for path: ${ pathLike } ` ) ;
201+ continue ;
202+ }
203+ workspaceManager . add ( workspace ) ;
204+ }
205+ // analyze all documents from the workspaces created above
200206 const result = await workspaceManager . analyzePendingDocuments ( ) ;
201207 if ( result ) {
202208 all = result . totalDocuments ;
203- for ( const [ path , docUris ] of Object . entries ( result . items ) ) {
204- items [ path ] = docUris . length ;
209+ for ( const [ path , uris ] of Object . entries ( result . items ) ) {
210+ items [ path ] = uris . length ;
205211 }
206212 }
207213 } , 'Background Analysis Time' ) ;
@@ -219,21 +225,13 @@ export async function timeServerStartup() {
219225 `${ all_indexed . length } paths` . padStart ( 20 ) ,
220226 ) ;
221227 // const maxItemLen = all_indexed.reduce((max, item) => Math.max(max, item.length > 60 ? 60 : item.length), 0);
222- config . fish_lsp_all_indexed_paths . forEach ( ( item , idx ) => {
228+ Object . keys ( items ) . forEach ( ( item , idx ) => {
223229 const text = item . length > 55 ? '...' + item . slice ( item . length - 52 ) : item ;
224230 const output = formatColumns ( [ ` [${ idx } ]` , `| ${ text } |` , `${ items [ item ] ?. toString ( ) || 0 } files` ] , [ 6 , - 59 , - 10 ] , 85 ) ;
225231 logger . logToStdout ( output ) ;
226232 } ) ;
227233 // incase we decide to log a different starting directory that isn't `~/.config/fish`
228234 logger . logToStdout ( '-' . repeat ( 85 ) ) ;
229- // Object.keys(items).forEach((key) => {
230- // const indexedPath = config.fish_lsp_all_indexed_paths.findIndex((item) => item === key);
231- // if (indexedPath !== -1) return;
232- // logger.logToStdoutJoined(
233- // ` ${key}`.padEnd(40),
234- // `${items[key]?.toString()} files`.padStart(66),
235- // );
236- // });
237235}
238236
239237/**
0 commit comments