MCPcopy Create free account
hub / github.com/webpro-nl/knip / handleFileChanges

Method handleFileChanges

packages/language-server/src/server.js:296–331  ·  view source on GitHub ↗

* @param {DidChangeWatchedFilesParams} params * @return {Promise }

(params)

Source from the content-addressed store, hash-verified

294 * @return {Promise<void>}
295 */
296 async handleFileChanges(params) {
297 this.fileCache = undefined;
298 this.packageJsonCache = undefined;
299 if (!this.session) return;
300
301 const cwd = this.cwd ?? process.cwd();
302
303 /** @type {{ type: "added" | "deleted" | "modified"; filePath: string }[]} */
304 const changes = [];
305 for (const change of params.changes) {
306 if (!change.uri.startsWith('file:')) continue;
307 const filePath = fileURLToPath(change.uri);
308 if (!filePath.startsWith(cwd) || filePath.includes('/.git/')) continue;
309 if (RESTART_FOR.has(path.basename(change.uri))) return this.restart();
310 const type = FILE_CHANGE_TYPES.get(change.type);
311 if (!type) continue;
312 changes.push({ type, filePath });
313 }
314
315 if (changes.length === 0) return;
316
317 try {
318 const result = await this.session.handleFileChanges(changes);
319
320 if (!result) return;
321
322 this.connection.console.log(
323 `Module graph updated (${Math.floor(result.duration)}ms • ${(result.mem / 1024 / 1024).toFixed(2)}M)`
324 );
325
326 const config = await this.getConfig();
327 this.publishDiagnostics(this.buildDiagnostics(this.session.getIssues().issues, config, this.rules));
328 } catch (_error) {
329 this.connection.console.error(`Error handling file changes: ${_error}`);
330 }
331 }
332
333 /**
334 * @param {string} filePath

Callers 1

setupHandlersMethod · 0.95

Calls 6

restartMethod · 0.95
getConfigMethod · 0.95
publishDiagnosticsMethod · 0.95
buildDiagnosticsMethod · 0.95
handleFileChangesMethod · 0.65
getIssuesMethod · 0.65

Tested by

no test coverage detected