@@ -4,6 +4,7 @@ import { RooIgnoreController } from "../../../core/ignore/RooIgnoreController"
44import { stat } from "fs/promises"
55import * as path from "path"
66import { generateNormalizedAbsolutePath , generateRelativeFilePath } from "../shared/get-relative-path"
7+ import { getWorkspacePathForContext } from "../../../utils/path"
78import { scannerExtensions } from "../shared/supported-extensions"
89import * as vscode from "vscode"
910import { CodeBlock , ICodeParser , IEmbedder , IVectorStore , IDirectoryScanner } from "../interfaces"
@@ -49,6 +50,9 @@ export class DirectoryScanner implements IDirectoryScanner {
4950 onFileParsed ?: ( fileBlockCount : number ) => void ,
5051 ) : Promise < { codeBlocks : CodeBlock [ ] ; stats : { processed : number ; skipped : number } ; totalBlockCount : number } > {
5152 const directoryPath = directory
53+ // Capture workspace context at scan start
54+ const scanWorkspace = getWorkspacePathForContext ( directoryPath )
55+
5256 // Get all files recursively (handles .gitignore automatically)
5357 const [ allPaths , _ ] = await listFiles ( directoryPath , true , MAX_LIST_FILES_LIMIT )
5458
@@ -66,7 +70,7 @@ export class DirectoryScanner implements IDirectoryScanner {
6670 // Filter by supported extensions, ignore patterns, and excluded directories
6771 const supportedPaths = allowedPaths . filter ( ( filePath ) => {
6872 const ext = path . extname ( filePath ) . toLowerCase ( )
69- const relativeFilePath = generateRelativeFilePath ( filePath )
73+ const relativeFilePath = generateRelativeFilePath ( filePath , scanWorkspace )
7074
7175 // Check if file is in an ignored directory using the shared helper
7276 if ( isPathInIgnoredDirectory ( filePath ) ) {
@@ -169,6 +173,7 @@ export class DirectoryScanner implements IDirectoryScanner {
169173 batchBlocks ,
170174 batchTexts ,
171175 batchFileInfos ,
176+ scanWorkspace ,
172177 onError ,
173178 onBlocksIndexed ,
174179 ) ,
@@ -185,12 +190,15 @@ export class DirectoryScanner implements IDirectoryScanner {
185190 await this . cacheManager . updateHash ( filePath , currentFileHash )
186191 }
187192 } catch ( error ) {
188- console . error ( `Error processing file ${ filePath } :` , error )
193+ console . error ( `Error processing file ${ filePath } in workspace ${ scanWorkspace } :` , error )
189194 if ( onError ) {
190195 onError (
191196 error instanceof Error
192- ? error
193- : new Error ( t ( "embeddings:scanner.unknownErrorProcessingFile" , { filePath } ) ) ,
197+ ? new Error ( `${ error . message } (Workspace: ${ scanWorkspace } , File: ${ filePath } )` )
198+ : new Error (
199+ t ( "embeddings:scanner.unknownErrorProcessingFile" , { filePath } ) +
200+ ` (Workspace: ${ scanWorkspace } )` ,
201+ ) ,
194202 )
195203 }
196204 }
@@ -214,7 +222,7 @@ export class DirectoryScanner implements IDirectoryScanner {
214222
215223 // Queue final batch processing
216224 const batchPromise = batchLimiter ( ( ) =>
217- this . processBatch ( batchBlocks , batchTexts , batchFileInfos , onError , onBlocksIndexed ) ,
225+ this . processBatch ( batchBlocks , batchTexts , batchFileInfos , scanWorkspace , onError , onBlocksIndexed ) ,
218226 )
219227 activeBatchPromises . push ( batchPromise )
220228 } finally {
@@ -235,15 +243,20 @@ export class DirectoryScanner implements IDirectoryScanner {
235243 await this . qdrantClient . deletePointsByFilePath ( cachedFilePath )
236244 await this . cacheManager . deleteHash ( cachedFilePath )
237245 } catch ( error ) {
238- console . error ( `[DirectoryScanner] Failed to delete points for ${ cachedFilePath } :` , error )
246+ console . error (
247+ `[DirectoryScanner] Failed to delete points for ${ cachedFilePath } in workspace ${ scanWorkspace } :` ,
248+ error ,
249+ )
239250 if ( onError ) {
240251 onError (
241252 error instanceof Error
242- ? error
253+ ? new Error (
254+ `${ error . message } (Workspace: ${ scanWorkspace } , File: ${ cachedFilePath } )` ,
255+ )
243256 : new Error (
244257 t ( "embeddings:scanner.unknownErrorDeletingPoints" , {
245258 filePath : cachedFilePath ,
246- } ) ,
259+ } ) + ` (Workspace: ${ scanWorkspace } )` ,
247260 ) ,
248261 )
249262 }
@@ -267,6 +280,7 @@ export class DirectoryScanner implements IDirectoryScanner {
267280 batchBlocks : CodeBlock [ ] ,
268281 batchTexts : string [ ] ,
269282 batchFileInfos : { filePath : string ; fileHash : string ; isNew : boolean } [ ] ,
283+ scanWorkspace : string ,
270284 onError ?: ( error : Error ) => void ,
271285 onBlocksIndexed ?: ( indexedCount : number ) => void ,
272286 ) : Promise < void > {
@@ -292,11 +306,14 @@ export class DirectoryScanner implements IDirectoryScanner {
292306 await this . qdrantClient . deletePointsByMultipleFilePaths ( uniqueFilePaths )
293307 } catch ( deleteError ) {
294308 console . error (
295- `[DirectoryScanner] Failed to delete points for ${ uniqueFilePaths . length } files before upsert:` ,
309+ `[DirectoryScanner] Failed to delete points for ${ uniqueFilePaths . length } files before upsert in workspace ${ scanWorkspace } :` ,
296310 deleteError ,
297311 )
298- // Re-throw the error to stop processing this batch attempt
299- throw deleteError
312+ // Re-throw the error with workspace context
313+ throw new Error (
314+ `Failed to delete points for ${ uniqueFilePaths . length } files. Workspace: ${ scanWorkspace } . ${ deleteError instanceof Error ? deleteError . message : String ( deleteError ) } ` ,
315+ { cause : deleteError } ,
316+ )
300317 }
301318 }
302319 // --- End Deletion Step ---
@@ -306,7 +323,7 @@ export class DirectoryScanner implements IDirectoryScanner {
306323
307324 // Prepare points for Qdrant
308325 const points = batchBlocks . map ( ( block , index ) => {
309- const normalizedAbsolutePath = generateNormalizedAbsolutePath ( block . file_path )
326+ const normalizedAbsolutePath = generateNormalizedAbsolutePath ( block . file_path , scanWorkspace )
310327
311328 // Use segmentHash for unique ID generation to handle multiple segments from same line
312329 const pointId = uuidv5 ( block . segmentHash , QDRANT_CODE_BLOCK_NAMESPACE )
@@ -315,7 +332,7 @@ export class DirectoryScanner implements IDirectoryScanner {
315332 id : pointId ,
316333 vector : embeddings [ index ] ,
317334 payload : {
318- filePath : generateRelativeFilePath ( normalizedAbsolutePath ) ,
335+ filePath : generateRelativeFilePath ( normalizedAbsolutePath , scanWorkspace ) ,
319336 codeChunk : block . content ,
320337 startLine : block . start_line ,
321338 endLine : block . end_line ,
@@ -335,7 +352,10 @@ export class DirectoryScanner implements IDirectoryScanner {
335352 success = true
336353 } catch ( error ) {
337354 lastError = error as Error
338- console . error ( `[DirectoryScanner] Error processing batch (attempt ${ attempts } ):` , error )
355+ console . error (
356+ `[DirectoryScanner] Error processing batch (attempt ${ attempts } ) in workspace ${ scanWorkspace } :` ,
357+ error ,
358+ )
339359
340360 if ( attempts < MAX_BATCH_RETRIES ) {
341361 const delay = INITIAL_RETRY_DELAY_MS * Math . pow ( 2 , attempts - 1 )
0 commit comments