@@ -11,6 +11,7 @@ import {
1111 variablePattern ,
1212} from './util' ;
1313import DEFAULT_UDFS from './constants' ;
14+ import MapTrackingService from './services/MapTrackingService.js' ;
1415
1516// Per-document cache for include completions
1617const includeCache = new Map ( ) ; // Map<documentUri, { files: string[], completions: CompletionItem[] }>
@@ -197,6 +198,55 @@ const getLocalFunctionCompletions = text => {
197198 return functions ;
198199} ;
199200
201+ /**
202+ * Get completions for Map variable keys
203+ * @param {import('vscode').TextDocument } document
204+ * @param {import('vscode').Position } position
205+ * @param {string } mapName - The Map variable name (e.g., '$mUser')
206+ * @returns {import('vscode').CompletionItem[] }
207+ */
208+ const getMapKeyCompletions = ( document , position , mapName ) => {
209+ const config = workspace . getConfiguration ( 'autoit.maps' ) ;
210+ const enableIntelligence = config . get ( 'enableIntelligence' , true ) ;
211+ const showFunctionKeys = config . get ( 'showFunctionKeys' , true ) ;
212+
213+ if ( ! enableIntelligence ) {
214+ return [ ] ;
215+ }
216+
217+ const mapTrackingService = MapTrackingService . getInstance ( ) ;
218+ const filePath = document . uri . fsPath ;
219+ const line = position . line ;
220+
221+ const result = mapTrackingService . getKeysForMapWithIncludes ( filePath , mapName , line ) ;
222+
223+ const completions = [ ] ;
224+
225+ // Add direct keys (high confidence)
226+ result . directKeys . forEach ( key => {
227+ const item = new CompletionItem ( key , CompletionItemKind . Property ) ;
228+ item . detail = `${ mapName } property` ;
229+ item . sortText = `0_${ key } ` ; // Sort direct keys first
230+ completions . push ( item ) ;
231+ } ) ;
232+
233+ // Add function-added keys (medium confidence)
234+ if ( showFunctionKeys ) {
235+ const seenFunctionKeys = new Set ( ) ;
236+ result . functionKeys . forEach ( keyObj => {
237+ if ( ! seenFunctionKeys . has ( keyObj . key ) ) {
238+ seenFunctionKeys . add ( keyObj . key ) ;
239+ const item = new CompletionItem ( keyObj . key , CompletionItemKind . Field ) ;
240+ item . detail = `${ mapName } property (added in function)` ;
241+ item . sortText = `1_${ keyObj . key } ` ; // Sort after direct keys
242+ completions . push ( item ) ;
243+ }
244+ } ) ;
245+ }
246+
247+ return completions ;
248+ } ;
249+
200250const provideCompletionItems = ( document , position ) => {
201251 // Gather the functions created by the user
202252
@@ -214,6 +264,15 @@ const provideCompletionItems = (document, position) => {
214264 const firstChar = line . text . charAt ( line . firstNonWhitespaceCharacterIndex ) ;
215265 if ( firstChar === ';' || _functionPattern . test ( line . text ) ) return null ;
216266
267+ // Check if we're completing Map keys (e.g., $mUser.)
268+ const linePrefix = line . text . slice ( 0 , position . character ) ;
269+ const mapKeyPattern = / ( \$ [ a - z A - Z _ ] \w * ) \. \s * $ / ;
270+ const mapMatch = linePrefix . match ( mapKeyPattern ) ;
271+
272+ if ( mapMatch ) {
273+ return getMapKeyCompletions ( document , position , mapMatch [ 1 ] ) ;
274+ }
275+
217276 const variableCompletions = getVariableCompletions ( text , prefix ) ;
218277 const functionCompletions = getLocalFunctionCompletions ( text ) ;
219278
0 commit comments