first commit

This commit is contained in:
game-loader
2022-10-06 17:40:06 +08:00
commit 42dda177d6
26 changed files with 1236 additions and 0 deletions

67
lua/lsp/cmp.lua Normal file
View File

@ -0,0 +1,67 @@
local lspkind = require('lspkind')
local cmp = require'cmp'
cmp.setup {
-- 指定 snippet 引擎
snippet = {
expand = function(args)
-- For `vsnip` users.
vim.fn["vsnip#anonymous"](args.body)
-- For `luasnip` users.
-- require('luasnip').lsp_expand(args.body)
-- For `ultisnips` users.
-- vim.fn["UltiSnips#Anon"](args.body)
-- For `snippy` users.
-- require'snippy'.expand_snippet(args.body)
end,
},
-- 来源
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- For vsnip users.
{ name = 'vsnip' },
-- For luasnip users.
-- { name = 'luasnip' },
--For ultisnips users.
-- { name = 'ultisnips' },
-- -- For snippy users.
-- { name = 'snippy' },
}, { { name = 'buffer' },
{ name = 'path' }
}),
-- 快捷键
mapping = require('keybindings').cmp(cmp),
-- 使用lspkind-nvim显示类型图标
formatting = {
format = lspkind.cmp_format({
with_text = true, -- do not show text alongside icons
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
before = function (entry, vim_item)
-- Source 显示提示来源
vim_item.menu = "["..string.upper(entry.source.name).."]"
return vim_item
end
})
},
}
-- Use buffer source for `/`.
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':'.
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})

21
lua/lsp/config/clangd.lua Normal file
View File

@ -0,0 +1,21 @@
return {
on_setup = function(server)
server.setup({
flags = {
debounce_text_changes = 150,
},
on_attach = function(client, bufnr)
-- 禁用格式化功能,交给专门插件插件处理
client.server_capabilities.document_formatting = false
client.server_capabilities.document_range_formatting = false
-- local function buf_set_keymap(...)
-- vim.api.nvim_buf_set_keymap(bufnr, ...)
-- end
-- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- 绑定快捷键
-- require("keybindings").mapLSP(buf_set_keymap)
end,
})
end,
}

59
lua/lsp/config/lua.lua Normal file
View File

@ -0,0 +1,59 @@
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
local opts = {
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 = runtime_path,
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { "vim" },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
},
},
flags = {
debounce_text_changes = 150,
},
on_attach = function(client, bufnr)
-- 禁用格式化功能,交给专门插件插件处理
client.server_capabilities.document_formatting = false
client.server_capabilities.document_range_formatting = false
-- local function buf_set_keymap(...)
-- vim.api.nvim_buf_set_keymap(bufnr, ...)
end
-- -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- -- 绑定快捷键
-- require("keybindings").mapLSP(buf_set_keymap)
-- end,
}
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
opts.capabilities = capabilities
-- 查看目录等信息
-- print(vim.inspect(server))
return {
on_setup = function(server)
-- opts = require("lua-dev").setup({ lspconfig = opts })
server.setup(opts)
end,
}

View File

@ -0,0 +1,21 @@
return {
on_setup = function(server)
server.setup({
flags = {
debounce_text_changes = 150,
},
on_attach = function(client, bufnr)
-- 禁用格式化功能,交给专门插件插件处理
client.server_capabilities.document_formatting = false
client.server_capabilities.document_range_formatting = false
-- local function buf_set_keymap(...)
-- vim.api.nvim_buf_set_keymap(bufnr, ...)
-- end
-- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- 绑定快捷键
-- require("keybindings").mapLSP(buf_set_keymap)
end,
})
end,
}

30
lua/lsp/init.lua Normal file
View File

@ -0,0 +1,30 @@
local lspconfig = require("lspconfig")
-- 安装列表
-- { key: 服务器名, value: 配置文件 }
-- key 必须为下列网址列出的 server name不可以随便写
-- https://github.com/williamboman/nvim-lsp-installer#available-lsps
local servers = {
sumneko_lua = require("lsp.config.lua"), -- lua/lsp/config/lua.lua
clangd = require("lsp.config.clangd"),
-- bashls = require("lsp.config.bash"),
pyright = require("lsp.config.pyright"),
-- html = require("lsp.config.html"),
-- cssls = require("lsp.config.css"),
-- emmet_ls = require("lsp.config.emmet"),
-- jsonls = require("lsp.config.json"),
-- tsserver = require("lsp.config.ts"),
-- rust_analyzer = require("lsp.config.rust"),
-- yamlls = require("lsp.config.yamlls"),
-- remark_ls = require("lsp.config.markdown"),
}
for name, config in pairs(servers) do
if config ~= nil and type(config) == "table" then
-- 自定义初始化配置文件必须实现on_setup 方法
config.on_setup(lspconfig[name])
else
-- 使用默认参数
lspconfig[name].setup({})
end
end