Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

- Windows: Normalize file actions when comparing to root dir [#245]

## [4.7.5] - 2024-02-20

### Fixed
Expand Down
16 changes: 2 additions & 14 deletions lua/rustaceanvim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local types = require('rustaceanvim.types.internal')
local rust_analyzer = require('rustaceanvim.rust_analyzer')
local server_status = require('rustaceanvim.server_status')
local cargo = require('rustaceanvim.cargo')
local os = require('rustaceanvim.os')

local function override_apply_text_edits()
local old_func = vim.lsp.util.apply_text_edits
Expand Down Expand Up @@ -34,19 +35,6 @@ 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

---@class LspStartConfig: RustaceanLspClientConfig
---@field root_dir string | nil
---@field init_options? table
Expand All @@ -69,7 +57,7 @@ M.start = function(bufnr)
---@type LspStartConfig
local lsp_start_config = vim.tbl_deep_extend('force', {}, client_config)
local root_dir = cargo.get_root_dir(vim.api.nvim_buf_get_name(bufnr))
root_dir = root_dir and normalize_path(root_dir)
root_dir = root_dir and os.normalize_path(root_dir)
lsp_start_config.root_dir = root_dir
if not root_dir then
--- No project root found. Start in detached/standalone mode.
Expand Down
10 changes: 10 additions & 0 deletions lua/rustaceanvim/os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ function os.open_url(url)
end
end

---Normalize path for Windows, which is case insensitive
---@param path string
---@return string normalize_path
function os.normalize_path(path)
if require('rustaceanvim.shell').is_windows() then
return path:lower()
end
return path
end

return os
3 changes: 2 additions & 1 deletion lua/rustaceanvim/rust_analyzer.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---@mod rustaceanvim.rust_analyzer Functions for interacting with rust-analyzer

local compat = require('rustaceanvim.compat')
local os = require('rustaceanvim.os')

---@class RustAnalyzerClientAdapter
local M = {}
Expand Down Expand Up @@ -74,7 +75,7 @@ M.file_request = function(file_path, method, params, handler)
local client_found = false
for _, client in ipairs(M.get_active_rustaceanvim_clients(nil, { method = method })) do
local root_dir = client.config.root_dir
if root_dir and vim.startswith(file_path, root_dir) then
if root_dir and vim.startswith(os.normalize_path(file_path), root_dir) then
local bufnr = find_buffer_by_name(file_path)
if not params then
params = {
Expand Down