~steef/dotfiles

00af385a6ee6dc8bfb34830619616468b4099ffb — Steef Hegeman 2 months ago 6f70268
nvim: initial tsserver lsp
2 files changed, 46 insertions(+), 11 deletions(-)

M .config/nvim/init.lua
M .config/nvim/lua/lsp.lua
M .config/nvim/init.lua => .config/nvim/init.lua +33 -2
@@ 17,10 17,18 @@ require('packer').startup(function(use)
  use { 'dart-lang/dart-vim-plugin', ft = 'dart' }
  use { 'rust-lang/rust.vim', ft = 'rust' }
  vim.g.dart_style_guide = 2
  use { 'https://git.sr.ht/~sircmpwn/hare.vim', ft = 'hare' }
  use 'neovim/nvim-lspconfig'
  use 'rmehri01/onenord.nvim'
  use 'sheerun/vim-polyglot'
  vim.g.polyglot_disabled = { 'sensible' }
  --use 'sheerun/vim-polyglot'
  --vim.g.polyglot_disabled = { 'sensible' }
  use 'L3MON4D3/LuaSnip' -- TODO: actually configure luasnip
  use 'saadparwaiz1/cmp_luasnip'
  use 'hrsh7th/cmp-nvim-lsp'
  use 'hrsh7th/cmp-buffer'
  use 'hrsh7th/cmp-path'
--use 'hrsh7th/cmp-cmdline' TODO
  use 'hrsh7th/nvim-cmp'
end)

-- LSP


@@ 28,6 36,29 @@ require('lsp')
vim.o.updatetime = 150
vim.o.completeopt = 'menu,noinsert'

-- Completions
local cmp = require 'cmp'
cmp.setup {
  snippet = {
    expand = function(args)
      require'luasnip'.lsp_expand(args.body)
    end,
  },
  mapping = cmp.mapping.preset.insert {
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-space>'] = cmp.mapping.complete(),
    ['<C-e>'] = cmp.mapping.abort(),
    ['<C-y>'] = cmp.mapping.confirm({ select = true }),
  },
  sources = cmp.config.sources({
    { name = 'nvim_lsp' },
    { name = 'luasnip' },
  }, {
    { name = 'buffer', keyword_length = 5 },
  })
}

-- Color scheme
vim.o.termguicolors = true
vim.cmd 'colorscheme onenord'

M .config/nvim/lua/lsp.lua => .config/nvim/lua/lsp.lua +13 -9
@@ 1,13 1,14 @@
-- TODO: decide on tabs/spaces
local nvim_lsp = require('lspconfig')

vim.diagnostic.config({
    virtual_text = false,
    virtual_text = true,
    signs = false,
    underline = true,
    update_in_insert = false,
    severity_sort = false,
})
vim.cmd 'autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})'
--vim.cmd 'autocmd CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})'

local on_attach = function(client, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end


@@ 43,12 44,15 @@ local on_attach = function(client, bufnr)
  buf_set_keymap('n', '<leader>cl', '<cmd>lua vim.lsp.codelens.run()<CR>', opts)
end

local servers = { 'hls' }
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
local servers = { 'hls', 'tsserver' } -- TODO: texlab
for _, lsp in ipairs(servers) do
    nvim_lsp[lsp].setup {
        on_attach = on_attach,
        flags = {
            debounce_text_changes = 150,
        }
    }
	nvim_lsp[lsp].setup {
		on_attach = on_attach,
		capabilities = capabilities,
		flags = {
			debounce_text_changes = 150,
		}
	}
end