利用 LSP,Lsp配置,石匠,MasonLsp配置具有多种用于编程的语言服务器。
问题是 Neovim 无法访问这些服务器。它与 Packer 包管理器配合使用。也许我配置错误了,但我不知道问题可能是什么。
语言服务器已安装并添加到 PATH。
Spawning language server with cmd: `lua-language-server` failed with error message: EACCES: permission denied
这样的“lua-language-server”命令是可调用的。
我在用着鱼壳作为默认 shell。
这是我的插件配置文件:
return {
{ "lvimuser/lsp-inlayhints.nvim" },
{
"neovim/nvim-lspconfig",
dependencies = { "lvimuser/lsp-inlayhints.nvim" },
config = function()
local lspconfig = require("lspconfig")
lspconfig.gopls.setup({
on_attach = function(client, bufnr)
require("settings/shared").on_attach(client, bufnr)
require("lsp-inlayhints").setup({
inlay_hints = {
type_hints = {
prefix = "=> "
},
},
})
require("lsp-inlayhints").on_attach(client, bufnr)
require("illuminate").on_attach(client)
end,
settings = {
gopls = {
analyses = {
nilness = true,
unusedparams = true,
unusedwrite = true,
useany = true,
},
experimentalPostfixCompletions = true,
gofumpt = true,
staticcheck = true,
usePlaceholders = true,
hints = {
assignVariableTypes = true,
compositeLiteralFields = true,
compositeLiteralTypes = true,
constantValues = true,
functionTypeParameters = true,
parameterNames = true,
rangeVariableTypes = true,
}
},
},
})
end
},
{ "williamboman/mason.nvim" },
{ "Afourcat/treesitter-terraform-doc.nvim" },
{ "williamboman/mason-lspconfig.nvim",
dependencies = { "williamboman/mason.nvim" },
config = function()
local mason_lspconfig = require("mason-lspconfig")
mason_lspconfig.setup({
PATH = "prepend",
ensure_installed = {
"eslint",
"gopls", -- WARNING: This could be an issue with goenv switching.
"marksman",
"rust_analyzer",
"sumneko_lua",
"terraformls",
"tflint",
"tsserver",
"yamlls",
}
})
mason_lspconfig.setup_handlers({
function(server_name)
require("lspconfig")[server_name].setup({
on_attach = function(client, bufnr)
require("settings/shared").on_attach(client, bufnr)
require("illuminate").on_attach(client)
if server_name == "terraformls" then
require("treesitter-terraform-doc").setup()
end
end
})
end
})
end
},
{ "simrat39/symbols-outline.nvim",
config = function()
require("symbols-outline").setup({
-- autofold_depth = 1, -- h: close, l: open, W: close all, E: open all
auto_close = false,
highlight_hovered_item = true,
position = "left",
width = 15,
symbols = {
File = { icon = "", hl = "GruvboxAqua" }, -- TSURI
Module = { icon = "", hl = "GruvboxBlue" }, -- TSNamespace
Namespace = { icon = "", hl = "GruvboxBlue" }, -- TSNamespace
Package = { icon = "", hl = "GruvboxBlue" }, -- TSNamespace
Class = { icon = "
答案1
在我重启系统后,lsp-config 检测到了lua-language-server
。我猜是 PATH 没有被正确获取。
对于遇到类似问题的人 - 请确保已安装语言服务器并将其正确添加到 PATH,并且不要忘记使用变量来获取配置文件。
以下是fish shell 格式的lua-language-server
和服务器的变量:gopls
# Lua
set -gx PATH ~/.config/lsp/lua-language-server/bin $PATH
# Go
set -gx GOPATH ~/go
set -gx PATH /usr/local/go/bin $PATH
set -gx PATH $GOPATH/bin $PATH
它们的 bash 格式如下:
# Lua
export PATH=$PATH:$HOME/.config/lsp/lua-language-server/bin
# Go
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$GOPATH/bin