@@ -79,6 +79,7 @@ import {
7979 additionalContentInnerContextLimit ,
8080 contextMaxLength ,
8181} from '../../constants'
82+ import { ChatSession } from '../../clients/chat/v0/chat'
8283
8384export interface ChatControllerMessagePublishers {
8485 readonly processPromptChatMessage : MessagePublisher < PromptMessage >
@@ -582,14 +583,14 @@ export class ChatController {
582583 private async processFileClickMessage ( message : FileClick ) {
583584 const session = this . sessionStorage . getSession ( message . tabID )
584585 // TODO remove currentContextId but use messageID to track context for each answer message
585- const lineRanges = session . contexts . get ( session . currentContextId ) ?. get ( message . filePath )
586+ const lineRanges = session . contexts . get ( message . filePath )
586587
587588 if ( ! lineRanges ) {
588589 return
589590 }
590591
591592 // TODO: Fix for multiple workspace setup
592- const projectRoot = workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath
593+ const projectRoot = session . relativePathToWorkspaceRoot . get ( message . filePath )
593594 if ( ! projectRoot ) {
594595 return
595596 }
@@ -877,7 +878,10 @@ export class ChatController {
877878 this . messenger . sendStaticTextResponse ( responseType , triggerID , tabID )
878879 }
879880
880- private async resolveContextCommandPayload ( triggerPayload : TriggerPayload ) : Promise < string [ ] > {
881+ private async resolveContextCommandPayload (
882+ triggerPayload : TriggerPayload ,
883+ session : ChatSession
884+ ) : Promise < string [ ] > {
881885 const contextCommands : ContextCommandItem [ ] = [ ]
882886 const relativePaths : string [ ] = [ ]
883887
@@ -914,7 +918,17 @@ export class ChatController {
914918 if ( contextCommands . length === 0 ) {
915919 return [ ]
916920 }
917- const workspaceFolder = contextCommands [ 0 ] . workspaceFolder
921+ const workspaceFolder = vscode . workspace . workspaceFolders ?. [ 0 ] . uri ?. fsPath
922+ if ( ! workspaceFolder ) {
923+ return [ ]
924+ }
925+ for ( const contextCommand of contextCommands ) {
926+ let relativePath = path . relative (
927+ workspaceFolder ,
928+ path . join ( contextCommand . workspaceFolder , contextCommand . relativePath )
929+ )
930+ session . relativePathToWorkspaceRoot . set ( relativePath , contextCommand . workspaceFolder )
931+ }
918932 const prompts = await LspClient . instance . getContextCommandPrompt ( contextCommands )
919933 if ( prompts . length === 0 ) {
920934 return [ ]
@@ -1000,7 +1014,8 @@ export class ChatController {
10001014 return
10011015 }
10021016
1003- const relativePathsOfContextCommandFiles = await this . resolveContextCommandPayload ( triggerPayload )
1017+ const session = this . sessionStorage . getSession ( tabID )
1018+ const relativePathsOfContextCommandFiles = await this . resolveContextCommandPayload ( triggerPayload , session )
10041019 triggerPayload . useRelevantDocuments =
10051020 triggerPayload . context ?. some (
10061021 ( context ) => typeof context !== 'string' && context . command === '@workspace'
@@ -1047,10 +1062,7 @@ export class ChatController {
10471062 triggerPayload . documentReferences = this . mergeRelevantTextDocuments ( triggerPayload . relevantTextDocuments || [ ] )
10481063
10491064 const request = triggerPayloadToChatRequest ( triggerPayload )
1050- const session = this . sessionStorage . getSession ( tabID )
10511065
1052- session . currentContextId ++
1053- session . contexts . set ( session . currentContextId , new Map ( ) )
10541066 if ( triggerPayload . documentReferences !== undefined ) {
10551067 const relativePathsOfMergedRelevantDocuments = triggerPayload . documentReferences . map (
10561068 ( doc ) => doc . relativeFilePath
@@ -1065,10 +1077,7 @@ export class ChatController {
10651077 }
10661078 if ( triggerPayload . documentReferences ) {
10671079 for ( const doc of triggerPayload . documentReferences ) {
1068- const currentContext = session . contexts . get ( session . currentContextId )
1069- if ( currentContext ) {
1070- currentContext . set ( doc . relativeFilePath , doc . lineRanges )
1071- }
1080+ session . contexts . set ( doc . relativeFilePath , doc . lineRanges )
10721081 }
10731082 }
10741083 }
0 commit comments