From c549be2af16e9c5c10f09d7d47b10a1e219d6563 Mon Sep 17 00:00:00 2001 From: TrungNguyen153 <41288282+TrungNguyen153@users.noreply.github.com> Date: Mon, 15 Jan 2024 04:11:04 +0700 Subject: [PATCH] fix(lsp): normalize case sensitive `root_dir` on Windows (#152) Co-authored-by: TrungNguyen153 <> Co-authored-by: Marc Jakobi --- lua/rustaceanvim/lsp.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lua/rustaceanvim/lsp.lua b/lua/rustaceanvim/lsp.lua index 9297d7c2..c06b87f9 100644 --- a/lua/rustaceanvim/lsp.lua +++ b/lua/rustaceanvim/lsp.lua @@ -97,6 +97,19 @@ local function is_in_workspace(client, root_dir) return false end +---Normalize path for Windows, which is case insensitive +---@param path string +---@return string normalize_path +local function normalize_path(path) + if require('rustaceanvim.shell').is_windows() then + local has_windows_drive_letter = path:match('^%a:') + if has_windows_drive_letter then + return path:sub(1, 1):lower() .. path:sub(2) + end + end + return path +end + --- Start or attach the LSP client ---@param bufnr? number The buffer number (optional), defaults to the current buffer ---@return integer|nil client_id The LSP client ID @@ -106,6 +119,7 @@ M.start = function(bufnr) ---@type RustaceanLspClientConfig local lsp_start_opts = vim.tbl_deep_extend('force', {}, client_config) local root_dir = get_root_dir(vim.api.nvim_buf_get_name(bufnr)) + root_dir = root_dir and normalize_path(root_dir) lsp_start_opts.root_dir = root_dir local settings = client_config.settings