@@ -14,6 +14,7 @@ import { registerCommands } from './registerCommands';
1414import { formatterProvider } from './ai_formatter' ;
1515import { clearDiagnosticsOwnedBy , parseAu3CheckOutput } from './diagnosticUtils' ;
1616import conf from './ai_config' ;
17+ import MapTrackingService from './services/MapTrackingService.js' ;
1718
1819const { config } = conf ;
1920
@@ -172,6 +173,76 @@ export const activate = ctx => {
172173
173174 registerCommands ( ctx ) ;
174175
176+ // Initialize MapTrackingService
177+ const workspaceRoot = workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath || '' ;
178+ const autoitConfig = workspace . getConfiguration ( 'autoit' ) ;
179+ const autoitIncludePaths = autoitConfig . get ( 'includePaths' , [ ] ) ;
180+ const maxIncludeDepth = autoitConfig . get ( 'maps.includeDepth' , 3 ) ;
181+
182+ const mapTrackingService = MapTrackingService . getInstance (
183+ workspaceRoot ,
184+ autoitIncludePaths ,
185+ maxIncludeDepth ,
186+ ) ;
187+
188+ // Debounce timer for file changes
189+ let updateTimer = null ;
190+ const DEBOUNCE_DELAY = 300 ; // ms
191+
192+ // Track document changes with debouncing
193+ const onDocumentChange = document => {
194+ if ( document . languageId !== 'autoit' ) return ;
195+
196+ clearTimeout ( updateTimer ) ;
197+ updateTimer = setTimeout ( ( ) => {
198+ mapTrackingService . updateFile ( document . uri . fsPath , document . getText ( ) ) ;
199+ } , DEBOUNCE_DELAY ) ;
200+ } ;
201+
202+ // Handle document open
203+ ctx . subscriptions . push (
204+ workspace . onDidOpenTextDocument ( document => {
205+ if ( document . languageId === 'autoit' ) {
206+ mapTrackingService . updateFile ( document . uri . fsPath , document . getText ( ) ) ;
207+ }
208+ } ) ,
209+ ) ;
210+
211+ // Handle document change (debounced)
212+ ctx . subscriptions . push (
213+ workspace . onDidChangeTextDocument ( event => {
214+ onDocumentChange ( event . document ) ;
215+ } ) ,
216+ ) ;
217+
218+ // Handle document save (immediate update)
219+ ctx . subscriptions . push (
220+ workspace . onDidSaveTextDocument ( document => {
221+ if ( document . languageId === 'autoit' ) {
222+ clearTimeout ( updateTimer ) ; // Cancel debounce
223+ mapTrackingService . updateFile ( document . uri . fsPath , document . getText ( ) ) ;
224+ }
225+ } ) ,
226+ ) ;
227+
228+ // Handle document close
229+ ctx . subscriptions . push (
230+ workspace . onDidCloseTextDocument ( document => {
231+ if ( document . languageId === 'autoit' ) {
232+ clearTimeout ( updateTimer ) ;
233+ // Note: We keep the file in cache for includes
234+ // mapTrackingService.removeFile(document.uri.fsPath);
235+ }
236+ } ) ,
237+ ) ;
238+
239+ // Parse all open AutoIt documents
240+ workspace . textDocuments . forEach ( document => {
241+ if ( document . languageId === 'autoit' ) {
242+ mapTrackingService . updateFile ( document . uri . fsPath , document . getText ( ) ) ;
243+ }
244+ } ) ;
245+
175246 if ( process . platform === 'win32' ) {
176247 const diagnosticCollection = languages . createDiagnosticCollection ( 'autoit' ) ;
177248 ctx . subscriptions . push ( diagnosticCollection ) ;
0 commit comments