Skip to content

Commit

Permalink
Improve pipenv open completions.
Browse files Browse the repository at this point in the history
- Fix bug that collected lib dir names, instead of their contents,
  resulting in never having any completions at all.
- Fix bug that converted "foo.pyro.py" to "fooro".
  • Loading branch information
chrisant996 committed Jul 4, 2024
1 parent 40ab322 commit ddb8a4d
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions pipenv.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
local matchers = require("matchers")
local w = require("tables").wrap
local concat = require("funclib").concat

local parser = clink.arg.new_parser

local function pipenv_libs_list(token)
local handle = io.popen('python -c "import sys; print(\\";\\".join(sys.path))"')
local result = handle:read("*a")
handle:close()
local result = ""
local handle = io.popen('2>nul python -c "import sys; print(\\";\\".join(sys.path))"')
if handle then
result = handle:read("*a")
handle:close()
end

-- trim spaces
result = clink.get_cwd() .. result:gsub("^%s*(.-)%s*$", "%1")
Expand All @@ -16,21 +18,24 @@ local function pipenv_libs_list(token)

local list = w()
for _,lib_path in ipairs(lib_paths) do
local finder = matchers.create_files_matcher(lib_path)
lib_path = lib_path .. "\\"
local finder = matchers.create_files_matcher(lib_path .. "*")
local libs = finder(token)
libs =
libs:filter(
function(v)
return clink.is_dir(lib_path .. "/" .. v) or string.find(v, "%.py$")
for _,v in ipairs(libs) do
local ext = path.getextension(v):lower()
if ext == ".py" then
v = v:sub(1, #v - #ext)
table.insert(list, v)
elseif ext == ".dist-info" then
if clink.is_dir(lib_path .. "/" .. v) then
local tmp = v:sub(1, #v - #ext)
if tmp:match("%-%d[%d%.]+$") then
v = tmp:gsub("%-%d[%d%.]+$", "")
table.insert(list, v)
end
end
end
)

list = w(concat(list, libs))
end

-- remove ".py" and "-1.2.3-dist-info" of file name
for k, v in pairs(list) do
list[k] = v:gsub(".py", ""):gsub("-[%d%.]+dist%-info$", "")
end
end

return list
Expand Down

0 comments on commit ddb8a4d

Please sign in to comment.