Skip to content

Commit

Permalink
fix: windows fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 3, 2024
1 parent f3cbedc commit f98d85a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lua/lazydev/buf.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local Config = require("lazydev.config")
local Lsp = require("lazydev.lsp")
local Pkg = require("lazydev.pkg")
local Util = require("lazydev.util")
local Workspace = require("lazydev.workspace")

local M = {}
Expand All @@ -12,7 +13,7 @@ M.attached = {}
M.modules = {}

function M.setup()
M.add(Config.runtime)
M.add(vim.uv.fs_stat(Config.runtime) and Config.runtime or vim.env.VIMRUNTIME)
for _, lib in pairs(Config.library) do
M.add(lib)
end
Expand Down Expand Up @@ -52,9 +53,9 @@ end
--- Automatically appends "/lua" if it exists.
---@param path string
function M.add(path)
path = vim.fs.normalize(path)
path = Util.norm(path)
-- try to resolve to a plugin path
if path:sub(1, 1) ~= "/" and not vim.uv.fs_stat(path) then
if not Util.is_absolute(path) and not vim.uv.fs_stat(path) then
local name, extra = path:match("([^/]+)(/?.*)")
if name then
local pp = Pkg.get_plugin_path(name)
Expand Down
1 change: 1 addition & 0 deletions lua/lazydev/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function M.attach(client)
return
end
M.attached[client.id] = client.id
Workspace.single(client):update()
---@param params lsp.ConfigurationParams
client.handlers["workspace/configuration"] = function(err, params, ctx, cfg)
if not params.items then
Expand Down
4 changes: 3 additions & 1 deletion lua/lazydev/pkg.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local Util = require("lazy.core.util")

---@class lazydev.Pkg
local M = {}

Expand Down Expand Up @@ -35,7 +37,7 @@ function M.pack_unloaded()
for _, site in pairs(sites) do
for _, pack in ipairs(vim.fn.expand(site .. "/pack/*/opt/*/lua", false, true)) do
if not pack:find("*", 1, true) then
packs[#packs + 1] = vim.fs.normalize(pack:sub(1, -5))
packs[#packs + 1] = Util.norm(pack:sub(1, -5))
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions lua/lazydev/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ function M.notify(msg, opts)
})
end

---@param path string
function M.is_absolute(path)
return path:sub(1, 1) == "/" or path:sub(2, 2) == ":"
end

---@param path string
function M.norm(path)
path = vim.fs.normalize(path)
-- Special case for Windows drive letters
-- vim.fs.normalize doesn't handle them correctly
if path:sub(2, 2) == ":" then
path = path:sub(1, 1):lower() .. path:sub(2)
end
return path
end

---@param msg string|string[]
---@param opts? NotifyOpts
function M.warn(msg, opts)
Expand Down
10 changes: 7 additions & 3 deletions lua/lazydev/workspace.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local Config = require("lazydev.config")
local Util = require("lazydev.util")

---@class lazydev.Workspace
---@field root string
Expand All @@ -13,6 +14,10 @@ M.GLOBAL = "global"
---@type table<string,lazydev.Workspace>
M.workspaces = {}

function M.is_special(root)
return root == M.SINGLE or root == M.GLOBAL
end

---@param client_id number
---@param root string
function M.new(client_id, root)
Expand All @@ -28,6 +33,7 @@ end
---@param client vim.lsp.Client|number
---@param root string
function M.get(client, root)
root = M.is_special(root) and root or Util.norm(root)
local client_id = type(client) == "number" and client or client.id
local id = client_id .. root
if not M.workspaces[id] then
Expand Down Expand Up @@ -127,10 +133,8 @@ function M:update()
end

function M:debug()
local Util = require("lazydev.util")
local Plugin = require("lazy.core.plugin")
local root = (self.root == M.GLOBAL or self.root == M.SINGLE) and "[" .. self.root .. "]"
or vim.fn.fnamemodify(self.root, ":~")
local root = M.is_special(self.root) and "[" .. self.root .. "]" or vim.fn.fnamemodify(self.root, ":~")
local lines = { "## " .. root }
---@type string[]
local library = vim.tbl_get(self.settings, "Lua", "workspace", "library") or {}
Expand Down

0 comments on commit f98d85a

Please sign in to comment.