@@ -363,63 +363,79 @@ local function checkModule(state, word, position, results)
363363 goto CONTINUE
364364 end
365365 local path = furi .decode (uri )
366- local fileName = path :match ' [^/\\ ]*$'
367- local stemName = fileName :gsub (' %..+' , ' ' )
368- if not locals [stemName ]
369- and not vm .hasGlobalSets (state .uri , ' variable' , stemName )
370- and not globals [stemName ]
371- and stemName :match ' ^[%a_][%w_]*$'
372- and matchKey (word , stemName ) then
373- local targetState = files .getState (uri )
374- if not targetState then
375- goto CONTINUE
376- end
377- local targetReturns = targetState .ast .returns
378- if not targetReturns then
379- goto CONTINUE
380- end
381- local targetSource = targetReturns [1 ] and targetReturns [1 ][1 ]
382- if not targetSource then
383- goto CONTINUE
384- end
385- if targetSource .type ~= ' getlocal'
386- and targetSource .type ~= ' table'
387- and targetSource .type ~= ' function' then
388- goto CONTINUE
366+ local relativePath = workspace .getRelativePath (path )
367+ local infos = rpath .getVisiblePath (uri , path )
368+ local testedStem = { }
369+ for _ , sr in ipairs (infos ) do
370+ local pattern = sr .searcher
371+ :gsub (" (%p)" , " %%%1" )
372+ :gsub (" %%%?" , " ([%%a_][%%w_]*)" )
373+
374+ local stemName = relativePath
375+ :match (pattern )
376+
377+ if not stemName or testedStem [stemName ] then
378+ goto INNER_CONTINUE
389379 end
390- if targetSource .type == ' getlocal'
391- and vm .getDeprecated (targetSource .node ) then
392- goto CONTINUE
393- end
394- results [# results + 1 ] = {
395- label = stemName ,
396- kind = define .CompletionItemKind .Variable ,
397- commitCharacters = { ' .' },
398- command = {
399- title = ' autoRequire' ,
400- command = ' lua.autoRequire' ,
401- arguments = {
402- {
403- uri = guide .getUri (state .ast ),
404- target = uri ,
405- name = stemName ,
380+ testedStem [stemName ] = true
381+
382+ if not locals [stemName ]
383+ and not vm .hasGlobalSets (state .uri , ' variable' , stemName )
384+ and not globals [stemName ]
385+ and stemName :match ' ^[%a_][%w_]*$'
386+ and matchKey (word , stemName ) then
387+ local targetState = files .getState (uri )
388+ if not targetState then
389+ goto INNER_CONTINUE
390+ end
391+ local targetReturns = targetState .ast .returns
392+ if not targetReturns then
393+ goto INNER_CONTINUE
394+ end
395+ local targetSource = targetReturns [1 ] and targetReturns [1 ][1 ]
396+ if not targetSource then
397+ goto INNER_CONTINUE
398+ end
399+ if targetSource .type ~= ' getlocal'
400+ and targetSource .type ~= ' table'
401+ and targetSource .type ~= ' function' then
402+ goto INNER_CONTINUE
403+ end
404+ if targetSource .type == ' getlocal'
405+ and vm .getDeprecated (targetSource .node ) then
406+ goto INNER_CONTINUE
407+ end
408+ results [# results + 1 ] = {
409+ label = stemName ,
410+ kind = define .CompletionItemKind .Variable ,
411+ commitCharacters = { ' .' },
412+ command = {
413+ title = ' autoRequire' ,
414+ command = ' lua.autoRequire' ,
415+ arguments = {
416+ {
417+ uri = guide .getUri (state .ast ),
418+ target = uri ,
419+ name = stemName ,
420+ },
406421 },
407422 },
408- },
409- id = stack (function () --- @async
410- local md = markdown ()
411- md :add (' md' , lang .script (' COMPLETION_IMPORT_FROM' , (' [%s](%s)' ):format (
412- workspace .getRelativePath (uri ),
413- uri
414- )))
415- md :add (' md' , buildDesc (targetSource ))
416- return {
417- detail = buildDetail (targetSource ),
418- description = md ,
419- -- additionalTextEdits = buildInsertRequire(state, originUri, stemName),
420- }
421- end )
422- }
423+ id = stack (function () --- @async
424+ local md = markdown ()
425+ md :add (' md' , lang .script (' COMPLETION_IMPORT_FROM' , (' [%s](%s)' ):format (
426+ workspace .getRelativePath (uri ),
427+ uri
428+ )))
429+ md :add (' md' , buildDesc (targetSource ))
430+ return {
431+ detail = buildDetail (targetSource ),
432+ description = md ,
433+ -- additionalTextEdits = buildInsertRequire(state, originUri, stemName),
434+ }
435+ end )
436+ }
437+ end
438+ :: INNER_CONTINUE::
423439 end
424440 :: CONTINUE::
425441 end
0 commit comments