|
| 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 | + |
0 commit comments