Skip to content

Commit

Permalink
fix(lsp): implement vim.fs.joinpath for nvim 0.9 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Oct 22, 2023
1 parent 507593f commit 62f7ac2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Add support for `workspace/didChangeWorkspaceFolders` to prevent more than one
rust-analyzer server from spawning per Neovim instance [#7](https://github.com/mrcjkb/rustaceanvim/issues/7).
- Implement `vim.fs.joinpath` for Neovim 0.9 compatibility.

## [3.0.0] - 2023-10-22

Expand Down
14 changes: 9 additions & 5 deletions lua/rustaceanvim/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ local M = {}
local config = require('rustaceanvim.config.internal')
local methods = require('vim.lsp.protocol').Methods

local joinpath = vim.fs.joinpath or function(...)
return (table.concat({ ... }, '/'):gsub('//+', '/'))
end

local function override_apply_text_edits()
local old_func = vim.lsp.util.apply_text_edits
---@diagnostic disable-next-line
Expand All @@ -14,11 +18,11 @@ local function override_apply_text_edits()
end

local function is_library(fname)
local cargo_home = os.getenv('CARGO_HOME') or vim.fs.joinpath(vim.env.HOME, '.cargo')
local registry = vim.fs.joinpath(cargo_home, 'registry', 'src')
local cargo_home = os.getenv('CARGO_HOME') or joinpath(vim.env.HOME, '.cargo')
local registry = joinpath(cargo_home, 'registry', 'src')

local rustup_home = os.getenv('RUSTUP_HOME') or vim.fs.joinpath(vim.env.HOME, '.rustup')
local toolchains = vim.fs.joinpath(rustup_home, 'toolchains')
local rustup_home = os.getenv('RUSTUP_HOME') or joinpath(vim.env.HOME, '.rustup')
local toolchains = joinpath(rustup_home, 'toolchains')

for _, item in ipairs { toolchains, registry } do
if fname:sub(1, #item) == item then
Expand All @@ -44,7 +48,7 @@ local function get_root_dir(fname)
local cmd = { 'cargo', 'metadata', '--no-deps', '--format-version', '1' }
if cargo_crate_dir ~= nil then
cmd[#cmd + 1] = '--manifest-path'
cmd[#cmd + 1] = vim.fs.joinpath(cargo_crate_dir, 'Cargo.toml')
cmd[#cmd + 1] = joinpath(cargo_crate_dir, 'Cargo.toml')
end
local cargo_metadata = ''
local cm = vim.fn.jobstart(cmd, {
Expand Down

0 comments on commit 62f7ac2

Please sign in to comment.