MCPcopy Index your code
hub / github.com/microsoft/pyright / _removeUnneededFiles

Method _removeUnneededFiles

server/src/analyzer/program.ts:446–494  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

444 // that have been removed. This is needed to clear out the
445 // errors for files that have been deleted or closed.
446 private _removeUnneededFiles(): FileDiagnostics[] {
447 let fileDiagnostics: FileDiagnostics[] = [];
448
449 // If a file is no longer tracked or opened, it can
450 // be removed from the program.
451 for (let i = 0; i < this._sourceFileList.length; ) {
452 let fileInfo = this._sourceFileList[i];
453 if (!this._isFileNeeded(fileInfo)) {
454 fileDiagnostics.push({
455 filePath: fileInfo.sourceFile.getFilePath(),
456 diagnostics: []
457 });
458
459 fileInfo.sourceFile.prepareForClose();
460 delete this._sourceFileMap[fileInfo.sourceFile.getFilePath()];
461 this._sourceFileList.splice(i, 1);
462
463 // Unlink any imports and remove them from the list if
464 // they are no longer referenced.
465 fileInfo.imports.forEach(importedFile => {
466 let indexToRemove = importedFile.importedBy.findIndex(fi => fi === fileInfo);
467 assert(indexToRemove >= 0);
468 importedFile.importedBy.splice(indexToRemove, 1);
469
470 // See if we need to remove the imported file because it
471 // is no longer needed. If its index is >= i, it will be
472 // removed when we get to it.
473 if (!this._isFileNeeded(importedFile)) {
474 let indexToRemove = this._sourceFileList.findIndex(fi => fi === importedFile);
475 if (indexToRemove < i) {
476 fileDiagnostics.push({
477 filePath: importedFile.sourceFile.getFilePath(),
478 diagnostics: []
479 });
480
481 importedFile.sourceFile.prepareForClose();
482 delete this._sourceFileMap[importedFile.sourceFile.getFilePath()];
483 this._sourceFileList.splice(indexToRemove, 1);
484 i--;
485 }
486 }
487 });
488 } else {
489 i++;
490 }
491 }
492
493 return fileDiagnostics;
494 }
495
496 private _isFileNeeded(fileInfo: SourceFileInfo) {
497 if (fileInfo.isTracked || fileInfo.isOpenByClient) {

Callers 3

setTrackedFilesMethod · 0.95
setFileClosedMethod · 0.95
getDiagnosticsMethod · 0.95

Calls 4

_isFileNeededMethod · 0.95
getFilePathMethod · 0.80
prepareForCloseMethod · 0.80
forEachMethod · 0.80

Tested by

no test coverage detected