Closed CoolPlayLin closed 9 months ago
could you run :LspInfo
? and try the min config which provide by lspconfig.
vuels or tsserver on this buffer? i think you should provide more
all configs
local lspconfig_status, lspconfig = pcall(require, "lspconfig")
if not lspconfig_status then
return
end
local keymap = vim.keymap
local capabilities = vim.lsp.protocol.make_client_capabilities()
local on_attach = function(client, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
-- set keybinds
keymap.set("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) -- got to declaration
keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) -- go to implementation
keymap.set("n", "<leader>o", "<cmd>LSoutlineToggle<CR>", opts) -- see outline on right hand side
-- lspsaga
keymap.set("n", "gf", "<cmd>Lspsaga lsp_finder<CR>", opts) -- show definition, references
keymap.set("n", "gd", "<cmd>Lspsaga peek_definition<CR>", opts) -- see definition and make edits in window
keymap.set("n", "gp", "<cmd>Lspsaga preview_definition<CR>", opts)
keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts) -- see available code actions
keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts) -- smart rename
keymap.set("n", "<leader>D", "<cmd>Lspsaga show_line_diagnostics<CR>", opts) -- show diagnostics for line
keymap.set("n", "<leader>d", "<cmd>Lspsaga show_cursor_diagnostics<CR>", opts) -- show diagnostics for cursor
keymap.set("n", "[d", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opts) -- jump to previous diagnostic in buffer
keymap.set("n", "]d", "<cmd>Lspsaga diagnostic_jump_next<CR>", opts) -- jump to next diagnostic in buffer
keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", opts) -- show documentation for what is under cursor
keymap.set("n", "<C-k>", "<cmd>Lspsaga signature_help<CR>", opts)
-- typescript specific keymaps (e.g. rename file and update imports)
if client.name == "tsserver" then
keymap.set("n", "<leader>rf", ":TypescriptRenameFile<CR>") -- rename file and update imports
keymap.set("n", "<leader>oi", ":TypescriptOrganizeImports<CR>") -- organize imports (not in youtube nvim video)
keymap.set("n", "<leader>ru", ":TypescriptRemoveUnused<CR>") -- remove unused variables (not in youtube nvim video)
end
if client.name == "eslint" then
vim.api.nvim_create_autocmd(
"BufWritePre",
{
buffer = bufnr,
command = "EslintFixAll"
})
end
end
capabilities.textDocument.completion.completionItem.snippetSupport = true
lspconfig.yamlls.setup({})
lspconfig.jsonls.setup({})
lspconfig.html.setup({})
lspconfig.tailwindcss.setup({})
lspconfig.cssls.setup({})
lspconfig.pyright.setup(
{
settings = {
python = {
analysis = {
typeCheckingMode = "basic",
autoSearchPaths = true,
useLibraryCodeForTypes = true
}
}
}
}
)
lspconfig.cssls.setup(
{
capabilities = capabilities
}
)
--Enable (broadcasting) snippet capability for completion
lspconfig.html.setup(
{
capabilities = capabilities
}
)
lspconfig.eslint.setup(
{
on_attach = on_attach
}
)
-- lua
lspconfig.lua_ls.setup ({
on_attach = on_attach,
on_init = function(client)
local path = client.workspace_folders[1].name
if not vim.loop.fs_stat(path..'/.luarc.json') and not vim.loop.fs_stat(path..'/.luarc.jsonc') then
client.config.settings = vim.tbl_deep_extend('force', client.config.settings, {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
}
})
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
end
return true
end
})
lspconfig.vuels.setup ({
on_attach = on_attach,
filetypes = {"typescript", "javascript", "javascriptreact", "typescriptreact", "vue", "json"}
})
lspconfig.denols.setup ({
on_attach = on_attach,
root_dir = lspconfig.util.root_pattern("deno.json", "deno.jsonc")
})
lspconfig.tsserver.setup ({
on_attach = on_attach,
root_dir = lspconfig.util.root_pattern("tsconfig.json", "package.json", "jsconfig.json", ".git"),
single_file_support = true,
filetypes = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx" }
})
lspconfig.powershell_es.setup ({
on_attach = on_attach,
bundle_path = vim.env.PowerShellEditorServices,
shell = "pwsh.exe"
})
scroll on lspinfo buffer . i wonder the root of vuels and tsserver , i guess it from vuels?
@glepnir No, it is actually tssever's error message I deleted the vue's config but it still shows
root is correct ? if true i think it work as expect.
How to ensure root is correct?
emmm...where is your project root folder? and disable the eslint server , this error message still shown ?
好像确实是 eslint 的问题
config your eslitrc.js
Description
When I edit file which is not in the folder where is the tsconfig.json, it shows cannot read file in folder of current file But it runs normally in folder where is the tsconfig.json
Neovim version
NVIM v0.9.5 Build type: RelWithDebInfo LuaJIT 2.1.1703942320 Compilation: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe /MD /Zi /O2 /Ob1 -W3 -wd4311 -wd4146 -DUNIT_TESTING -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0602 -DMSWIN -DINCLUDE_GENERATED_DECLARATIONS -ID:/a/neovim/neovim/.deps/usr/include/luajit-2.1 -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/build/src/nvim/auto -ID:/a/neovim/neovim/build/include -ID:/a/neovim/neovim/build/cmake.config -ID:/a/neovim/neovim/src -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include
system vimrc file: "$VIM\sysinit.vim" fall-back for $VIM: "C:/Program Files (x86)/nvim/share/nvim"
Run :checkhealth for more info
Nvim-lspconfig version
latest
Operating system and version
Windows11 23H2
Affected language servers
eslint
Steps to reproduce
Open the file which is not in folder where is tsconfig.json
Actual behavior
Runs normally just like this
Expected behavior
Shows
cannot read file in [current file's folder\tsconfig.json]
Minimal config
LSP log