@@ -88,23 +88,43 @@ function M.resolve_python_import(symbol, current_file_path)
8888 .. current_file_path
8989 .. " "
9090 .. build_symbol_regexes (symbol , IMPORTABLE_SYMBOLS_PATTERNS )
91+ --- fd -H -I -p "/sqlalchemy/__init__.py$|/sqlalchemy.py$" ~.venv/lib/python3.11/site-package
92+ local fd_args = ' -H -I -p "/'
93+ .. symbol
94+ .. " /__init__.py$|/"
95+ .. symbol
96+ .. " .py$"
97+ .. ' "'
98+ .. " "
9199 local candidate_paths = jobs .find_import_candidates (gg_args , target_paths )
100+ local modules_paths =
101+ jobs .find_import_modules_candidates (fd_args , target_paths )
102+ log .debug (" Modules: " .. vim .inspect (modules_paths ))
92103 log .debug (" Candidates: " .. vim .inspect (candidate_paths ))
93104 candidate_paths = filter_candidates (candidate_paths )
105+ modules_paths = filter_candidates (modules_paths )
106+ local result = {}
94107
95- local import_candidates = {}
96108 for _ , path in ipairs (candidate_paths ) do
97109 local _path = utils .make_relative_to (path , root )
98- local import_path = utils .to_import_path (_path )
99- table.insert (import_candidates , import_path )
110+ local reference_path = utils .to_python_reference_path (_path , symbol )
111+ table.insert (result , reference_path )
112+ end
113+
114+ for _ , path in ipairs (modules_paths ) do
115+ local _path = utils .make_relative_to (path , root )
116+ local reference_path = utils .to_python_reference_path (_path )
117+ table.insert (result , reference_path )
100118 end
101- -- sort imports by length
102- table.sort (import_candidates , function (a , b )
119+
120+ result = utils .deduplicate_list (result )
121+
122+ table.sort (result , function (a , b )
103123 -- TODO: add other sorting rules (e.g. alphabetical, private modules, etc.)
104124 return # a < # b
105125 end )
106126
107- return import_candidates
127+ return result
108128end
109129
110130return M
0 commit comments