11local config = require " python_import.config"
22local lookup_table = require " python_import.lookup_table"
33
4+ --- In Lua, if a value in a table is set to `nil`, it is treated as if the key does not exist.
5+ --- Thus, we use `vim.NIL` in the PythonImport.UserConfig to indicate that the value should be removed from the table.
6+ --- @param t table
7+ local function remove_vim_nil (t )
8+ for k , v in pairs (t ) do
9+ if v == vim .NIL then
10+ t [k ] = nil
11+ end
12+ end
13+ end
14+
415local M = {}
516
17+ --- @class PythonImport.UserExtendLookupTable
18+ --- @field import string[] ?
19+ --- @field import_as table<string , string | vim.NIL> ?
20+ --- @field import_from table<string , string | vim.NIL> ?
21+ --- @field statement_after_imports table<string , string[] | vim.NIL> ?
22+
23+ --- @class PythonImport.UserConfig
24+ --- @field extend_lookup_table PythonImport.UserExtendLookupTable ?
25+ ---
26+ --- Return nil to indicate no match is found and continue with the default lookup
27+ --- Return a table to stop the lookup and use the returned table as the result
28+ --- Return an empty table to stop the lookup. This is useful when you want to add to wherever you need to.
29+ --- @field custom_function fun ( winnr : integer , word : string , ts_node : TSNode ?): string[] ? | nil
30+
631--- @param opts PythonImport.UserConfig
732function M .setup (opts )
833 -- NOTE: This may be called twice if you lazy load the plugin
@@ -25,6 +50,10 @@ function M.setup(opts)
2550 config .opts .extend_lookup_table .statement_after_imports
2651 )
2752
53+ remove_vim_nil (lookup_table .import_as )
54+ remove_vim_nil (lookup_table .import_from )
55+ remove_vim_nil (lookup_table .statement_after_imports )
56+
2857 -- make lookup table for faster lookup
2958 for _ , v in ipairs (lookup_table .import ) do
3059 lookup_table .is_import [v ] = true
0 commit comments