1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
--plugin-nvim-lspconfig.lua
return {
{
"neovim/nvim-lspconfig",
lazy = false,
config = function()
vim.lsp.set_log_level("debug")
local nvim_lsp = require('lspconfig')
nvim_lsp.clangd.setup({
enure_installed = { "lua_ls"},
--cmd = {
-- "clangd",
-- --"--query-driver=*arm-none-eabi*",
-- -- NOTE:使用如下绝对路径时反而无效
-- -- "--query-driver=${path_to_compiler}\\gcc-arm-none-eabi\\12.2.rel1\\bin\\arm-none-eabi*",
--},
cmd = { "clangd", "--log=verbose"},
-- 将标准输出和标准错误重定向到日志文件
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
-- 可选:配置 `on_attach` 函数来绑定 LSP 功能
on_attach = function(client, bufnr)
-- 绑定快捷键
local buf_set_keymap = vim.api.nvim_buf_set_keymap
local opts = { noremap=true, silent=true }
-- 跳转到声明
-- buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
-- buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
-- 绑定跳转到定义
--buf_set_keymap(bufnr, 'n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap(bufnr, 'n', 'gD', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
-- 绑定查找所有引用
buf_set_keymap(bufnr, 'n', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
-- 绑定显示悬停信息
buf_set_keymap(bufnr, 'n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
-- 跳转到实现
buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
-- 以浮窗形式显示错误
buf_set_keymap(bufnr, "n", "go", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
buf_set_keymap(bufnr, "n", "gp", "<cmd>lua vim.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap(bufnr, "n", "gn", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)
buf_set_keymap(bufnr, "n", "gq", "<cmd>lua vim.diagnostic.setqflist()<CR>", opts)
buf_set_keymap(bufnr, "n", "ge", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
end,
})
nvim_lsp.lua_ls.setup({
cmd = {'lua-language-server'};
settings = {
--settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
-- Setup your lua path
path = vim.split(package.path, ';'),
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'},
},
--workspace = {
-- -- Make the server aware of Neovim runtime files
-- library = {
-- [vim.fn.expand('$VIMRUNTIME/lua')] = true,
-- [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
-- },
--},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
--}
},
-- 定义快捷键
-- 根据官方的提示,这里我们使用 on_attach 表示当前缓冲加载服务端完成之后调用
on_attach = function(client, bufnr)
-- 跳转到声明
--vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.declaration()<CR>", {silent = true, noremap = true})
vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", {silent = true, noremap = true})
-- 跳转到定义
--vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.definition()<CR>", {silent = true, noremap = true})
vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", {silent = true, noremap = true})
-- 显示注释文档
vim.api.nvim_buf_set_keymap(bufnr, "n", "gh", "<cmd>lua vim.lsp.buf.hover()<CR>", {silent = true, noremap = true})
-- 跳转到实现
vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", {silent = true, noremap = true})
-- 跳转到引用位置
vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", {silent = true, noremap = true})
-- 以浮窗形式显示错误
vim.api.nvim_buf_set_keymap(bufnr, "n", "go", "<cmd>lua vim.diagnostic.open_float()<CR>", {silent = true, noremap = true})
vim.api.nvim_buf_set_keymap(bufnr, "n", "gp", "<cmd>lua vim.diagnostic.goto_prev()<CR>", {silent = true, noremap = true})
vim.api.nvim_buf_set_keymap(bufnr, "n", "gn", "<cmd>lua vim.diagnostic.goto_next()<CR>", {silent = true, noremap = true})
end
})
--gopls for go
nvim_lsp.gopls.setup({
cmd = {'gopls'};
--settings = {
-- gopls = {
-- --ui = {
-- -- completion = {
-- -- usePlaceholders = true,
-- -- },
-- --},
-- },
--}
})
end
}
}
|