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

Method getFileDescriptor

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

* @param {string} filePath * @param {{ isShowContention?: boolean }} [options] * @returns {File | typeof SESSION_LOADING | undefined}

(filePath, options)

Source from the content-addressed store, hash-verified

336 * @returns {File | typeof SESSION_LOADING | undefined}
337 */
338 getFileDescriptor(filePath, options) {
339 if (!this.session) return SESSION_LOADING;
340 const relPath = toPosix(path.relative(this.cwd ?? process.cwd(), filePath));
341 if (relPath.startsWith('..')) return;
342 if (this.fileCache?.filePath === relPath) return this.fileCache.file;
343 const startTime = performance.now();
344 const file = this.session.describeFile(relPath, options);
345 if (file) {
346 const duration = Math.round(performance.now() - startTime);
347 const mem = process.memoryUsage().heapUsed;
348 this.connection.console.log(
349 `Received file descriptor (${relPath} • ${duration}ms • ${(mem / 1024 / 1024).toFixed(2)}M)`
350 );
351 const m = file.metrics;
352 this.connection.console.log(
353 ` ↳ imports: ${Math.round(m.imports)}ms, exports: ${Math.round(m.exports)}ms, cycles: ${Math.round(m.cycles)}ms, contention: ${Math.round(m.contention)}ms`
354 );
355 } else {
356 this.connection.console.log(`File not in project (${relPath})`);
357 }
358 this.fileCache = { filePath: relPath, file };
359 return file;
360 }
361
362 /**
363 * @returns {import('knip/session').PackageJsonFile & { dependenciesUsage: Record<string, import('knip/session').DependencyNodes> } | typeof SESSION_LOADING}

Callers 1

setupHandlersMethod · 0.95

Calls 2

describeFileMethod · 0.80
toPosixFunction · 0.70

Tested by

no test coverage detected