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