Created
September 24, 2023 02:20
-
-
Save brcolow/f819672b4f0e12ae44451d8754c64bcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim.g.mapleader = ' ' | |
vim.g.maplocalleader = ' ' | |
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | |
if not vim.loop.fs_stat(lazypath) then | |
vim.fn.system({ | |
"git", | |
"clone", | |
"--filter=blob:none", | |
"https://github.com/folke/lazy.nvim.git", | |
"--branch=stable", -- latest stable release | |
lazypath, | |
}) | |
end | |
vim.opt.rtp:prepend(lazypath) | |
require("lazy").setup({ | |
'tpope/vim-fugitive', | |
'tpope/vim-rhubarb', | |
'tpope/vim-sleuth', | |
{ | |
"mfussenegger/nvim-jdtls", | |
dependencies = { "williamboman/mason.nvim" }, | |
build = ":MasonInstall jdtls" | |
}, | |
{ | |
'neovim/nvim-lspconfig', | |
dependencies = { 'williamboman/mason.nvim', config = true }, | |
'williamboman/mason-lspconfig.nvim', | |
}, | |
"williamboman/mason.nvim", | |
{ | |
"folke/which-key.nvim", | |
event = "VeryLazy", | |
init = function() | |
vim.o.timeout = true | |
vim.o.timeoutlen = 300 | |
end, | |
opts = { | |
} | |
}, | |
{ | |
-- Autocompletion | |
'hrsh7th/nvim-cmp', | |
dependencies = { | |
'L3MON4D3/LuaSnip', | |
'saadparwaiz1/cmp_luasnip', | |
'hrsh7th/cmp-nvim-lsp', | |
}, | |
}, | |
{ | |
-- Set lualine as statusline | |
'nvim-lualine/lualine.nvim', | |
-- See `:help lualine.txt` | |
opts = { | |
options = { | |
icons_enabled = false, | |
theme = 'onedark', | |
component_separators = '|', | |
section_separators = '', | |
}, | |
}, | |
}, | |
{ | |
-- Highlight, edit, and navigate code | |
'nvim-treesitter/nvim-treesitter', | |
dependencies = { | |
'nvim-treesitter/nvim-treesitter-textobjects', | |
}, | |
build = ':TSUpdate', | |
}, | |
{ | |
'navarasu/onedark.nvim', | |
priority = 1000, | |
config = function() | |
vim.cmd.colorscheme 'onedark' | |
end, | |
}, | |
}) | |
require("mason").setup() | |
local mason_root = require("mason.settings").current.install_root_dir | |
local install_path = require("mason-registry").get_package("jdtls"):get_install_path() | |
local project_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":p:h:t") | |
-- calculate workspace dir | |
local workspace_dir = vim.fn.stdpath("data") .. "/site/java/workspace-root/" .. project_name | |
-- get the current OS | |
local os | |
if vim.fn.has "mac" == 1 then | |
os = "mac" | |
elseif vim.fn.has "unix" == 1 then | |
os = "linux" | |
elseif vim.fn.has "win32" == 1 then | |
os = "win" | |
end | |
-- ensure that OS is valid | |
if not os or os == "" then | |
return | |
end | |
local config = { | |
cmd = { | |
"java", | |
"-Declipse.application=org.eclipse.jdt.ls.core.id1", | |
"-Dosgi.bundles.defaultStartLevel=4", | |
"-Declipse.product=org.eclipse.jdt.ls.core.product", | |
"-Dlog.protocol=true", | |
"-Dlog.level=ALL", | |
"-javaagent:" .. install_path .. "/lombok.jar", | |
"-Xms1g", | |
"--add-modules=ALL-SYSTEM", | |
"--add-opens", | |
"java.base/java.util=ALL-UNNAMED", | |
"--add-opens", | |
"java.base/java.lang=ALL-UNNAMED", | |
"-jar", | |
vim.fn.glob(install_path .. "/plugins/org.eclipse.equinox.launcher_*.jar"), | |
"-configuration", | |
install_path .. "/config_" .. os, | |
"-data", | |
workspace_dir, | |
}, | |
root_dir = vim.fs.dirname(vim.fs.find({'pom.xml', 'gradlew', '.git', 'mvnw'}, { upward = true })[1]), | |
} | |
require('jdtls').start_or_attach(config) | |
local mason_lspconfig = require 'mason-lspconfig' | |
mason_lspconfig.setup({ | |
ensure_installed = { 'jdtls' }, | |
}) | |
mason_lspconfig.setup_handlers({ | |
function(server_name) | |
if server_name ~= "jdtls" then | |
local opts = { | |
on_attach = require("plugins.lsp.handlers").on_attach, | |
capabilities = require("plugins.lsp.handlers").capabilities, | |
} | |
local require_ok, server = pcall(require, "plugins.lsp.settings." .. server_name) | |
if require_ok then | |
opts = vim.tbl_deep_extend("force", server, opts) | |
end | |
lspconfig[server_name].setup(opts) | |
end | |
end, | |
}) | |
require('nvim-treesitter.configs').setup { | |
ensure_installed = { 'java' }, | |
auto_install = false, | |
highlight = { enable = true }, | |
indent = { enable = true }, | |
incremental_selection = { | |
enable = true, | |
keymaps = { | |
init_selection = '<c-space>', | |
node_incremental = '<c-space>', | |
scope_incremental = '<c-s>', | |
node_decremental = '<M-space>', | |
}, | |
}, | |
} | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) | |
local cmp = require 'cmp' | |
local luasnip = require 'luasnip' | |
require('luasnip.loaders.from_vscode').lazy_load() | |
luasnip.config.setup {} | |
cmp.setup { | |
snippet = { | |
expand = function(args) | |
luasnip.lsp_expand(args.body) | |
end, | |
}, | |
mapping = cmp.mapping.preset.insert { | |
['<C-n>'] = cmp.mapping.select_next_item(), | |
['<C-p>'] = cmp.mapping.select_prev_item(), | |
['<C-d>'] = cmp.mapping.scroll_docs(-4), | |
['<C-f>'] = cmp.mapping.scroll_docs(4), | |
['<C-Space>'] = cmp.mapping.complete {}, | |
['<CR>'] = cmp.mapping.confirm { | |
behavior = cmp.ConfirmBehavior.Replace, | |
select = true, | |
}, | |
['<Tab>'] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
elseif luasnip.expand_or_locally_jumpable() then | |
luasnip.expand_or_jump() | |
else | |
fallback() | |
end | |
end, { 'i', 's' }), | |
['<S-Tab>'] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_prev_item() | |
elseif luasnip.locally_jumpable(-1) then | |
luasnip.jump(-1) | |
else | |
fallback() | |
end | |
end, { 'i', 's' }), | |
}, | |
sources = { | |
{ name = 'nvim_lsp' }, | |
{ name = 'luasnip' }, | |
}, | |
} | |
local status_ok, which_key = pcall(require, "which-key") | |
if not status_ok then return end | |
local mappings = { | |
c = { | |
name = "Code", | |
o = { "<Cmd>lua require'jdtls'.organize_imports()<CR>", "Organize Imports" }, | |
v = { "<Cmd>lua require('jdtls').extract_variable()<CR>", "Extract Variable" }, | |
c = { "<Cmd>lua require('jdtls').extract_constant()<CR>", "Extract Constant" }, | |
t = { "<Cmd>lua require'jdtls'.test_nearest_method()<CR>", "Test Method" }, | |
T = { "<Cmd>lua require'jdtls'.test_class()<CR>", "Test Class" }, | |
u = { "<Cmd>JdtUpdateConfig<CR>", "Update Config" }, | |
a = { "<Cmd>lua AttachDebugLocalhost()<CR>", "Attach Debugger" }, | |
}, | |
} | |
local vmappings = { | |
c = { | |
name = "Code", | |
v = { "<Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>", "Extract Variable" }, | |
c = { "<Esc><Cmd>lua require('jdtls').extract_constant(true)<CR>", "Extract Constant" }, | |
m = { "<Esc><Cmd>lua require('jdtls').extract_method(true)<CR>", "Extract Method" }, | |
}, | |
} | |
which_key.register(mappings, { | |
mode = "n", -- NORMAL mode | |
prefix = "<leader>", | |
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings | |
silent = true, -- use `silent` when creating keymaps | |
noremap = true, -- use `noremap` when creating keymaps | |
nowait = true, -- use `nowait` when creating keymaps | |
}) | |
which_key.register(vmappings, { | |
mode = "v", -- VISUAL mode | |
prefix = "<leader>", | |
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings | |
silent = true, -- use `silent` when creating keymaps | |
noremap = true, -- use `noremap` when creating keymaps | |
nowait = true, -- use `nowait` when creating keymaps | |
}) | |
vim.o.hlsearch = false | |
vim.wo.number = true | |
vim.o.mouse = 'a' | |
vim.o.clipboard = 'unnamedplus' | |
vim.o.breakindent = true | |
vim.o.undofile = true | |
vim.o.ignorecase = true | |
vim.o.smartcase = true | |
vim.wo.signcolumn = 'yes' | |
vim.o.updatetime = 250 | |
vim.o.timeoutlen = 300 | |
vim.o.completeopt = 'menuone,noselect' | |
vim.o.termguicolors = true | |
vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true }) | |
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true }) | |
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true }) | |
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true }) | |
vim.api.nvim_create_autocmd('TextYankPost', { | |
callback = function() | |
vim.highlight.on_yank() | |
end, | |
group = highlight_group, | |
pattern = '*', | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment