From 8af3cdd256b7c23c196d9ba5db5df9b580f498d0 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Wed, 2 Mar 2022 20:19:11 +0200 Subject: [PATCH] WIP: Not working yet --- home/.config/nvim/ftplugin/java.lua | 7 +- home/.config/nvim/lua/pluginconf/lsp.lua | 78 +++++++++---------- .../src/main/java/com/example/Greeter.java | 0 3 files changed, 42 insertions(+), 43 deletions(-) create mode 100644 home/.config/nvim/src/main/java/com/example/Greeter.java diff --git a/home/.config/nvim/ftplugin/java.lua b/home/.config/nvim/ftplugin/java.lua index 0ec274e..57bbb39 100644 --- a/home/.config/nvim/ftplugin/java.lua +++ b/home/.config/nvim/ftplugin/java.lua @@ -1,7 +1,7 @@ local nvim_local_dir = vim.fn.expand('~/.local/share/nvim') - local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ':p:h:t') local workspace_dir = nvim_local_dir .. '/jdtls-workspaces/' .. project_name + require('jdtls').start_or_attach({ cmd = { 'java', '-Declipse.application=org.eclipse.jdt.ls.core.id1', @@ -10,10 +10,11 @@ require('jdtls').start_or_attach({ '-Dlog.protocol=true', '-Dlog.level=ALL', '-Xms1g', '--add-modules=ALL-SYSTEM', '--add-opens', 'java.base/java.util=ALL-UNNAMED', '--add-opens', - 'java.base/java.lang=ALL-UNNAMED', -- 💀 - '-jar', nvim_local_dir .. + 'java.base/java.lang=ALL-UNNAMED', '-jar', nvim_local_dir .. '/lsp_servers/jdtls/plugins/org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar', '-configuration', nvim_local_dir .. '/lsp_servers/jdtls/config_linux', '-data', workspace_dir } }) + +require('pluginconf.lsp').Lsp_map_keys('jdtls', nil) diff --git a/home/.config/nvim/lua/pluginconf/lsp.lua b/home/.config/nvim/lua/pluginconf/lsp.lua index 6c2b431..82192fd 100644 --- a/home/.config/nvim/lua/pluginconf/lsp.lua +++ b/home/.config/nvim/lua/pluginconf/lsp.lua @@ -1,47 +1,45 @@ local lsp_installer = require("nvim-lsp-installer") -local buf_map_keys = function(server_name, bufnr) - local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) +Lsp_map_keys = function(server, bufnr) + print("Lsp_map_keys()") + local function map_key(...) + -- Map to buffer if buffer number is supplied, + -- globally otherwise + if bufnr == nil then + vim.api.nvim_set_keymap(...) + else + vim.api.nvim_buf_set_keymap(bufnr, ...) + end end local keymapOpts = {noremap = true, silent = true} - buf_set_keymap('n', 'gD', 'lua vim.lsp.buf.declaration()', - keymapOpts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', - keymapOpts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', keymapOpts) - buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', - keymapOpts) - buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', - keymapOpts) - buf_set_keymap('n', 'wa', - 'lua vim.lsp.buf.add_workspace_folder()', keymapOpts) - buf_set_keymap('n', 'wr', - 'lua vim.lsp.buf.remove_workspace_folder()', - keymapOpts) - buf_set_keymap('n', 'wl', - 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', - keymapOpts) - buf_set_keymap('n', 'D', - 'lua vim.lsp.buf.type_definition()', keymapOpts) - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', - keymapOpts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', - keymapOpts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', - keymapOpts) - buf_set_keymap('n', 'e', - 'lua vim.lsp.diagnostic.show_line_diagnostics()', - keymapOpts) - buf_set_keymap('n', '[d', 'lua vim.diagnostic.goto_prev()', - keymapOpts) - buf_set_keymap('n', ']d', 'lua vim.diagnostic.goto_next()', - keymapOpts) - buf_set_keymap('n', 'q', 'lua vim.diagnostic.set_loclist()', - keymapOpts) - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', - keymapOpts) + map_key('n', 'gD', 'lua vim.lsp.buf.declaration()', keymapOpts) + map_key('n', 'gd', 'lua vim.lsp.buf.definition()', keymapOpts) + map_key('n', 'K', 'lua vim.lsp.buf.hover()', keymapOpts) + map_key('n', 'gi', 'lua vim.lsp.buf.implementation()', keymapOpts) + map_key('n', '', 'lua vim.lsp.buf.signature_help()', + keymapOpts) + map_key('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', + keymapOpts) + map_key('n', 'wr', + 'lua vim.lsp.buf.remove_workspace_folder()', keymapOpts) + map_key('n', 'wl', + 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', + keymapOpts) + map_key('n', 'D', 'lua vim.lsp.buf.type_definition()', + keymapOpts) + map_key('n', 'rn', 'lua vim.lsp.buf.rename()', keymapOpts) + map_key('n', 'ca', 'lua vim.lsp.buf.code_action()', + keymapOpts) + map_key('n', 'gr', 'lua vim.lsp.buf.references()', keymapOpts) + map_key('n', 'e', + 'lua vim.lsp.diagnostic.show_line_diagnostics()', + keymapOpts) + map_key('n', '[d', 'lua vim.diagnostic.goto_prev()', keymapOpts) + map_key('n', ']d', 'lua vim.diagnostic.goto_next()', keymapOpts) + map_key('n', 'q', 'lua vim.diagnostic.set_loclist()', + keymapOpts) + map_key('n', 'f', 'lua vim.lsp.buf.formatting()', keymapOpts) end -- Add additional capabilities supported by nvim-cmp @@ -80,7 +78,7 @@ lsp_installer.on_server_ready(function(server) } end - opts.on_attach = buf_map_keys + opts.on_attach = Lsp_map_keys opts.capabilities = capabilities server:setup(opts) end) diff --git a/home/.config/nvim/src/main/java/com/example/Greeter.java b/home/.config/nvim/src/main/java/com/example/Greeter.java new file mode 100644 index 0000000..e69de29