Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions src/services/code-index/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export class CodeIndexOrchestrator {
if (totalInBatch > 0 && this.stateManager.state !== "Indexing") {
this.stateManager.setSystemState("Indexing", "Processing file changes...")
}
this.stateManager.reportFileQueueProgress(
processedInBatch,
totalInBatch,
currentFile ? path.basename(currentFile) : undefined,
)

// Extract package name from file path if possible
let packageName = this.extractPackageName(currentFile)

this.stateManager.reportFileQueueProgress(processedInBatch, totalInBatch, currentFile, packageName)
if (processedInBatch === totalInBatch) {
// Covers (N/N) and (0/0)
if (totalInBatch > 0) {
Expand Down Expand Up @@ -291,4 +291,40 @@ export class CodeIndexOrchestrator {
public get state(): IndexingState {
return this.stateManager.state
}

/**
* Extracts package name from a file path
* @param filePath Path to extract package name from
* @returns Package name if identified, otherwise undefined
*/
private extractPackageName(filePath?: string): string | undefined {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new method lacks test coverage. Could we add unit tests to verify the package name extraction logic works correctly for various path patterns?

if (!filePath) return undefined

// Check if path contains node_modules
const nodeModulesMatch = filePath.match(/node_modules[\\/\\\\](@[^\\/\\\\]+[\\/\\\\][^\\/\\\\]+|[^\\/\\\\]+)/)
if (nodeModulesMatch && nodeModulesMatch[1]) {
return nodeModulesMatch[1]
}

// Check if path contains packages directory structure (monorepo)
const packagesMatch = filePath.match(/packages[\\/\\\\]([^\\/\\\\]+)/)
if (packagesMatch && packagesMatch[1]) {
return packagesMatch[1]
}

// Extract npm package name from package.json if close to the file
try {
const dirPath = path.dirname(filePath)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is declared but never used. Should we remove it?


// Check if it's part of the src/ directory structure
const srcMatch = filePath.match(/src[\\/\\\\]([^\\/\\\\]+)/)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the intended behavior? A file at src/components/Button.tsx would return "components" as the package name, which seems misleading. Should we reconsider this logic or perhaps only use this as a last resort?

if (srcMatch && srcMatch[1]) {
return srcMatch[1]
}
} catch (error) {
// Ignore errors in package name extraction
}

return undefined
}
}
21 changes: 17 additions & 4 deletions src/services/code-index/state-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from "vscode"
import * as path from "path"

export type IndexingState = "Standby" | "Indexing" | "Indexed" | "Error"

Expand Down Expand Up @@ -78,7 +79,12 @@ export class CodeIndexStateManager {
}
}

public reportFileQueueProgress(processedFiles: number, totalFiles: number, currentFileBasename?: string): void {
public reportFileQueueProgress(
processedFiles: number,
totalFiles: number,
currentFilePath?: string,
packageName?: string,
): void {
const progressChanged = processedFiles !== this._processedItems || totalFiles !== this._totalItems

if (progressChanged || this._systemStatus !== "Indexing") {
Expand All @@ -89,9 +95,16 @@ export class CodeIndexStateManager {

let message: string
if (totalFiles > 0 && processedFiles < totalFiles) {
message = `Processing ${processedFiles} / ${totalFiles} ${this._currentItemUnit}. Current: ${
currentFileBasename || "..."
}`
// Extract file information for display
const fileBasename = currentFilePath ? path.basename(currentFilePath) : "..."
const packageDisplay = packageName ? `${packageName}` : ""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These template literals are redundant. Could we simplify to just:

const pathDisplay = currentFilePath ? `${currentFilePath}` : ""

if (packageName) {
message = `Processing ${processedFiles} / ${totalFiles} ${this._currentItemUnit}. Package: ${packageDisplay}, File: ${fileBasename}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we considered using the i18n system for these new status messages? The rest of the codebase uses t() for user-facing strings, and it would maintain consistency.

} else {
message = `Processing ${processedFiles} / ${totalFiles} ${this._currentItemUnit}. Path: ${pathDisplay}`
}
} else if (totalFiles > 0 && processedFiles === totalFiles) {
message = `Finished processing ${totalFiles} ${this._currentItemUnit} from queue.`
} else {
Expand Down
Loading