11import * as vscode from 'vscode'
2- import * as path from 'path'
32import {
43 WorkspaceProvider ,
54 FileItem
65} from './providers/workspace/workspace-provider'
7- import { FilesCollector } from '../utils/files-collector'
86import { OpenEditorsProvider } from './providers/open-editors/open-editors-provider'
97import { SharedContextState } from './shared-context-state'
108import { EventEmitter } from 'events'
11- import { dictionary } from '@shared/constants/dictionary'
129import {
1310 CONTEXT_CHECKED_PATHS_STATE_KEY ,
1411 CONTEXT_CHECKED_TIMESTAMPS_STATE_KEY ,
@@ -17,8 +14,6 @@ import {
1714 type DuplicateWorkspaceContext
1815} from '../constants/state-keys'
1916import { SelectedFilesProvider } from './providers/selected-files/selected-files-provider'
20- import { is_binary_file } from '../utils/is-binary'
21- import { PromptBuilder } from '../utils/prompt-builder'
2217
2318export const token_count_emitter = new EventEmitter ( )
2419
@@ -127,11 +122,6 @@ export const context_initialization = async (
127122 shared_context_state
128123 } )
129124
130- const files_collector = new FilesCollector ( {
131- workspace_provider,
132- open_editors_provider
133- } )
134-
135125 const update_view_badges = async ( ) => {
136126 let context_token_count = 0
137127 if ( selected_files_provider && selected_files_view ) {
@@ -209,115 +199,6 @@ export const context_initialization = async (
209199 )
210200
211201 context . subscriptions . push (
212- vscode . commands . registerCommand ( 'codeWebChat.copyContext' , async ( ) => {
213- let context_text = ''
214-
215- try {
216- const collected = await files_collector . collect_files ( )
217- context_text = collected . other_files + collected . recent_files
218- } catch ( error : any ) {
219- console . error ( 'Error collecting files:' , error )
220- vscode . window . showErrorMessage (
221- dictionary . error_message . ERROR_COLLECTING_FILES ( error . message )
222- )
223- return
224- }
225-
226- if ( context_text == '' ) {
227- vscode . window . showWarningMessage (
228- dictionary . warning_message . NO_FILES_SELECTED
229- )
230- return
231- }
232-
233- context_text =
234- PromptBuilder . build_prompt ( { context_text } ) . full_prompt + '\n'
235- await vscode . env . clipboard . writeText ( context_text )
236- vscode . window . showInformationMessage (
237- dictionary . information_message . CONTEXT_COPIED_TO_CLIPBOARD
238- )
239- } ) ,
240- vscode . commands . registerCommand (
241- 'codeWebChat.copyContextOpenEditors' ,
242- async ( ) => {
243- if ( ! open_editors_provider ) return
244- const checked_files = open_editors_provider . get_checked_files ( )
245-
246- if ( checked_files . length == 0 ) {
247- vscode . window . showWarningMessage (
248- dictionary . warning_message . NO_OPEN_EDITORS_SELECTED
249- )
250- return
251- }
252-
253- let context_text = ''
254- const workspace_folders = vscode . workspace . workspaceFolders
255- const is_multi_root =
256- ! ! workspace_folders && workspace_folders . length > 1
257-
258- for ( const file_path of checked_files ) {
259- try {
260- const file_uri = vscode . Uri . file ( file_path )
261- const content_uint8_array =
262- await vscode . workspace . fs . readFile ( file_uri )
263-
264- let display_path : string
265- const workspace_folder =
266- vscode . workspace . getWorkspaceFolder ( file_uri )
267-
268- if ( is_multi_root && workspace_folder ) {
269- const relative_path = path . relative (
270- workspace_folder . uri . fsPath ,
271- file_path
272- )
273- display_path = `${ workspace_folder . name } /${ relative_path } `
274- } else {
275- display_path = vscode . workspace . asRelativePath ( file_path )
276- }
277-
278- if ( is_binary_file ( file_path , content_uint8_array ) ) {
279- context_text += PromptBuilder . build_file_context ( {
280- filepath : display_path ,
281- is_binary : true
282- } )
283- continue
284- }
285-
286- let content = new TextDecoder ( ) . decode ( content_uint8_array )
287-
288- const range = workspace_provider . get_range ( file_path )
289- if ( range ) {
290- content = workspace_provider . apply_range_to_content (
291- content ,
292- range
293- )
294- }
295-
296- context_text += PromptBuilder . build_file_context ( {
297- filepath : display_path ,
298- content
299- } )
300- } catch ( error : any ) {
301- vscode . window . showErrorMessage (
302- dictionary . error_message . ERROR_READING_FILE (
303- file_path ,
304- error . message
305- )
306- )
307- }
308- }
309-
310- if ( context_text == '' ) return
311-
312- context_text =
313- PromptBuilder . build_prompt ( { context_text } ) . full_prompt + '\n'
314- await vscode . env . clipboard . writeText ( context_text )
315- vscode . window . showInformationMessage (
316- dictionary . information_message
317- . CONTEXT_FROM_OPEN_EDITORS_COPIED_TO_CLIPBOARD
318- )
319- }
320- ) ,
321202 vscode . commands . registerCommand (
322203 'codeWebChat.expandContextFolders' ,
323204 async ( ) => {
0 commit comments