From edddc2cfcd649556e9a8843debec95dac0d264f6 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 12 Mar 2024 07:52:38 +0800 Subject: [PATCH 1/2] WIP: Add assertion for path normalization --- src/SnapshotTesting.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/SnapshotTesting.ts b/src/SnapshotTesting.ts index b04578f9..e0563ed2 100644 --- a/src/SnapshotTesting.ts +++ b/src/SnapshotTesting.ts @@ -1,3 +1,4 @@ +import * as path from 'path' import { Input } from './Input' import { Range } from './Range' import { scip } from './scip' @@ -62,6 +63,12 @@ export function formatSnapshot( const out: string[] = [] const symbolTable = getSymbolTable(doc) + if (path.normalize(doc.relative_path) !== doc.relative_path) { + throw new Error( + `Document path must be normalized: ${doc.relative_path}` + ) + } + const externalSymbolTable: Map = new Map() for (const externalSymbol of externalSymbols) { externalSymbolTable.set(externalSymbol.symbol, externalSymbol) From 2bb6714d3fc58bfcc183d516265f0fba77e68455 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 12 Mar 2024 07:53:11 +0800 Subject: [PATCH 2/2] WIP: Avoid redundant work for same path --- src/ProjectIndexer.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/ProjectIndexer.ts b/src/ProjectIndexer.ts index df823aaf..7baa2369 100644 --- a/src/ProjectIndexer.ts +++ b/src/ProjectIndexer.ts @@ -88,17 +88,18 @@ export class ProjectIndexer { const startTimestamp = Date.now() const sourceFiles = this.program.getSourceFiles() - const filesToIndex: ts.SourceFile[] = [] + const filesToIndexMap: Map = new Map() // Visit every sourceFile in the program for (const sourceFile of sourceFiles) { const includes = this.config.fileNames.includes(sourceFile.fileName) if (!includes) { continue } - filesToIndex.push(sourceFile) + const projectRelativePath = path.normalize(path.relative(this.options.cwd, sourceFile.fileName)) + filesToIndexMap.set(projectRelativePath, sourceFile) } - if (filesToIndex.length === 0) { + if (filesToIndexMap.size === 0) { throw new Error( `no indexable files in project '${this.options.projectDisplayName}'` ) @@ -108,7 +109,7 @@ export class ProjectIndexer { ? new ProgressBar( ` ${this.options.projectDisplayName} [:bar] :current/:total :title`, { - total: filesToIndex.length, + total: filesToIndexMap.size, renderThrottle: 100, incomplete: '_', complete: '#', @@ -119,9 +120,10 @@ export class ProjectIndexer { ) : undefined let lastWrite = startTimestamp - for (const [index, sourceFile] of filesToIndex.entries()) { - const title = path.relative(this.options.cwd, sourceFile.fileName) - jobs?.tick({ title }) + let index = -1 + for (const [projectRelativePath, sourceFile] of filesToIndexMap.entries()) { + index += 1 + jobs?.tick({ title: projectRelativePath }) if (!this.options.progressBar) { const now = Date.now() const elapsed = now - lastWrite @@ -131,7 +133,7 @@ export class ProjectIndexer { } } const document = new scip.scip.Document({ - relative_path: path.relative(this.options.cwd, sourceFile.fileName), + relative_path: projectRelativePath, occurrences: [], }) const input = new Input(sourceFile.fileName, sourceFile.getText())