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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
-- See `:help vim.diagnostic.*` for documentation on any of the below functiolocal opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
vim.lsp.set_log_level("info")
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, "formatexpr", "v:lua.vim.lsp.formatexpr()")
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
vim.api.nvim_buf_set_option(bufnr, "tagfunc", "v:lua.vim.lsp.tagfunc")
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set('n', 'gk', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', '<leader><leader>', vim.lsp.buf.hover, bufopts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
-- disable lsp highlighting
-- client.server_capabilities.semanticTokensProvider = nil
end
-- Setup buffer-local keymaps / options for LSP buffers
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Setup rust_analyzer via rust-tools.nvim
require("rust-tools").setup({
server = {
capabilities = capabilities,
on_attach = on_attach,
settings = {
['rust-analyzer'] = {
cargo = {
features = "all"
}
}
}
}
})
-- https://github.com/ray-x/go.nvim#lsp-cmp-support
require('go').setup({
lsp_cfg = {
capabilities = capabilities,
on_attach = on_attach
}
})
local lspconfig = require('lspconfig')
lspconfig.zls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.bashls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
lspconfig.vimls.setup({
on_attach = on_attach,
capabilities = capabilities,
})
require 'lspconfig'.sqlls.setup({
server = {
on_attach = on_attach,
}
})
-- https://github.com/nikeee/dot-language-server
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#dotls
lspconfig['dotls'].setup({
capabilities = capabilities,
on_attach = on_attach,
})
lspconfig.yamlls.setup {
settings = {
yaml = {
-- FIX mapKeyOrder warning
keyOrdering = false,
},
}
}
lspconfig.lua_ls.setup {
on_attach = on_attach,
capabilities = capabilities,
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.sqls.setup {
on_attach = function(client, bufnr)
require('sqls').on_attach(client, bufnr)
end,
sqls = {
connections = {
{
driver = 'sqlite3',
dataSourceName = '/home/algo/test.sqlite3',
},
},
},
}
vim.api.nvim_create_autocmd('BufWritePre', {
pattern = '*.go',
callback = function()
vim.lsp.buf.code_action({ context = { only = { 'source.organizeImports' } }, apply = true })
end
})
|