a1798b64f670bfad5caa1c4d9526625f0e7a6d5f — Maarten Vos 3 months ago df5f4d1
setup nvim lsp
3 files changed, 98 insertions(+), 12 deletions(-)

M .config/nvim/init.vim
A .config/nvim/lua/lsp_config.lua
M .profile
M .config/nvim/init.vim => .config/nvim/init.vim +11 -7
@@ 1,21 1,21 @@
call plug#begin('~/.vim/plugged')
"Plug 'chriskempson/base16-vim' 
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'neovim/nvim-lspconfig'

Plug 'https://git.sr.ht/~sircmpwn/hare.vim'
Plug 'morhetz/gruvbox'
call plug#end()

set tw=80
set nocompatible
set termguicolors
set tw=80 " Wrap text at 80 characters
set nocompatible " We don't care about vi compatibility here
set termguicolors " Use correct colors
set number " Show absolute line numbers on the left.
set relativenumber " Show relative line numbers on the left. These change based upon where your cursor is.
set ai " Sets auto-indentation
set si " Sets smart-indentation
set noswapfile " Prevent vim from creating .swp files
set expandtab " Use spaces instead of a tab charate on TAB
set tabstop=4
set shiftwidth=4
set tabstop=4 " Sets the amount of spaces used when pressing TAB
set shiftwidth=4 " Sets the amount of space used for >>
set wrap " Wrap overflowing lines
set hlsearch " When searching (/), highlights matches as you go
set ignorecase " When searching (/), ignore case entirely

@@ 25,3 25,7 @@ set encoding=utf8 " Set text encoding as utf8
filetype plugin on " Auto-detect un-labeled filetypes
colorscheme gruvbox
syntax on " Turn syntax highlighting on

lua require("lsp_config")

autocmd BufWritePre * lua vim.lsp.buf.formatting()

A .config/nvim/lua/lsp_config.lua => .config/nvim/lua/lsp_config.lua +85 -0
@@ 0,0 1,85 @@
local nvim_lsp = require('lspconfig')

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true

local on_attach = function(client, bufnr)
  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', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
  buf_set_keymap('n', 'ga', '<Cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
  buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
  buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
  buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)

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

  -- Set autocommands conditional on server_capabilities
  if client.resolved_capabilities.document_highlight then
      hi LspReferenceRead cterm=bold ctermbg=DarkMagenta guibg=LightYellow
      hi LspReferenceText cterm=bold ctermbg=DarkMagenta guibg=LightYellow
      hi LspReferenceWrite cterm=bold ctermbg=DarkMagenta guibg=LightYellow
      augroup lsp_document_highlight
        autocmd! * <buffer>
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]], false)

	cmd = {'gopls'},
	-- for postfix snippets and analyzers
	capabilities = capabilities,
	    settings = {
	      gopls = {
		      experimentalPostfixCompletions = true,
		      analyses = {
		        unusedparams = true,
		        shadow = true,
		     staticcheck = true,
	on_attach = on_attach,

    on_attach = on_attach,
    cmd = {
  filetypes = {"c"},

M .profile => .profile +2 -5
@@ 1,11 1,8 @@
[ -f ~/.bashrc ] && . ~/.bashrc


if [ "$XDG_SESSION_TYPE" == "wayland" ]; then

export GOPATH=~/.local/share/go
export GOPROXY=direct