williamboman / mason-lspconfig.nvim

Extension to mason.nvim that makes it easier to use lspconfig with mason.nvim.
Apache License 2.0
2.59k stars 156 forks source link

Same configuration, but not the same behavior in Windows and Linux: Spawning language server with cmd: clangd failed. #139

Open qujihan opened 1 year ago

qujihan commented 1 year ago

Problem description

Spawning language server with cmd: clangd failed. The language server is either not installed, missing from PATH, or not executable. The same configuration works fine under ArchLinux(wsl), but not under Windows

Why do you think this is an issue with mason-lspconfig.nvim?

I'm not sure if it's Mason's problem, but I wondered if there was a problem with the download

Neovim version (>= 0.7)

windows:NVIM v0.8.2 archlinux(wsl):NVIM v0.8.2

Operating system/version

windows:windows 11 /archlinux :Linux 9a3b81476179 5.10.16.3-microsoft-standard-WSL2 #1 SMP Fri Apr 2 22:23:49 UTC 2021 x86_64 GNU/Linux

I've manually reviewed the Nvim LPS client log (:LspLog) to find potential errors

I've recently downloaded the latest plugin version of mason.nvim, mason-lspconfig.nvim, and nvim-lspconfig

Affected language servers

clangd

Steps to reproduce

  1. add init.lua
    
    -- https://github.com/folke/lazy.nvim

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", -- latest stable release lazypath, }) end

vim.opt.rtp:prepend(lazypath)

require("lazy").setup( { { "williamboman/mason.nvim", config = function() require("mason").setup {} end }, { "williamboman/mason-lspconfig.nvim", config = function() require("mason-lspconfig").setup { ensure_installed = { "clangd" }, automatic_installation = true, } end }, { "neovim/nvim-lspconfig", config = function() require("lspconfig")['clangd'].setup {} end }, } )


2. nvim demo.cpp

### Actual behavior

![image](https://user-images.githubusercontent.com/43026824/214762223-5b56f415-5ad3-4af6-a08d-b8496e14a6f6.png)

### Expected behavior

On Windows can be consistent with Linux

### LspInfo

```Text
Press q or <Esc> to close this window. Press <Tab> to view server doc.

 Language client log: C:\Users\Qu\AppData\Local\nvim-data\lsp.log
 Detected filetype:   cpp

 0 client(s) attached to this buffer: 

 Other clients that match the filetype: cpp

 Config: clangd
    Refer to :h lspconfig-root-detection for help.
    filetypes:         c, cpp, objc, objcpp, cuda, proto
    root directory:    Not found.
    cmd:               clangd
    cmd is executable: true
    autostart:         true
    custom handlers:   

 Configured servers list: clangd

LspLog

No response

Healthcheck

mason: require("mason.health").check()
========================================================================
## mason.nvim report
  - OK: neovim version >= 0.7.0
  - OK: **Go**: `go version go1.19.5 windows/amd64`
  - OK: **cargo**: `cargo 1.66.0 (d65d197ad 2022-11-15)`
  - WARNING: **luarocks**: not available
  - WARNING: **Ruby**: not available
  - WARNING: **RubyGem**: not available
  - WARNING: **Composer**: not available
  - WARNING: **PHP**: not available
  - ERROR: **npm**: not available
  - ERROR: **node**: not available
  - OK: **python3**: `Python 3.11.1
`
  - OK: **pip3**: `pip 22.3.1 from C:\Scoop\apps\python\current\Lib\site-packages\pip (python 3.11)

`
  - OK: **javac**: `javac 19.0.1
`
  - OK: **java**: `openjdk version "19.0.1" 2022-10-18
`
  - WARNING: **julia**: not available
  - ERROR: **wget**: not available
  - OK: **curl**: `curl 7.83.1 (Windows) libcurl/7.83.1 Schannel
`
  - WARNING: **gzip**: not available
  - OK: **tar**: `bsdtar 3.5.2 - libarchive 3.5.2 zlib/1.2.5.f-ipp bz2lib/1.0.6 
`
  - ERROR: **pwsh**: not available
  - OK: **python**: `Python 3.11.1
`
  - OK: **pip**: `pip 22.3.1 from C:\Scoop\apps\python\current\Lib\site-packages\pip (python 3.11)

`
  - OK: **7z**: `7-Zip 22.01 (x64) : Copyright (c) 1999-2022 Igor Pavlov : 2022-07-15
`
  - ERROR: GitHub API rate limit exceeded. Used: 60. Remaining: 0. Limit: 60. Reset: 2023/1/26 13:44:51.

Screenshots or recordings

No response

williamboman commented 1 year ago

Hey! This is probably happening because the config hook for lspconfig executes before Mason. You need to ensure that Mason is set up before lspconfig.

nerditation commented 1 year ago

I had the same issue with rust-analyzer, and I figured out that mason installs binary packages and put a wrapper shell script into a single bin directory, in this way it would only need to add one entry to the PATH environment variable. in my case, it is named rust-analyzer.cmd. this is usually fine, so long you run this command through a shell, as the .cmd suffix is recognized by the Windows shell. e.g. :lua =vim.fn.system 'rust-analyzer --version' would give me the correct version, and I can type rust-analyzer --version directly into a nvim terminal too. I guess the lsp integration somehow trys to spawn a process directly from this command name, which it can't and hence the error.

in my case, I solved it by manually set the server cmd like so:

-- pass nil will use default setting
local cmd = nil
if jit.os == 'Windows' then
    cmd = { 'cmd.exe', '/c', 'rust-analyzer' }
end
require 'lspconfig'.rust_analyzer.setup {
    cmd = cmd,
}

ps1: my lua_ls works out of the box, but rust-analyzer doesn't

ps1: I am not sure my problem is caused by setup order, as I have my setup code explictly specifying mason-lspconfig should load after mason.nvim:

packer.use {
    'williamboman/mason.nvim' ,
    config = function() require 'mason'.setup {} end,
}
packer.use {
    'williamboman/mason-lspconfig.nvim',
    requires = { 'williamboman/mason.nvim', 'neovim/nvim-lspconfig', },
    after = { 'mason.nvim', },
    config = function() require 'mason-lspconfig'setup {} end,
}
packer.use {
    'neovim/nvim-lspconfig',
    after = { 'mason-lspconfig.nvim', },
    config = function()
        local lsconfig = require 'lspconfig'
        -- server settings omitted
    end,
}
holiq commented 4 months ago

I got some error like this

Spawning language server with cmd: /data/data/com.termux/files/home/.local/share/nvim/mason/bin/intelephense failed. The language server is either not installed, missing from PATH, or not executable.

I use AstroNvim, it works on Linux Ubuntu, but it doesn't work Termux(latest build, android 14), if I run $ intelphense it show the script and I think it executable

So how to fix it?