Skip to content

Commit ba0f0b7

Browse files
committed
feat(extension): integrate MapTrackingService with document events
1 parent 7667736 commit ba0f0b7

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,21 @@
540540
"minimum": 1,
541541
"maximum": 100,
542542
"description": "Number of files to process in each batch when building workspace symbol index. Lower values reduce UI freezing but take longer to complete."
543+
},
544+
"autoit.maps.enableIntelligence": {
545+
"type": "boolean",
546+
"default": true,
547+
"description": "Enable intelligent Map key completions"
548+
},
549+
"autoit.maps.includeDepth": {
550+
"type": "number",
551+
"default": 3,
552+
"description": "Maximum depth for resolving #include files when tracking Map keys"
553+
},
554+
"autoit.maps.showFunctionKeys": {
555+
"type": "boolean",
556+
"default": true,
557+
"description": "Show keys added by function parameters (marked with lower confidence)"
543558
}
544559
}
545560
},

src/extension.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { registerCommands } from './registerCommands';
1414
import { formatterProvider } from './ai_formatter';
1515
import { clearDiagnosticsOwnedBy, parseAu3CheckOutput } from './diagnosticUtils';
1616
import conf from './ai_config';
17+
import MapTrackingService from './services/MapTrackingService.js';
1718

1819
const { 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

Comments
 (0)