Skip to content

Commit 4351afe

Browse files
committed
basic nvim setup with metals for scala
1 parent cb1c891 commit 4351afe

File tree

11 files changed

+2946
-0
lines changed

11 files changed

+2946
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.sw[op]
22
tmux/resurrect/
3+
local/state
4+
local/share/nvim/.netrwhist

.gitmodules

+15
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,18 @@
6161
[submodule "vim/bundle/vim-easymotion"]
6262
path = vim/bundle/vim-easymotion
6363
url = https://github.com/easymotion/vim-easymotion.git
64+
[submodule "local/share/nvim/plugged/plenary.nvim"]
65+
path = local/share/nvim/plugged/plenary.nvim
66+
url = https://github.com/nvim-lua/plenary.nvim.git
67+
[submodule "local/share/nvim/plugged/nvim-metals"]
68+
path = local/share/nvim/plugged/nvim-metals
69+
url = https://github.com/scalameta/nvim-metals.git
70+
[submodule "local/share/nvim/plugged/cmp-nvim-lsp"]
71+
path = local/share/nvim/plugged/cmp-nvim-lsp
72+
url = https://github.com/hrsh7th/cmp-nvim-lsp.git
73+
[submodule "local/share/nvim/plugged/nvim-cmp"]
74+
path = local/share/nvim/plugged/nvim-cmp
75+
url = https://github.com/hrsh7th/nvim-cmp.git
76+
[submodule "local/share/nvim/plugged/vim-vsnip"]
77+
path = local/share/nvim/plugged/vim-vsnip
78+
url = https://github.com/hrsh7th/vim-vsnip.git

config/nvim/init.vim

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
autocmd BufRead,BufNewFile *.txt,*.md setlocal spell spelllang=en_us
2+
3+
set nocompatible
4+
filetype plugin on
5+
syntax on
6+
7+
8+
call plug#begin()
9+
10+
Plug 'hrsh7th/cmp-nvim-lsp'
11+
Plug 'hrsh7th/nvim-cmp'
12+
Plug 'hrsh7th/vim-vsnip'
13+
14+
Plug 'nvim-lua/plenary.nvim'
15+
Plug 'scalameta/nvim-metals'
16+
17+
18+
call plug#end()
19+
20+

config/nvim/plugin/metals.lua

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
local api = vim.api
2+
local cmd = vim.cmd
3+
local map = vim.keymap.set
4+
5+
----------------------------------
6+
-- OPTIONS -----------------------
7+
----------------------------------
8+
9+
map("n", "gD", vim.lsp.buf.definition)
10+
map("n", "gi", vim.lsp.buf.implementation)
11+
map("n", "gr", vim.lsp.buf.references)
12+
map("n", "<leader>sh", vim.lsp.buf.signature_help)
13+
map("n", "<leader>rn", vim.lsp.buf.rename)
14+
map("n", "<leader>f", vim.lsp.buf.format)
15+
16+
17+
----------------------------------
18+
-- Completion Setup --------------
19+
----------------------------------
20+
local cmp = require("cmp")
21+
cmp.setup({
22+
sources = {
23+
{ name = "nvim_lsp" },
24+
{ name = "vsnip" },
25+
},
26+
snippet = {
27+
expand = function(args)
28+
-- Comes from vsnip
29+
vim.fn["vsnip#anonymous"](args.body)
30+
end,
31+
},
32+
mapping = cmp.mapping.preset.insert({
33+
-- None of this made sense to me when first looking into this since there
34+
-- is no vim docs, but you can't have select = true here _unless_ you are
35+
-- also using the snippet stuff. So keep in mind that if you remove
36+
-- snippets you need to remove this select
37+
["<CR>"] = cmp.mapping.confirm({ select = true }),
38+
-- I use tabs... some say you should stick to ins-completion but this is just here as an example
39+
["<Tab>"] = function(fallback)
40+
if cmp.visible() then
41+
cmp.select_next_item()
42+
else
43+
fallback()
44+
end
45+
end,
46+
["<S-Tab>"] = function(fallback)
47+
if cmp.visible() then
48+
cmp.select_prev_item()
49+
else
50+
fallback()
51+
end
52+
end,
53+
}),
54+
})
55+
56+
57+
----------------------------------
58+
-- LSP Setup ---------------------
59+
----------------------------------
60+
local metals_config = require("metals").bare_config()
61+
62+
-- Example of settings
63+
metals_config.settings = {
64+
showImplicitArguments = true,
65+
excludedPackages = { "akka.actor.typed.javadsl", "com.github.swagger.akka.javadsl" },
66+
}
67+
68+
-- *READ THIS*
69+
-- I *highly* recommend setting statusBarProvider to true, however if you do,
70+
-- you *have* to have a setting to display this in your statusline or else
71+
-- you'll not see any messages from metals. There is more info in the help
72+
-- docs about this
73+
-- metals_config.init_options.statusBarProvider = "on"
74+
75+
-- Example if you are using cmp how to make sure the correct capabilities for snippets are set
76+
metals_config.capabilities = require("cmp_nvim_lsp").default_capabilities()
77+
78+
-- Autocmd that will actually be in charging of starting the whole thing
79+
local nvim_metals_group = api.nvim_create_augroup("nvim-metals", { clear = true })
80+
api.nvim_create_autocmd("FileType", {
81+
-- NOTE: You may or may not want java included here. You will need it if you
82+
-- want basic Java support but it may also conflict if you are using
83+
-- something like nvim-jdtls which also works on a java filetype autocmd.
84+
pattern = { "scala", "sbt", "java" },
85+
callback = function()
86+
require("metals").initialize_or_attach(metals_config)
87+
end,
88+
group = nvim_metals_group,
89+
})
90+

install.conf.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- [cd vim/bundle; for d in *; do (cd $d && git checkout master); done, Checkout vim plugin branches]
1010

1111
- link:
12+
~/.config: config
13+
~/.local: local
1214
~/.tmux.conf: tmux.conf
1315
~/.tmux: tmux
1416
~/.vim: vim

local/share/nvim/plugged/cmp-nvim-lsp

Submodule cmp-nvim-lsp added at 44b16d1

local/share/nvim/plugged/nvim-cmp

Submodule nvim-cmp added at 5dce1b7

local/share/nvim/plugged/nvim-metals

Submodule nvim-metals added at d395a78

local/share/nvim/plugged/plenary.nvim

Submodule plenary.nvim added at 9ce85b0

local/share/nvim/plugged/vim-vsnip

Submodule vim-vsnip added at be27746

0 commit comments

Comments
 (0)