Skip to content

Instantly share code, notes, and snippets.

@cjgratacos
Last active March 8, 2021 17:21
Show Gist options
  • Save cjgratacos/5ee75b44a4c3606c584bf3b9ec7d954a to your computer and use it in GitHub Desktop.
Save cjgratacos/5ee75b44a4c3606c584bf3b9ec7d954a to your computer and use it in GitHub Desktop.
if !exists('g:vscode')
set nocompatible
let mapleader = "\<Space>"
lua require('plugins')
lua require('themes')
lua require('servers')
lua require('debugger')
lua require('mappings')
augroup highlight_yank
autocmd!
autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank()
augroup end
augroup jdtls_lsp
autocmd!
autocmd FileType java lua require'jdtls_setup'.setup()
augroup end
" lua vim.lsp.set_log_level("debug")
if has('nvim') || has('termguicolors')
set termguicolors
endif
if !has('gui_running')
set t_Co=256
endif
let g:edge_style = 'aura'
colorscheme edge
""""""""""""""""""""""""""""""""""""""'
""""""""""""""""""""""""""""""""""""""'
"" GUI Configs
""""""""""""""""""""""""""""""""""""""'
""""""""""""""""""""""""""""""""""""""'
set guioptions-=T " Remove toolbar
set vb t_vb= " No more beeps
set backspace=2 " Backspace over newlines
set nofoldenable
set ttyfast
" https://github.com/vi/vim/issues/1735#issuecomment-383353563
set lazyredraw
set synmaxcol=500
set laststatus=2
set diffopt+=iwhite " No whitespace in vimdiff
" Make diffing better: https://vimways.org/2018/the-power-of-diff/
set diffopt+=algorithm:patience
set diffopt+=indent-heuristic
set showcmd " Show (partial) command in status line.
set mouse=a " Enable mouse usage (all modes) in terminals
set shortmess+=c " don't give |ins-completion-menu| messages.
" Show those damn hidden characters
" Verbose: set listchars=nbsp:¬,eol:¶,extends:»,precedes:«,trail:•
set listchars=nbsp:¬,extends:»,precedes:«,trail:•
set number
set relativenumber
syntax on
" Cursor Setup
set cursorline
set cmdheight=2
set updatetime=50
filetype plugin indent on
set autoindent
set timeoutlen=300 " http://stackoverflow.com/questions/2158516/delay-before-o-opens-a-new-line
set encoding=utf-8
set scrolloff=5
set noshowmode
set hidden
set nowrap
set nojoinspaces
" Always draw sign column. Prevent buffer moving when adding/deleting sign.
set signcolumn=yes
" Sane splits
set splitright
set splitbelow
" Permanent undo
set undodir=~/.vimdid
set undofile
" Use wide spaces instead of tabs
set shiftwidth=4 softtabstop=4 tabstop=4 expandtab
" Wrapping options
set formatoptions=tc " wrap text and comments using textwidth
set formatoptions+=r " continue comments when pressing ENTER in I mode
set formatoptions+=q " enable formatting of comments with gq
set formatoptions+=n " detect lists for formatting
set formatoptions+=b " auto-wrap in insert mode, and do not wrap old long lines
" Proper search
set incsearch
set ignorecase
set smartcase
set gdefault
" Search results centered please
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" Very magic by default
nnoremap ? ?\v
nnoremap / /\v
cnoremap %s/ %sm/
" =============================================================================
" # Keyboard shortcuts
" =============================================================================
" ; as :
nnoremap . ;
nnoremap ; :
" Ctrl+c and Ctrl+j as Esc
" Ctrl-j is a little awkward unfortunately:
" https://github.com/neovim/neovim/issues/5916
" So we also map Ctrl+k
inoremap <C-j> <Esc>
nnoremap <C-k> <Esc>
inoremap <C-k> <Esc>
vnoremap <C-k> <Esc>
snoremap <C-k> <Esc>
xnoremap <C-k> <Esc>
cnoremap <C-k> <Esc>
onoremap <C-k> <Esc>
lnoremap <C-k> <Esc>
tnoremap <C-k> <Esc>
nnoremap <C-c> <Esc>
inoremap <C-c> <Esc>
vnoremap <C-c> <Esc>
snoremap <C-c> <Esc>
xnoremap <C-c> <Esc>
cnoremap <C-c> <Esc>
onoremap <C-c> <Esc>
lnoremap <C-c> <Esc>
tnoremap <C-c> <Esc>
" Neat X clipboard integration
" ,p will paste clipboard into buffer
" ,c will copy entire buffer into clipboard
noremap <leader>p :read !xsel --clipboard --output<cr>
noremap <leader>y :w !xsel -ib<cr><cr>
" Open new file adjacent to current file
nnoremap <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
" No arrow keys --- force yourself to use the home row
nnoremap <up> <nop>
nnoremap <down> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
" Left and right can switch buffers
nnoremap <left> :bp<CR>
nnoremap <right> :bn<CR>
" Move by line
nnoremap j gj
nnoremap k gk
" Git fugitive
nnoremap <leader>gs :Git<CR>
" Quick-save
nmap <leader>w :w<CR>
map H ^
map L $
nnoremap Q <nop>
nnoremap <silent><leader>b :lua require'telescope.builtin'.buffers{}<CR>
nnoremap <silent><leader><leader> :lua require'telescope.builtin'.buffers{}<CR>
nnoremap <silent><leader>f :lua require'telescope.builtin'.git_files{}<CR>
nnoremap <silent><leader>s :lua require'telescope.builtin'.current_buffer_fuzzy_find{}<CR>
nnoremap <silent><leader>m :lua require'telescope.builtin'.marks{}<CR>
nnoremap <silent><leader>r :lua require'telescope.builtin'.live_grep{}<CR>
nnoremap <silent><leader>gc :lua require'telescope.builtin'.git_commits{}<CR>
" NvimTreeOpen and NvimTreeClose are also available if you need them
nnoremap <silent><leader>tt :NvimTreeToggle<CR>
nnoremap <silent><leader>tr :NvimTreeRefresh<CR>
nnoremap <silent><leader>tn :NvimTreeFindFile<CR>
nnoremap <silent><leader>tf :Lspsaga open_floaterm<CR>
nnoremap <silent><leader>tc :Lspsaga close_floaterm<CR>
nnoremap <silent><leader>ac :only<CR>
nnoremap <leader>, :set invlist<CR>
nnoremap <silent>Q :bd!<CR>
nnoremap <silent><leader>q :q<CR>
" I can type :help on my own, thanks.
map <F1> <Esc>
imap <F1> <Esc>
nnoremap <leader>h <C-W>h
nnoremap <leader>j <C-W>j
nnoremap <leader>k <C-W>k
nnoremap <leader>l <C-W>l
" Prevent accidental writes to buffers that shouldn't be edited
autocmd BufRead *.orig set readonly
autocmd BufRead *.pacnew set readonly
" Leave paste mode when leaving insert mode
autocmd InsertLeave * set nopaste
" Jump to last edit position on opening file
if has("autocmd")
" https://stackoverflow.com/questions/31449496/vim-ignore-specifc-file-in-autocommand
au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""
"" Sneak
""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""
let g:sneak#label = 1
" case insensitive sneak
let g:sneak#use_ic_scs = 1
" immediately move to the next instance of search, if you move the cursor sneak is back to default behavior
let g:sneak#s_next = 1
" remap so I can use , and ; with f and t
""""""""""""""""""""""""""""""""""""
" Trigger a highlight in the appropriate direction when pressing these keys:
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
highlight QuickScopePrimary guifg='#00C7DF' gui=underline ctermfg=155 cterm=underline
highlight QuickScopeSecondary guifg='#afff5f' gui=underline ctermfg=81 cterm=underline
let g:qs_max_chars=150
""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""
"" Dirvish
""""""""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""""""""
let g:loaded_netrwPlugin = 1
command! -nargs=? -complete=dir Explore Dirvish <args>
command! -nargs=? -complete=dir Sexplore belowright split | silent Dirvish <args>
command! -nargs=? -complete=dir Vexplore leftabove vsplit | silent Dirvish <args>
let g:dirvish_mode = ':sort ,^.*[\/], | silent keeppatterns g@\v/\.[^\/]+/?$@d _'
endif
@cjgratacos
Copy link
Author

-- file: lua/debugger.lua
-- vim.g.vimspector_enable_mappings = 'HUMAN'
vim.g.vimspector_base_dir=os.getenv('HOME') .. '/.vim/vimspector-config'
local opts = { noremap=true, silent=true }

vim.api.nvim_set_keymap("n", "<leader>/", "<plug>kommentary_line_default", {})
vim.api.nvim_set_keymap("n", "<leader>dd", "<Cmd>call vimspector#Launch()<CR>", opts)
vim.api.nvim_set_keymap("n", "<leader>dw", "<Cmd><Plug>VimspectorWatch<CR>", opts)
vim.api.nvim_set_keymap("n", "<leader>de", "<Cmd><Plug>VimspectorEval<CR>", opts)
vim.api.nvim_set_keymap("n", "<leader>do", "<Cmd>VimspectorShowOutput<CR>", opts)
vim.api.nvim_set_keymap("n", "<leader>dx", "<Cmd>VimspectorReset<CR>", opts)
vim.api.nvim_set_keymap("n", "<F1>", "<Cmd<Plug>VimspectorToggleBreakpoint<CR>", opts)
vim.api.nvim_set_keymap("n", "<F2>", "<Cmd<Plug>VimspectorStep<CR>", opts)
vim.api.nvim_set_keymap("n", "<F2>", "<Cmd><Plug><CR>", opts)

-- <Plug>VimspectorContinue
-- <Plug>VimspectorStop
-- <Plug>VimspectorRestart
-- <Plug>VimspectorPause
-- <Plug>VimspectorToggleBreakpoint
-- <Plug>VimspectorToggleConditionalBreakpoint
-- <Plug>VimspectorAddFunctionBreakpoint
-- <Plug>VimspectorStepOver
-- <Plug>VimspectorStepInto
-- <Plug>VimspectorStepOut
-- <Plug>VimspectorRunToCursor

@cjgratacos
Copy link
Author

--file: lua/jdtls_setup.lua
local M = {}

function M.setup()
    local on_attach = function(client, bufnr)
      require'compe'.setup {
          enabled = true;
          autocomplete = true;
          debug = false;
          min_length = 1;
          preselect = 'enable';
          throttle_time = 80;
          source_timeout = 200;
          incomplete_delay = 400;
          max_abbr_width = 100;
          max_kind_width = 100;
          max_menu_width = 100;
          documentation = true;

          source = {
            path = true;
            buffer = true;
            calc = true;
            vsnip = false;
            nvim_lsp = true;
            nvim_lua = true;
            spell = true;
            tags = true;
            snippets_nvim = false;
            treesitter = true;
          };
        }

      require'lspkind'.init()
      require'jdtls.setup'.add_commands()
      require'jdtls'.setup_dap()
      require'lsp-status'.register_progress()
      require'illuminate'.on_attach(client)

      local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
      local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

      buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

      -- Mappings.
      local opts = { noremap=true, silent=true }
      buf_set_keymap('n', '<leader>gr', '<Cmd>Lspsaga lsp_finder<CR>', opts)
      buf_set_keymap('n', '<leader>gd', '<Cmd>Lspsaga preview_definition<CR>', opts)
      buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
      buf_set_keymap('n', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
      buf_set_keymap('n', 'K', '<Cmd>Lspsaga hover_doc<CR>', opts)
      buf_set_keymap('n', 'gi', '<Cmd>lua vim.lsp.buf.implementation()<CR>', opts)
      buf_set_keymap('n', 'g1', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
      buf_set_keymap('n', 'gw', '<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)
      buf_set_keymap('n', '<C-h>', '<Cmd>Lspsaga signature_help<CR>', opts)
      buf_set_keymap('n', '<leader>rn', '<Cmd>Lspsaga rename<CR>', opts)
      buf_set_keymap('n', '<leader>wa', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
      buf_set_keymap('n', '<leader>wr', '<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
      buf_set_keymap('n', '<leader>cs', '<Cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
      buf_set_keymap('n', '<leader>ca', '<Cmd>Lspsaga code_action<CR>', opts)
      buf_set_keymap('n', '<C-k>', '<Cmd>Lspsaga diagnostic_jump_prev<CR>', opts)
      buf_set_keymap('n', '<C-j>', '<Cmd>Lspsaga diagnostic_jump_next<CR>', opts)

      buf_set_keymap('n', '<leader>cw', "<Cmd>lua require'telescope.builtin'.lsp_workspace_symbols{}<CR>", opts)
      buf_set_keymap('n', '<leader>cd', "<Cmd>lua require'telescope.builtin'.lsp_document_symbols{}<CR>", opts)
      buf_set_keymap('n', '<leader>ct', "<Cmd>lua require'telescope.builtin'.treesitter{}<CR>", opts)
      buf_set_keymap("n", "<leader>cf", "<Cmd>lua vim.lsp.buf.formatting()<CR>", opts)

      buf_set_keymap("n", "<leader>ty", "<Cmd>TestNearest<CR>", opts)
      buf_set_keymap("n", "<leader>tu", "<Cmd>TestFile<CR>", opts)
      buf_set_keymap("n", "<leader>tl", "<Cmd>TestLast<CR>", opts)
      buf_set_keymap("n", "<leader>tv", "<Cmd>TestVisit<CR>", opts)

      -- Java specific
      buf_set_keymap("n", "<leader>di", "<Cmd>lua require'jdtls'.organize_imports()<CR>", opts)
      buf_set_keymap("n", "<leader>dt", "<Cmd>lua require'jdtls'.test_class()<CR>", opts)
      buf_set_keymap("n", "<leader>dn", "<Cmd>lua require'jdtls'.test_nearest_method()<CR>", opts)
      buf_set_keymap("v", "<leader>de", "<Esc><Cmd>lua require('jdtls').extract_variable(true)<CR>", opts)
      buf_set_keymap("n", "<leader>de", "<Cmd>lua require('jdtls').extract_variable()<CR>", opts)
      buf_set_keymap("v", "<leader>dm", "<Esc><Cmd>lua require('jdtls').extract_method(true)<CR>", opts)
    end

    local root_markers = {'build.gradle', 'pom.xml'}
    local root_dir = require('jdtls.setup').find_root(root_markers)
    local home = os.getenv('HOME')

    -- For Gradle only lets remove the .settings folder
    if root_dir ~=nil then
        local f=io.open(root_dir .. "/build.gradle","r")
        if f~=nil then
           io.close(f)
           -- vim.g['test#java#runner'] = 'gradletest'
           vim.api.nvim_exec([[
           let test#java#runner = 'gradletest'
           ]], true)
           os.execute("rm -rf " .. root_dir .. "/.settings")
        end
    end

    local capabilities = {
        workspace = {
            configuration = true
        },
        textDocument = {
            completion = {
                completionItem = {
                    snippetSupport = true
                }
            }
        }
    }

    local workspace_folder = home .. "/.workspace/workspace-" .. vim.fn.fnamemodify(root_dir, ":p:h:t")

    local config = {
        name = 'jdtls',
        flags = {
          allow_incremental_sync = true,
        };
        capabilities = capabilities,
        on_attach = on_attach,
    }

    config.settings = {
        ['java.format.settings.url'] = home .. "/.config/nvim/language-servers/java-google-formatter.xml",
        ['java.format.settings.profile'] = "GoogleStyle",
        ['java.import.gradle.enabled'] = true,
        ['java.import.gradle.wrapper.enabled'] = true,
        ['java.import.gradle.home'] = home .. "/.gradle",
        ['java.import.gradle.user.home'] = home,
        java = {
          signatureHelp = { enabled = true };
          contentProvider = { preferred = 'fernflower' };
          completion = {
            favoriteStaticMembers = {
              "org.hamcrest.MatcherAssert.assertThat",
              "org.hamcrest.Matchers.*",
              "org.hamcrest.CoreMatchers.*",
              "org.junit.jupiter.api.Assertions.*",
              "java.util.Objects.requireNonNull",
              "java.util.Objects.requireNonNullElse",
              "org.mockito.Mockito.*"
            }
          };
          sources = {
            organizeImports = {
              starThreshold = 9999;
              staticStarThreshold = 9999;
            };
          };
          codeGeneration = {
            toString = {
              template = "${object.className}{${member.name()}=${member.value}, ${otherMembers}}"
            }
          };
          configuration = {
            runtimes = {
              {
                name = "JavaSE-11",
                path = home .. "/.sdkman/candidates/java/11.0.10-open/",
              },
              {
                name = "JavaSE-14",
                path = home .. "/.sdkman/candidates/java/14.0.2-open/",
              },
              {
                name = "JavaSE-15",
                path = home .. "/.sdkman/candidates/java/15.0.1-open/",
              },
            }
          };
        };
    }
    config.cmd = {'java-lsp', workspace_folder}
    config.on_attach = on_attach
    config.on_init = function(client, _)
        client.notify('workspace/didChangeConfiguration', { settings = config.settings })
    end

    local jar_patterns = {
        home .. '/.local/share/lsp/java-debug/com.microsoft.java.debug.plugin/target/com.microsoft.java.debug.plugin-*.jar',
        -- '/dev/dgileadi/vscode-java-decompiler/server/*.jar',
        home .. '/.local/share/lsp/vscode-java-test/server/*.jar',
    }

    local bundles = {}
    for _, jar_pattern in ipairs(jar_patterns) do
      for _, bundle in ipairs(vim.split(vim.fn.glob(home .. jar_pattern), '\n')) do
        if not vim.endswith(bundle, 'com.microsoft.java.test.runner.jar') then
          table.insert(bundles, bundle)
        end
      end
    end

    local extendedClientCapabilities = require'jdtls'.extendedClientCapabilities
    extendedClientCapabilities.resolveAdditionalTextEditsSupport = true
    config.init_options = {
      bundles = bundles;
      extendedClientCapabilities = extendedClientCapabilities;
    }

    -- Server
    require('jdtls').start_or_attach(config)
end

return M

@cjgratacos
Copy link
Author

--file: lua/mappings.lua
vim.o.completeopt = "menuone,noselect"

local t = function(str)
  return vim.api.nvim_replace_termcodes(str, true, true, true)
end

local check_back_space = function()
    local col = vim.fn.col('.') - 1
    if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
        return true
    else
        return false
    end
end

-- Use (s-)tab to:
--- move to prev/next item in completion menuone
--- jump to prev/next snippet's placeholder
_G.tab_complete = function()
  if vim.fn.pumvisible() == 1 then
    return t "<C-n>"
  elseif check_back_space() then
    return t "<Tab>"
  else
    return vim.fn['compe#complete']()
  end
end

_G.s_tab_complete = function()
  if vim.fn.pumvisible() == 1 then
    return t "<C-p>"
  else
    return t "<S-Tab>"
  end
end


local opts = {expr = true, silent = true}
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", opts)
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", opts)
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", opts)
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", opts)
vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", opts)
vim.api.nvim_set_keymap("s", "<CR>", "compe#confirm('<CR>')", opts)
-- Kommentary
vim.api.nvim_set_keymap("n", "<leader>/", "<plug>kommentary_line_default", {})
vim.api.nvim_set_keymap("v", "<leader>/", "<plug>kommentary_visual_default", {})

@cjgratacos
Copy link
Author

--file:lua/plugins.lua
local execute = vim.api.nvim_command
local fn = vim.fn

local install_path = fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'

if fn.empty(fn.glob(install_path)) > 0 then
  execute('!git clone https://github.com/wbthomason/packer.nvim '..install_path)
  execute 'packadd packer.nvim'
end

vim.g.kommentary_create_default_mappings = false

vim.cmd [[packadd packer.nvim]]

return require('packer').startup(function()
    use 'tpope/vim-sensible'
    use 'kyazdani42/nvim-web-devicons'
    use 'neovim/nvim-lspconfig'
    use 'hrsh7th/nvim-compe'
    use 'nvim-lua/lsp_extensions.nvim'
    use 'anott03/nvim-lspinstall'
    use 'nvim-lua/lsp-status.nvim'
    use 'glepnir/lspsaga.nvim'
    use 'onsails/lspkind-nvim'
    use 'akinsho/nvim-toggleterm.lua'
    use 'b3nj5m1n/kommentary'
    use 'nvim-lua/popup.nvim'
    use 'nvim-lua/plenary.nvim'
    use 'nvim-telescope/telescope.nvim'
    use 'RRethy/vim-illuminate'
    use 'akinsho/nvim-bufferline.lua'
    use 'akinsho/dependency-assist.nvim'

    use 'nvim-treesitter/playground'
    use 'kyazdani42/nvim-tree.lua'
    use 'glepnir/galaxyline.nvim'

    use 'puremourning/vimspector'

    use 'scalameta/nvim-metals'
    use 'mfussenegger/nvim-jdtls'

    use 'vim-test/vim-test'

    use {
      'lewis6991/gitsigns.nvim',
      requires = {
        'nvim-lua/plenary.nvim'
      },
      config = function()
        require('gitsigns').setup()
      end
    }

    use {
        'nvim-treesitter/nvim-treesitter',
        run = ':TSUpdate'
    }

    use 'sainnhe/edge'

    use 'justinmk/vim-dirvish'
    use 'tpope/vim-vinegar'
    use 'justinmk/vim-sneak'
    use 'unblevable/quick-scope'
    use 'rhysd/git-messenger.vim'
    use 'tpope/vim-fugitive'

    use 'uiiaoo/java-syntax.vim'
    use 'sheerun/vim-polyglot'

    --Markdown Preview
    use {
        'iamcco/markdown-preview.nvim',
        run = 'cd app && yarn install'
    }

end)

@cjgratacos
Copy link
Author

--file:lua/servers.lua
local lsp_status = require('lsp-status')
local nvim_lsp = require('lspconfig')
local on_attach = function(client, bufnr)
  require'compe'.setup {
      enabled = true;
      autocomplete = true;
      debug = false;
      min_length = 1;
      preselect = 'enable';
      throttle_time = 80;
      source_timeout = 200;
      incomplete_delay = 400;
      max_abbr_width = 100;
      max_kind_width = 100;
      max_menu_width = 100;
      documentation = true;

      source = {
        path = true;
        buffer = true;
        calc = true;
        vsnip = false;
        nvim_lsp = true;
        nvim_lua = true;
        spell = true;
        tags = true;
        snippets_nvim = false;
        treesitter = true;
      };
    }
  lsp_status.register_progress()
  require'lspkind'.init()
  require'illuminate'.on_attach(client)

  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { noremap=true, silent=true }
  buf_set_keymap('n', '<leader>gr', '<Cmd>Lspsaga lsp_finder<CR>', opts)
  buf_set_keymap('n', '<leader>gd', '<Cmd>Lspsaga preview_definition<CR>', opts)
  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
  buf_set_keymap('n', 'gr', '<Cmd>lua vim.lsp.buf.references()<CR>', opts)
  buf_set_keymap('n', 'K', '<Cmd>Lspsaga hover_doc<CR>', opts)
  buf_set_keymap('n', 'gi', '<Cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  buf_set_keymap('n', 'g1', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
  buf_set_keymap('n', 'gw', '<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)
  buf_set_keymap('n', '<C-h>', '<Cmd>Lspsaga signature_help<CR>', opts)
  buf_set_keymap('n', '<leader>rn', '<Cmd>Lspsaga rename<CR>', opts)
  buf_set_keymap('n', '<leader>wa', '<Cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<leader>wr', '<Cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<leader>cs', '<Cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
  buf_set_keymap('n', '<leader>ca', '<Cmd>Lspsaga code_action<CR>', opts)
  buf_set_keymap('n', '<C-k>', '<Cmd>Lspsaga diagnostic_jump_prev<CR>', opts)
  buf_set_keymap('n', '<C-j>', '<Cmd>Lspsaga diagnostic_jump_next<CR>', opts)

  buf_set_keymap('n', '<leader>cw', "<Cmd>lua require'telescope.builtin'.lsp_workspace_symbols{}<CR>", opts)
  buf_set_keymap('n', '<leader>cd', "<Cmd>lua require'telescope.builtin'.lsp_document_symbols{}<CR>", opts)
  buf_set_keymap('n', '<leader>ct', "<Cmd>lua require'telescope.builtin'.treesitter{}<CR>", opts)
  buf_set_keymap("n", "<leader>cf", "<Cmd>lua vim.lsp.buf.formatting()<CR>", opts)

  buf_set_keymap("n", "<leader>ty", "<Cmd>TestNearest<CR>", opts)
  buf_set_keymap("n", "<leader>tu", "<Cmd>TestFile<CR>", opts)
  buf_set_keymap("n", "<leader>tl", "<Cmd>TestLast<CR>", opts)
  buf_set_keymap("n", "<leader>tv", "<Cmd>TestVisit<CR>", opts)

  -- Set some keybinds conditional on server capabilities
  if client.resolved_capabilities.document_formatting then
    buf_set_keymap("n", "<leader>cf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
  elseif client.resolved_capabilities.document_range_formatting then
    buf_set_keymap("n", "<leader>cf", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
  end
end

-- Use a loop to conveniently both setup defined servers
-- and map buffer local keybindings when the language server attaches
local servers = { "bashls",
"dockerls",
"pyright",
"gopls",
"graphql",
"jsonls",
"rust_analyzer",
"tsserver",
"sourcekit",
"sqls",
"cmake",
"denols",
"vuels",
"yamlls",
"vimls"
}
for _, lsp in ipairs(servers) do
  nvim_lsp[lsp].setup { on_attach = on_attach }
end

-- Rust setup
vim.api.nvim_exec([[
  augroup rust_commands
    autocmd!
    autocmd BufEnter,BufWinEnter,TabEnter *.rs lua require'lsp_extensions'.inlay_hints{ prefix = " » " }
    autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 1000)
  augroup end
]], false)

--Enable (broadcasting) snippet capability for completion
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require'lspconfig'.html.setup {
  on_attach = on_attach,
  capabilities = capabilities,
}

require'lspconfig'.intelephense.setup{
  on_attach = on_attach,
  init_options = {
    licenceKey = ''
  }
}

-- set the path to the sumneko installation; if you previously installed via the now deprecated :LspInstall, use
local sumneko_root_path = '/home/cjgratacos/.local/share/lsp/sumneko-language-server'
local sumneko_binary = sumneko_root_path .. "/sumneko-language-server"

require'lspconfig'.sumneko_lua.setup {
  on_attach = on_attach,
  cmd = {sumneko_binary, "-E", sumneko_root_path .. "/extension/server/main.lua"},
  settings = {
    Lua = {
      runtime = {
        -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
        version = 'LuaJIT',
        -- Setup your lua path
        path = vim.split(package.path, ';'),
      },
      diagnostics = {
        -- Get the language server to recognize the `vim` global
        globals = {'vim'},
      },
      workspace = {
        -- Make the server aware of Neovim runtime files
        library = {
          [vim.fn.expand('$VIMRUNTIME/lua')] = true,
          [vim.fn.expand('$VIMRUNTIME/lua/vim/lsp')] = true,
        },
      },
    },
  },
}

-- Enable diagnostics
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
  vim.lsp.diagnostic.on_publish_diagnostics, {
    virtual_text = true,
    signs = true,
    update_in_insert = true,
  }
)

require 'nvim-treesitter.configs'.setup {
  playground = {
    enable = true,
    disable = {},
    updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
    persist_queries = false -- Whether the query persists across vim sessions
  }
}

local actions = require('telescope.actions')
require('telescope').setup{
  defaults = {
    mappings = {
      i = {
        ["<esc>"] = actions.close
      },
    },
  }
}

--- Saga
require'lspsaga'.init_lsp_saga {
    server_filetype_map = {
        metals = { 'sbt', 'scala' },
        jdtls = { 'java' }
    },
    finder_action_keys = {
        open = '<CR>'
    }
}

-- Bufferline
require'bufferline'.setup{
    diagnostics = 'nvim_lsp'
}

require'dependency_assist'.setup{}

require'toggleterm'.setup{
    open_mapping = '<C-t>'
}

@cjgratacos
Copy link
Author

--file:lua/themes.lua
local gl = require('galaxyline')
local lsp_status = require('lsp-status')
local lspconfig = require('lspconfig')

lsp_status.register_progress()


local gls = gl.section
gl.short_line_list = {'NvimTree','vista','dbui'}

local colors = {
  bg = '#202328',
  fg = '#bbc2cf',
  yellow = '#fabd2f',
  cyan = '#008080',
  darkblue = '#081633',
  green = '#98be65',
  orange = '#FF8800',
  violet = '#a9a1e1',
  magenta = '#c678dd',
  blue = '#51afef';
  red = '#ec5f67';
}

local buffer_not_empty = function()
  if vim.fn.empty(vim.fn.expand('%:t')) ~= 1 then
    return true
  end
  return false
end

gls.left[1] = {
  RainbowRed = {
    provider = function() return '' end,
    highlight = {colors.blue,colors.bg}
  },
}
gls.left[2] = {
  ViMode = {
    provider = function()
      -- auto change color according the vim mode
      local mode_color = {n = colors.magenta, i = colors.green,v=colors.blue,
                          [''] = colors.blue,V=colors.blue,
                          c = colors.red,no = colors.magenta,s = colors.orange,
                          S=colors.orange,[''] = colors.orange,
                          ic = colors.yellow,R = colors.violet,Rv = colors.violet,
                          cv = colors.red,ce=colors.red, r = colors.cyan,
                          rm = colors.cyan, ['r?'] = colors.cyan,
                          ['!']  = colors.red,t = colors.red}
      vim.api.nvim_command('hi GalaxyViMode guifg='..mode_color[vim.fn.mode()])
      return ''
    end,
    highlight = {colors.red,colors.bg,'bold'},
  },
}
gls.left[3] = {
  FileSize = {
    provider = 'FileSize',
    condition = buffer_not_empty,
    highlight = {colors.fg,colors.bg}
  }
}
gls.left[4] ={
  FileIcon = {
    provider = 'FileIcon',
    condition = buffer_not_empty,
    highlight = {require('galaxyline.provider_fileinfo').get_file_icon_color,colors.bg},
  },
}

gls.left[5] = {
  FileName = {
    provider = {'FileName'},
    condition = buffer_not_empty,
    highlight = {colors.green,colors.bg,'bold'}
  }
}

gls.left[6] = {
  LineInfo = {
    provider = 'LineColumn',
    separator = ' ',
    separator_highlight = {'NONE',colors.bg},
    highlight = {colors.fg,colors.bg},
  },
}

gls.left[7] = {
  PerCent = {
    provider = 'LinePercent',
    separator = ' ',
    separator_highlight = {'NONE',colors.bg},
    highlight = {colors.fg,colors.bg,'bold'},
  }
}

gls.left[8] = {
  LeftEnd = {
    provider = function() return require('lsp-status').status() end,
    highlight = {colors.fg,colors.bg,'bold'},
  }
}

gls.left[9] = {
  DiagnosticError = {
    provider = 'DiagnosticError',
    icon = '',
    highlight = {colors.red,colors.bg}
  }
}
gls.left[10] = {
  DiagnosticWarn = {
    provider = 'DiagnosticWarn',
    icon = '',
    highlight = {colors.yellow,colors.bg},
  }
}

gls.left[11] = {
  DiagnosticHint = {
    provider = 'DiagnosticHint',
    icon = '',
    highlight = {colors.cyan,colors.bg},
  }
}

gls.left[12] = {
  DiagnosticInfo = {
    provider = 'DiagnosticInfo',
    icon = '',
    highlight = {colors.blue,colors.bg},
  }
}

gls.right[1] = {
  FileEncode = {
    provider = 'FileEncode',
    separator = ' ',
    separator_highlight = {'NONE',colors.bg},
    highlight = {colors.cyan,colors.bg,'bold'}
  }
}

gls.right[2] = {
  FileFormat = {
    provider = 'FileFormat',
    separator = ' ',
    separator_highlight = {'NONE',colors.bg},
    highlight = {colors.cyan,colors.bg,'bold'}
  }
}

gls.right[3] = {
  GitIcon = {
    provider = function() return '' end,
    condition = require('galaxyline.provider_vcs').check_git_workspace,
    separator = ' ',
    separator_highlight = {'NONE',colors.bg},
    highlight = {colors.violet,colors.bg,'bold'},
  }
}

gls.right[4] = {
  GitBranch = {
    provider = 'GitBranch',
    condition = require('galaxyline.provider_vcs').check_git_workspace,
    highlight = {colors.violet,colors.bg,'bold'},
  }
}

local checkwidth = function()
  local squeeze_width  = vim.fn.winwidth(0) / 2
  if squeeze_width > 40 then
    return true
  end
  return false
end

gls.right[5] = {
  DiffAdd = {
    provider = 'DiffAdd',
    condition = checkwidth,
    icon = '',
    highlight = {colors.green,colors.bg},
  }
}
gls.right[6] = {
  DiffModified = {
    provider = 'DiffModified',
    condition = checkwidth,
    icon = '',
    highlight = {colors.orange,colors.bg},
  }
}
gls.right[7] = {
  DiffRemove = {
    provider = 'DiffRemove',
    condition = checkwidth,
    icon = '',
    highlight = {colors.red,colors.bg},
  }
}

gls.right[8] = {
  RainbowBlue = {
    provider = function() return '' end,
    highlight = {colors.blue,colors.bg}
  },
}

gls.short_line_left[1] = {
  BufferType = {
    provider = 'FileTypeName',
    separator = ' ',
    separator_highlight = {'NONE',colors.bg},
    highlight = {colors.blue,colors.bg,'bold'}
  }
}

gls.short_line_left[2] = {
  SFileName = {
    provider = function ()
      local fileinfo = require('galaxyline.provider_fileinfo')
      local fname = fileinfo.get_current_file_name()
      for _,v in ipairs(gl.short_line_list) do
        if v == vim.bo.filetype then
          return ''
        end
      end
      return fname
    end,
    condition = buffer_not_empty,
    highlight = {colors.white,colors.bg,'bold'}
  }
}

gls.short_line_right[1] = {
  BufferIcon = {
    provider= 'BufferIcon',
    highlight = {colors.fg,colors.bg}
  }
}

@cjgratacos
Copy link
Author

#file:language-servers/java-lsp.sh
#!/usr/bin/env bash

JAR="$HOME/.local/share/lsp/jdtls-server/plugins/org.eclipse.equinox.launcher_*.jar"

GRADLE_HOME="$HOME/.sdkman/candidates/gradle/current/" GRADLE_USER_HOME="$HOME/.gradle" java \
  -javaagent:$HOME/.local/share/lsp/lombok.jar \
  -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 \
  -Xms1g \
  -Xmx2G \
  -jar $(echo "$JAR") \
  -configuration "$HOME/.local/share/lsp/jdtls-server/config_linux" \
  -data "$1" \
  --add-modules=ALL-SYSTEM \
  --add-opens java.base/java.util=ALL-UNNAMED \
  --add-opens java.base/java.lang=ALL-UNNAMED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment