Skip to content

Commit 805784b

Browse files
committed
fix: update unconfigured cli output
- When the default values are not set, the CLI needs to have access to the envManager to expand the default values (new cross platform default) - Commands that specifically had issues include: - `fish-lsp info --check-health` - `fish-lsp info --time-startup`
1 parent 5c9e34f commit 805784b

File tree

3 files changed

+28
-68
lines changed

3 files changed

+28
-68
lines changed

src/server.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,9 @@ export default class FishServer {
129129
public backgroundAnalysisComplete: boolean;
130130

131131
constructor(
132-
// the connection of the FishServer
133-
// private connection: Connection,
134-
// public analyzer: Analyzer,
135-
// private docs: LspDocuments,
136132
private completion: CompletionPager,
137133
private completionMap: CompletionItemMap,
138134
private documentationCache: DocumentationCache,
139-
// protected logger: Logger,
140135
) {
141136
this.features = { codeActionDisabledSupport: true };
142137
this.clientSupportsShowDocument = false;
@@ -150,7 +145,6 @@ export default class FishServer {
150145
const documentHighlightHandler = getDocumentHighlights(analyzer);
151146

152147
// register the handlers
153-
154148
connection.onDidOpenTextDocument(this.didOpenTextDocument.bind(this));
155149
connection.onDidChangeTextDocument(this.didChangeTextDocument.bind(this));
156150
connection.onDidCloseTextDocument(this.didCloseTextDocument.bind(this));
@@ -287,25 +281,6 @@ export default class FishServer {
287281
workspaceManager.analyzePendingDocuments();
288282
}
289283

290-
// for (const folder of event.added) {
291-
// const workspace = workspaceManager.findWorkspace(folder.uri);
292-
// if (workspace && !workspace.isAnalyzed()) {
293-
// // Analyze the new workspace
294-
// const progress = await AnalyzeProgressToken.create(this.connection, { workspace: workspace });
295-
// // progress.begin('analyzing workspace', 0, `analyzing ${workspace.name}`);
296-
// await this.analyzer.analyzeWorkspace(workspace, (t) => logger.log(t), progress);
297-
// }
298-
// }
299-
//
300-
// // Handle removed workspaces
301-
// for (const folder of event.removed) {
302-
// const workspace = workspaceManager.findWorkspace(folder.uri);
303-
// if (workspace) {
304-
// // Clean up the workspace data
305-
// this.analyzer.clearEntireWorkspace(workspace, this.docs);
306-
// }
307-
// }
308-
// }
309284
// @TODO: REFACTOR THIS OUT OF SERVER
310285
// https://github.com/Dart-Code/Dart-Code/blob/7df6509870d51cc99a90cf220715f4f97c681bbf/src/providers/dart_completion_item_provider.ts#L197-202
311286
// https://github.com/microsoft/vscode-languageserver-node/pull/322
@@ -897,17 +872,5 @@ export default class FishServer {
897872
const root = doc ? analyzer.getRootNode(doc.uri) : undefined;
898873
return { doc, path, root };
899874
}
900-
901-
// public async startBackgroundAnalysis(progress?: ProgressWrapper) {
902-
// const notifyCallback = (text: string) => {
903-
// logger.info(`${new Date().toLocaleTimeString()} - [BACKGROUND ANALYSIS] - ${text}`);
904-
// if (config?.fish_lsp_show_client_popups) {
905-
// connection.window.showInformationMessage(text);
906-
// }
907-
// };
908-
// // analyzer.initiateBackgroundAnalysis(connection, notifyCallback);
909-
// // setTimeout(() => workspaceManager.analyzePendingDocuments(), 500);
910-
// return workspaceManager.analyzePendingDocuments(progress, notifyCallback);
911-
// }
912875
}
913876

src/utils/health-check.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import * as fs from 'fs';
2-
// import * as os from 'os';
32
import * as path from 'path';
43
import { config } from '../config';
54
import { logger } from '../logger';
65
import { initializeParser } from '../parser';
76
import { execAsyncFish } from './exec';
87
import { SyncFileHelper } from './file-operations';
9-
10-
// Add this function to safely run the health check within the server
8+
import { setupProcessEnvExecFile } from './process-env';
119

1210
export async function performHealthCheck() {
11+
await setupProcessEnvExecFile();
1312
logger.logToStdout('fish-lsp health check');
1413
logger.logToStdout('='.repeat(21));
1514

src/utils/startup.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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';
24
import FishServer from '../server';
35
import { createServerLogger, logger } from '../logger';
46
import { config, configHandlers } from '../config';
5-
import * as path from 'path';
6-
import * as os from 'os';
77
import { pathToUri } from './translation';
88
import { PackageVersion } from './commander-cli-subcommands';
9-
109
import { createConnection, InitializeParams, InitializeResult, StreamMessageReader, StreamMessageWriter, ProposedFeatures, Connection } from 'vscode-languageserver/node';
11-
import * as net from 'net';
1210
import { workspaceManager } from './workspace-manager';
11+
import { Workspace } from './workspace';
12+
import { SyncFileHelper } from './file-operations';
1313

1414
// Define proper types for the connection options
1515
export 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

Comments
 (0)