@@ -31,17 +31,22 @@ export const check_referencing_files_for_context_command = (
3131
3232 if ( ! locations ) return [ ]
3333
34- const unique_paths = new Set < string > ( )
34+ const file_map = new Map < string , vscode . Range > ( )
3535 locations . forEach ( ( loc ) => {
3636 const file_path = loc . uri . fsPath
3737 if (
3838 workspace_provider . get_workspace_root_for_file ( file_path ) &&
3939 ! workspace_provider . is_ignored_by_patterns ( file_path )
4040 ) {
41- unique_paths . add ( file_path )
41+ if ( ! file_map . has ( file_path ) ) {
42+ file_map . set ( file_path , loc . range )
43+ }
4244 }
4345 } )
44- return Array . from ( unique_paths )
46+ return Array . from ( file_map . entries ( ) ) . map ( ( [ file_path , range ] ) => ( {
47+ file_path,
48+ range
49+ } ) )
4550 }
4651 )
4752
@@ -57,7 +62,9 @@ export const check_referencing_files_for_context_command = (
5762 tooltip : t ( 'common.go-to-file' )
5863 }
5964
60- const quick_pick_items = matched_files . map ( ( file_path ) => {
65+ const currently_checked = workspace_provider . get_checked_files ( )
66+
67+ const quick_pick_items = matched_files . map ( ( { file_path, range } ) => {
6168 const workspace_root =
6269 workspace_provider . get_workspace_root_for_file ( file_path )
6370 const relative_path = workspace_root
@@ -68,16 +75,19 @@ export const check_referencing_files_for_context_command = (
6875 return {
6976 label : path . basename ( file_path ) ,
7077 description : dir_name == '.' ? '' : dir_name ,
71- file_path : file_path ,
78+ file_path,
79+ range,
7280 buttons : [ open_file_button ]
7381 }
7482 } )
7583
7684 const quick_pick = vscode . window . createQuickPick <
77- vscode . QuickPickItem & { file_path : string }
85+ vscode . QuickPickItem & { file_path : string ; range : vscode . Range }
7886 > ( )
7987 quick_pick . items = quick_pick_items
80- quick_pick . selectedItems = quick_pick_items
88+ quick_pick . selectedItems = quick_pick_items . filter ( ( item ) =>
89+ currently_checked . includes ( item . file_path )
90+ )
8191 quick_pick . canSelectMany = true
8292 quick_pick . placeholder = t (
8393 'command.context.check-references.select-files'
@@ -94,7 +104,11 @@ export const check_referencing_files_for_context_command = (
94104 quick_pick . buttons = [ close_button ]
95105
96106 const selected_items = await new Promise <
97- readonly ( vscode . QuickPickItem & { file_path : string } ) [ ] | undefined
107+ | readonly ( vscode . QuickPickItem & {
108+ file_path : string
109+ range : vscode . Range
110+ } ) [ ]
111+ | undefined
98112 > ( ( resolve ) => {
99113 let is_accepted = false
100114
@@ -125,7 +139,8 @@ export const check_referencing_files_for_context_command = (
125139 e . item . file_path
126140 )
127141 await vscode . window . showTextDocument ( doc , {
128- preview : true
142+ preview : true ,
143+ selection : e . item . range
129144 } )
130145 } catch ( error ) {
131146 vscode . window . showErrorMessage (
@@ -145,11 +160,12 @@ export const check_referencing_files_for_context_command = (
145160 }
146161
147162 const selected_paths = selected_items . map ( ( item ) => item . file_path )
148- const currently_checked = workspace_provider . get_checked_files ( )
149163
150164 const selected_paths_set = new Set ( selected_paths )
151165 const unselected_files_set = new Set (
152- matched_files . filter ( ( file ) => ! selected_paths_set . has ( file ) )
166+ matched_files
167+ . map ( ( m ) => m . file_path )
168+ . filter ( ( file_path ) => ! selected_paths_set . has ( file_path ) )
153169 )
154170 const currently_checked_filtered = currently_checked . filter (
155171 ( file ) => ! unselected_files_set . has ( file )
0 commit comments