@@ -6,7 +6,7 @@ import { dictionary } from '@shared/constants/dictionary'
66export const handle_go_to_file = async (
77 message : GoToFileMessage
88) : Promise < void > => {
9- const { file_path, workspace_name } = message
9+ const { file_path } = message
1010 const workspace_folders = vscode . workspace . workspaceFolders
1111 if ( ! workspace_folders ) {
1212 Logger . warn ( {
@@ -17,22 +17,31 @@ export const handle_go_to_file = async (
1717 }
1818
1919 let target_workspace : vscode . WorkspaceFolder | undefined
20+ let relative_file_path = file_path
2021
21- if ( workspace_name ) {
22- target_workspace = workspace_folders . find (
23- ( folder ) => folder . name == workspace_name
24- )
25- } else if ( workspace_folders . length == 1 ) {
26- target_workspace = workspace_folders [ 0 ]
27- } else {
22+ if ( workspace_folders . length > 1 ) {
2823 for ( const folder of workspace_folders ) {
29- const potential_uri = vscode . Uri . joinPath ( folder . uri , file_path )
30- try {
31- await vscode . workspace . fs . stat ( potential_uri )
24+ if ( file_path . startsWith ( `${ folder . name } /` ) ) {
3225 target_workspace = folder
26+ relative_file_path = file_path . substring ( folder . name . length + 1 )
3327 break
34- } catch {
35- // file not in this workspace folder
28+ }
29+ }
30+ }
31+
32+ if ( ! target_workspace ) {
33+ if ( workspace_folders . length == 1 ) {
34+ target_workspace = workspace_folders [ 0 ]
35+ } else {
36+ for ( const folder of workspace_folders ) {
37+ const potential_uri = vscode . Uri . joinPath ( folder . uri , file_path )
38+ try {
39+ await vscode . workspace . fs . stat ( potential_uri )
40+ target_workspace = folder
41+ break
42+ } catch {
43+ // file not in this workspace folder
44+ }
3645 }
3746 }
3847 }
@@ -41,15 +50,15 @@ export const handle_go_to_file = async (
4150 Logger . error ( {
4251 function_name : 'handle_go_to_file' ,
4352 message : `Workspace not found for file: ${ file_path } ` ,
44- data : { file_path, workspace_name }
53+ data : { file_path }
4554 } )
4655 vscode . window . showErrorMessage (
4756 dictionary . error_message . WORKSPACE_NOT_FOUND_FOR_FILE ( file_path )
4857 )
4958 return
5059 }
5160
52- const file_uri = vscode . Uri . joinPath ( target_workspace . uri , file_path )
61+ const file_uri = vscode . Uri . joinPath ( target_workspace . uri , relative_file_path )
5362
5463 try {
5564 const document = await vscode . workspace . openTextDocument ( file_uri )
0 commit comments