diff --git a/init.lua b/init.lua index cbf9ff6..406be44 100644 --- a/init.lua +++ b/init.lua @@ -91,7 +91,7 @@ vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' -- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -102,7 +102,7 @@ vim.g.have_nerd_font = false vim.opt.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' @@ -154,13 +154,19 @@ vim.opt.inccommand = 'split' vim.opt.cursorline = true -- Minimal number of screen lines to keep above and below the cursor. -vim.opt.scrolloff = 10 +vim.opt.scrolloff = 20 -- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`), -- instead raise a dialog asking if you wish to save the current file(s) -- See `:help 'confirm'` vim.opt.confirm = true +-- Set tabstop/shiftwidth to 2 spaces +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true + -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -669,7 +675,7 @@ require('lazy').setup({ -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { - -- clangd = {}, + clangd = {}, -- gopls = {}, -- pyright = {}, -- rust_analyzer = {}, @@ -698,6 +704,64 @@ require('lazy').setup({ }, } + -- mason-lspconfig's automatic_enable bypasses the `servers` table, so jdtls settings go here + -- instead. client.settings must be set (and pushed) after creation, not via before_init/config.settings: + -- vim.lsp.Client snapshots settings = config.settings at construction time, before before_init runs. + -- + -- java.format.settings.url needs an Eclipse XML export, not the flat .properties file + -- Spotless uses, so convert it to a cached XML profile before pointing jdtls at it. + local function jdtls_formatter_url(root_dir) + local props_path = (root_dir or vim.fn.getcwd()) .. '/config/eclipse-formatter.properties' + local fs = vim.uv or vim.loop + local stat = fs.fs_stat(props_path) + if not stat then + return nil + end + + local xml_path = vim.fn.stdpath('cache') .. '/jdtls-formatter-' .. vim.fn.sha256(props_path) .. '.xml' + local xml_stat = fs.fs_stat(xml_path) + if not xml_stat or xml_stat.mtime.sec < stat.mtime.sec then + local lines = { + '', + '', + '', + } + for line in io.lines(props_path) do + local key, value = line:match('^%s*([^=%s]+)%s*=%s*(.-)%s*$') + if key and not key:match('^#') then + value = value:gsub('&', '&'):gsub('"', '"'):gsub('<', '<'):gsub('>', '>') + table.insert(lines, string.format('', key, value)) + end + end + table.insert(lines, '') + table.insert(lines, '') + local f = io.open(xml_path, 'w') + if f then + f:write(table.concat(lines, '\n')) + f:close() + end + end + + return xml_path + end + + vim.lsp.config('jdtls', { + on_init = function(client) + local xml_path = jdtls_formatter_url(client.config.root_dir) + if xml_path then + client.settings = vim.tbl_deep_extend('force', client.settings or {}, { + java = { + format = { + enabled = true, + settings = { url = xml_path, profile = 'GTCS1332' }, + }, + }, + }) + client:notify('workspace/didChangeConfiguration', { settings = client.settings }) + end + end, + }) + -- Ensure the servers and tools above are installed -- -- To check the current status of installed tools and/or manually install @@ -766,12 +830,19 @@ require('lazy').setup({ end, formatters_by_ft = { lua = { 'stylua' }, + cpp = { 'clang_format' }, + c = { 'clang_format' }, -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- -- You can use 'stop_after_first' to run the first available formatter from the list -- javascript = { "prettierd", "prettier", stop_after_first = true }, }, + formatters = { + clang_format = { + prepend_args = { '--style=file', '--fallback-style=Google' }, + }, + }, }, }, @@ -970,6 +1041,7 @@ require('lazy').setup({ -- If you are experiencing weird indenting issues, add the language to -- the list of additional_vim_regex_highlighting and disabled languages for indent. additional_vim_regex_highlighting = { 'ruby' }, + disable = { 'latex' }, }, indent = { enable = true, disable = { 'ruby' } }, }, @@ -1001,7 +1073,7 @@ require('lazy').setup({ -- This is the easiest way to modularize your config. -- -- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going. - -- { import = 'custom.plugins' }, + { import = 'custom.plugins' }, -- -- For additional information with loading, sourcing and examples see `:help lazy.nvim-🔌-plugin-spec` -- Or use telescope! diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d..e66addb 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -2,4 +2,15 @@ -- I promise not to create any merge conflicts in this directory :) -- -- See the kickstart.nvim README for more information -return {} +return { + { + 'lervag/vimtex', + lazy = false, -- we don't want to lazy load VimTeX + -- tag = "v2.15", -- uncomment to pin to a specific release + init = function() + -- VimTeX configuration goes here, e.g. + vim.g.vimtex_view_method = 'zathura' + end, + config = function() end, + }, +}