Skip to content

Commit 2bb6714

Browse files
WIP: Avoid redundant work for same path
1 parent edddc2c commit 2bb6714

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/ProjectIndexer.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,18 @@ export class ProjectIndexer {
8888
const startTimestamp = Date.now()
8989
const sourceFiles = this.program.getSourceFiles()
9090

91-
const filesToIndex: ts.SourceFile[] = []
91+
const filesToIndexMap: Map<string, ts.SourceFile> = new Map()
9292
// Visit every sourceFile in the program
9393
for (const sourceFile of sourceFiles) {
9494
const includes = this.config.fileNames.includes(sourceFile.fileName)
9595
if (!includes) {
9696
continue
9797
}
98-
filesToIndex.push(sourceFile)
98+
const projectRelativePath = path.normalize(path.relative(this.options.cwd, sourceFile.fileName))
99+
filesToIndexMap.set(projectRelativePath, sourceFile)
99100
}
100101

101-
if (filesToIndex.length === 0) {
102+
if (filesToIndexMap.size === 0) {
102103
throw new Error(
103104
`no indexable files in project '${this.options.projectDisplayName}'`
104105
)
@@ -108,7 +109,7 @@ export class ProjectIndexer {
108109
? new ProgressBar(
109110
` ${this.options.projectDisplayName} [:bar] :current/:total :title`,
110111
{
111-
total: filesToIndex.length,
112+
total: filesToIndexMap.size,
112113
renderThrottle: 100,
113114
incomplete: '_',
114115
complete: '#',
@@ -119,9 +120,10 @@ export class ProjectIndexer {
119120
)
120121
: undefined
121122
let lastWrite = startTimestamp
122-
for (const [index, sourceFile] of filesToIndex.entries()) {
123-
const title = path.relative(this.options.cwd, sourceFile.fileName)
124-
jobs?.tick({ title })
123+
let index = -1
124+
for (const [projectRelativePath, sourceFile] of filesToIndexMap.entries()) {
125+
index += 1
126+
jobs?.tick({ title: projectRelativePath })
125127
if (!this.options.progressBar) {
126128
const now = Date.now()
127129
const elapsed = now - lastWrite
@@ -131,7 +133,7 @@ export class ProjectIndexer {
131133
}
132134
}
133135
const document = new scip.scip.Document({
134-
relative_path: path.relative(this.options.cwd, sourceFile.fileName),
136+
relative_path: projectRelativePath,
135137
occurrences: [],
136138
})
137139
const input = new Input(sourceFile.fileName, sourceFile.getText())

0 commit comments

Comments
 (0)