Skip to content

Commit 9b911c7

Browse files
committed
inital commit
0 parents  commit 9b911c7

17 files changed

+631
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.local
2+
.cache
3+
.config
4+
nvim/plugin

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Minimal Neovim Rust Configuration
2+
3+
## To test
4+
5+
If you wish to test this out, check out this repo and run the following command
6+
7+
```
8+
cd nvim-rust
9+
NVIM_CONFIG_HOME=`pwd` XDG_CONFIG_HOME=$NVIM_CONFIG_HOME XDG_DATA_HOME=$NVIM_CONFIG_HOME/.local/share XDG_CACHE_HOME=$NVIM_CONFIG_HOME/.cache XDG_STATE_HOME=$NVIM_CONFIG_HOME/.local/state nvim +PackerSync
10+
```
11+
12+
This will install all the plugins listed in `nvim/lua/config/plugins.lua`.
13+
14+
If you close and reopen Neovim, it should then start to install all the Treesitter and Mason tooling for you automatically. If it doesn't you can install what you need with `:Mason` and `:TSInstall`.

nvim/init.lua

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "config.plugins"
2+
require "config.colorscheme"
3+
require "config.cmp"
4+
require "config.treesitter"
5+
require "config.lsp"
6+
require "config.rust"
7+
require "config.crates"

nvim/lua/config/.nvimlog

Whitespace-only changes.

nvim/lua/config/cmp.lua

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
local cmp_status_ok, cmp = pcall(require, "cmp")
2+
if not cmp_status_ok then
3+
return
4+
end
5+
6+
local snip_status_ok, luasnip = pcall(require, "luasnip")
7+
if not snip_status_ok then
8+
return
9+
end
10+
11+
require("luasnip/loaders/from_vscode").lazy_load()
12+
13+
local check_backspace = function()
14+
local col = vim.fn.col "." - 1
15+
return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
16+
end
17+
18+
--   פּ ﯟ   some other good icons
19+
local kind_icons = {
20+
Text = "",
21+
Method = "m",
22+
Function = "",
23+
Constructor = "",
24+
Field = "",
25+
Variable = "",
26+
Class = "",
27+
Interface = "",
28+
Module = "",
29+
Property = "",
30+
Unit = "",
31+
Value = "",
32+
Enum = "",
33+
Keyword = "",
34+
Snippet = "",
35+
Color = "",
36+
File = "",
37+
Reference = "",
38+
Folder = "",
39+
EnumMember = "",
40+
Constant = "",
41+
Struct = "",
42+
Event = "",
43+
Operator = "",
44+
TypeParameter = "",
45+
}
46+
-- find more here: https://www.nerdfonts.com/cheat-sheet
47+
48+
cmp.setup {
49+
snippet = {
50+
expand = function(args)
51+
luasnip.lsp_expand(args.body) -- For `luasnip` users.
52+
end,
53+
},
54+
mapping = {
55+
["<C-k>"] = cmp.mapping.select_prev_item(),
56+
["<C-j>"] = cmp.mapping.select_next_item(),
57+
["<C-b>"] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }),
58+
["<C-f>"] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }),
59+
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
60+
["<C-y>"] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
61+
["<C-e>"] = cmp.mapping {
62+
i = cmp.mapping.abort(),
63+
c = cmp.mapping.close(),
64+
},
65+
-- Accept currently selected item. If none selected, `select` first item.
66+
-- Set `select` to `false` to only confirm explicitly selected items.
67+
["<CR>"] = cmp.mapping.confirm { select = true },
68+
["<Tab>"] = cmp.mapping(function(fallback)
69+
if cmp.visible() then
70+
cmp.select_next_item()
71+
elseif luasnip.expandable() then
72+
luasnip.expand()
73+
elseif luasnip.expand_or_jumpable() then
74+
luasnip.expand_or_jump()
75+
elseif check_backspace() then
76+
fallback()
77+
else
78+
fallback()
79+
end
80+
end, {
81+
"i",
82+
"s",
83+
}),
84+
["<S-Tab>"] = cmp.mapping(function(fallback)
85+
if cmp.visible() then
86+
cmp.select_prev_item()
87+
elseif luasnip.jumpable(-1) then
88+
luasnip.jump(-1)
89+
else
90+
fallback()
91+
end
92+
end, {
93+
"i",
94+
"s",
95+
}),
96+
},
97+
formatting = {
98+
fields = { "kind", "abbr", "menu" },
99+
format = function(entry, vim_item)
100+
-- Kind icons
101+
vim_item.kind = string.format("%s", kind_icons[vim_item.kind])
102+
-- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind
103+
vim_item.menu = ({
104+
nvim_lsp = "[LSP]",
105+
luasnip = "[Snippet]",
106+
buffer = "[Buffer]",
107+
path = "[Path]",
108+
})[entry.source.name]
109+
return vim_item
110+
end,
111+
},
112+
sources = {
113+
{ name = "nvim_lsp" },
114+
{ name = "luasnip" },
115+
{ name = "buffer" },
116+
{ name = "path" },
117+
},
118+
confirm_opts = {
119+
behavior = cmp.ConfirmBehavior.Replace,
120+
select = false,
121+
},
122+
window = {
123+
documentation = {
124+
border = { "", "", "", "", "", "", "", "" },
125+
},
126+
},
127+
experimental = {
128+
ghost_text = false,
129+
native_menu = false,
130+
},
131+
}

nvim/lua/config/colorscheme.lua

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local colorscheme = "tokyonight"
2+
3+
local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme)
4+
if not status_ok then
5+
return
6+
end

nvim/lua/config/crates.lua

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local status_ok, crates = pcall(require, "crates")
2+
if not status_ok then
3+
return
4+
end
5+
6+
crates.setup {
7+
popup = {
8+
-- autofocus = true,
9+
style = "minimal",
10+
border = "rounded",
11+
show_version_date = false,
12+
show_dependency_version = true,
13+
max_height = 30,
14+
min_width = 20,
15+
padding = 1,
16+
},
17+
null_ls = {
18+
enabled = true,
19+
name = "crates.nvim",
20+
},
21+
}

nvim/lua/config/lsp/handlers.lua

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
local M = {}
2+
3+
local status_cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
4+
if not status_cmp_ok then
5+
return
6+
end
7+
8+
M.capabilities = vim.lsp.protocol.make_client_capabilities()
9+
M.capabilities.textDocument.completion.completionItem.snippetSupport = true
10+
M.capabilities = cmp_nvim_lsp.default_capabilities(M.capabilities)
11+
12+
local function lsp_keymaps(bufnr)
13+
local opts = { noremap = true, silent = true }
14+
local keymap = vim.api.nvim_buf_set_keymap
15+
keymap(bufnr, "n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
16+
keymap(bufnr, "n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
17+
keymap(bufnr, "n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
18+
keymap(bufnr, "n", "gI", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
19+
keymap(bufnr, "n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
20+
keymap(bufnr, "n", "gl", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
21+
keymap(bufnr, "n", "<leader>lf", "<cmd>lua vim.lsp.buf.format{ async = true }<cr>", opts)
22+
keymap(bufnr, "n", "<leader>li", "<cmd>LspInfo<cr>", opts)
23+
keymap(bufnr, "n", "<leader>lI", "<cmd>LspInstallInfo<cr>", opts)
24+
keymap(bufnr, "n", "<leader>la", "<cmd>lua vim.lsp.buf.code_action()<cr>", opts)
25+
keymap(bufnr, "n", "<leader>lj", "<cmd>lua vim.diagnostic.goto_next({buffer=0})<cr>", opts)
26+
keymap(bufnr, "n", "<leader>lk", "<cmd>lua vim.diagnostic.goto_prev({buffer=0})<cr>", opts)
27+
keymap(bufnr, "n", "<leader>lr", "<cmd>lua vim.lsp.buf.rename()<cr>", opts)
28+
keymap(bufnr, "n", "<leader>ls", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
29+
keymap(bufnr, "n", "<leader>lq", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
30+
end
31+
32+
M.on_attach = function(client, bufnr)
33+
if client.name == "sumneko_lua" then
34+
client.server_capabilities.documentFormattingProvider = false
35+
end
36+
37+
lsp_keymaps(bufnr)
38+
local status_ok, illuminate = pcall(require, "illuminate")
39+
if not status_ok then
40+
return
41+
end
42+
illuminate.on_attach(client)
43+
end
44+
45+
M.setup = function()
46+
local signs = {
47+
48+
{ name = "DiagnosticSignError", text = "" },
49+
{ name = "DiagnosticSignWarn", text = "" },
50+
{ name = "DiagnosticSignHint", text = "" },
51+
{ name = "DiagnosticSignInfo", text = "" },
52+
}
53+
54+
for _, sign in ipairs(signs) do
55+
vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" })
56+
end
57+
58+
local config = {
59+
virtual_text = false, -- disable virtual text
60+
signs = {
61+
active = signs, -- show signs
62+
},
63+
update_in_insert = true,
64+
underline = true,
65+
severity_sort = true,
66+
float = {
67+
focusable = true,
68+
style = "minimal",
69+
border = "rounded",
70+
source = "always",
71+
header = "",
72+
prefix = "",
73+
},
74+
}
75+
76+
vim.diagnostic.config(config)
77+
78+
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
79+
border = "rounded",
80+
})
81+
82+
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
83+
border = "rounded",
84+
})
85+
end
86+
87+
return M

nvim/lua/config/lsp/init.lua

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local status_ok, _ = pcall(require, "lspconfig")
2+
if not status_ok then
3+
return
4+
end
5+
6+
require "config.lsp.mason"
7+
require("config.lsp.handlers").setup()

nvim/lua/config/lsp/mason.lua

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
local servers = {
2+
"bashls",
3+
"gopls",
4+
"golangci_lint_ls",
5+
"jsonls",
6+
"rust_analyzer",
7+
"sumneko_lua",
8+
"yamlls",
9+
}
10+
11+
local settings = {
12+
ui = {
13+
border = "none",
14+
icons = {
15+
package_installed = "",
16+
package_pending = "",
17+
package_uninstalled = "",
18+
},
19+
},
20+
log_level = vim.log.levels.INFO,
21+
max_concurrent_installers = 4,
22+
}
23+
24+
require("mason").setup(settings)
25+
require("mason-lspconfig").setup({
26+
ensure_installed = servers,
27+
automatic_installation = true,
28+
})
29+
30+
local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig")
31+
if not lspconfig_status_ok then
32+
return
33+
end
34+
35+
local opts = {}
36+
37+
for _, server in pairs(servers) do
38+
opts = {
39+
on_attach = require("config.lsp.handlers").on_attach,
40+
capabilities = require("config.lsp.handlers").capabilities,
41+
}
42+
43+
server = vim.split(server, "@")[1]
44+
45+
local require_ok, conf_opts = pcall(require, "user.lsp.settings." .. server)
46+
if require_ok then
47+
opts = vim.tbl_deep_extend("force", conf_opts, opts)
48+
end
49+
50+
51+
lspconfig[server].setup(opts)
52+
end
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local status_ok, schemastore = pcall(require, "schemastore")
2+
if not status_ok then
3+
return
4+
end
5+
6+
return {
7+
init_options = {
8+
provideFormatter = false,
9+
},
10+
settings = {
11+
json = {
12+
schemas = schemastore.json.schemas(),
13+
},
14+
},
15+
setup = {
16+
commands = {
17+
-- Format = {
18+
-- function()
19+
-- vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 })
20+
-- end,
21+
-- },
22+
},
23+
},
24+
}

0 commit comments

Comments
 (0)