diff --git a/home/editors/default.nix b/home/editors/default.nix index 47e7d23..e26a664 100644 --- a/home/editors/default.nix +++ b/home/editors/default.nix @@ -1,16 +1,9 @@ { config, pkgs, ... }: { - imports = [ - ./lsp.nix - ./neovim.nix - ./vscode.nix - ]; + imports = [ ./lsp.nix ./neovim ./vscode.nix ]; - home.packages = with pkgs; [ - fzf - ripgrep - ]; + home.packages = with pkgs; [ fzf ripgrep ]; home.sessionVariables = with pkgs; { EDITOR = "nvim"; diff --git a/home/editors/lsp.vim b/home/editors/lsp.vim deleted file mode 100644 index 20c0866..0000000 --- a/home/editors/lsp.vim +++ /dev/null @@ -1,194 +0,0 @@ -" autocomplete config -set completeopt=menu,preview,menuone,noinsert -set omnifunc=v:lua.vim.lsp.omnifunc - -let g:deoplete#enable_at_startup = 1 -let g:deoplete#smart_case = 1 - -" Use to trigger completion. -inoremap deoplete#manual_complete() - -" Autocomplete and cycle from top-to-bottom of suggestions using . -inoremap pumvisible() ? "\" : "\" - -" : completion. -inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : - \ deoplete#manual_complete() -inoremap pumvisible() ? "\" : "\" - -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" maps -nnoremap gd lua vim.lsp.buf.declaration() -nnoremap lua vim.lsp.buf.definition() -nnoremap K lua vim.lsp.buf.hover() -nnoremap gD lua vim.lsp.buf.implementation() -nnoremap lua vim.lsp.buf.signature_help() -nnoremap 1gD lua vim.lsp.buf.type_definition() -nnoremap gr lua vim.lsp.buf.references() -nnoremap g0 lua vim.lsp.buf.document_symbol() -nnoremap gW lua vim.lsp.buf.workspace_symbol() -nnoremap f lua vim.lsp.buf.formatting() -nnoremap a lua vim.lsp.buf.code_action() -nnoremap r lua vim.lsp.buf.rename() - -" nvim-lsp config -packloadall " https://github.com/neovim/neovim/issues/11407 -lua << EOF -local nvim_lsp = require'nvim_lsp' -local configs = require'nvim_lsp/configs' -local util = require'nvim_lsp/util' - --- format on save --- TODO often takes way longer to save than 1000 ms (e.g. 7000 ms in fitnesspilot-web) -local diagnosticls_on_attach = function(_, bufnr) - vim.api.nvim_command("au BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000)") -end - -nvim_lsp.bashls.setup{} -nvim_lsp.jsonls.setup{} -nvim_lsp.yamlls.setup{} -nvim_lsp.html.setup{} -nvim_lsp.cssls.setup{} -nvim_lsp.vimls.setup{} -nvim_lsp.dockerls.setup{} -nvim_lsp.rnix.setup{} -nvim_lsp.tsserver.setup{} -nvim_lsp.omnisharp.setup{ - cmd = {"omnisharp", "--languageserver"}; -} -nvim_lsp.pyls.setup{} -nvim_lsp.terraformls.setup{} -nvim_lsp.hls.setup{} - --- based on: https://github.com/mikew/vimrc/blob/master/src/nvim/coc-settings.json -nvim_lsp.diagnosticls.setup{ - on_attach = diagnosticls_on_attach; - filetypes = { - "javascript", - "javascript.jsx", - "javascriptreact", - "typescript", - "typescript.jsx", - "typescriptreact", - "json", - "yaml", - "markdown", - "html", - "css" - }; - init_options = { - linters = { - eslint = { - command = "eslint"; - args = { - "--stdin", - "--stdin-filename", - "%filepath", - "--format", - "json" - }; - rootPatterns = {".git"}; - debounce = 50; - sourceName = "eslint"; - parseJson = { - errorsRoot = "[0].messages"; - line = "line"; - column = "column"; - endLine = "endLine"; - endColumn = "endColumn"; - message = "${message} [${ruleId}]"; - security = "severity"; - }; - securities = { - ["2"] = "error"; - ["1"] = "warning"; - }; - }; - stylelint = { - command = "stylelint"; - args = { - "--stdin", - "--formatter", - "json", - "--file", - "%filepath" - }; - rootPatterns = {".git"}; - debounce = 50; - sourceName = "stylelint"; - parseJson = { - errorsRoot = "[0].warnings"; - line = "line"; - column = "column"; - message = "${text}"; - security = "severity"; - }; - securities = { - error = "error"; - warning = "warning"; - }; - }; - }; - filetypes = { - javascript = {"eslint"}; - ["javascript.jsx"] = {"eslint"}; - javascriptreact = {"eslint"}; - typescript = {"eslint"}; - ["typescript.jsx"] = {"eslint"}; - typescriptreact = {"eslint"}; - css = {"stylelint"}; - }; - formatters = { - eslint = { - command = "eslint"; - args = { - "--fix", - "%file" - }; - rootPatterns = {".git"}; - isStdout = 1; - doesWriteToFile = 1; - }; - stylelint = { - command = "stylelint"; - args = { - "--stdin", - "--fix", - "--file", - "%filepath" - }; - rootPatterns = {".git"}; - }; - prettier = { - command = "prettier"; - args = { - "--stdin", - "--stdin-filepath", - "%filepath" - }; - rootPatterns = {".git"}; - }; - }; - formatFiletypes = { - javascript = {"eslint"}; - ["javascript.jsx"] = {"eslint"}; - javascriptreact = {"eslint"}; - typescript = {"eslint"}; - ["typescript.jsx"] = {"eslint"}; - typescriptreact = {"eslint"}; - json = {"prettier"}; - yaml = {"prettier"}; - markdown = {"prettier"}; - html = {"prettier"}; - css = {"stylelint"}; - }; - }; -} - -EOF diff --git a/home/editors/neovim/dap.vim b/home/editors/neovim/dap.vim new file mode 100644 index 0000000..07789d9 --- /dev/null +++ b/home/editors/neovim/dap.vim @@ -0,0 +1,9 @@ +nnoremap :lua require'dap'.continue() +nnoremap :lua require'dap'.step_over() +nnoremap :lua require'dap'.step_into() +nnoremap :lua require'dap'.step_out() +nnoremap b :lua require'dap'.toggle_breakpoint() +nnoremap B :lua require'dap'.set_breakpoint(vim.fn.input('Breakpoint condition: ')) +nnoremap lp :lua require'dap'.set_breakpoint(nil, nil, vim.fn.input('Log point message: ')) +nnoremap dr :lua require'dap'.repl.open() +nnoremap dl :lua require'dap'.repl.run_last() diff --git a/home/editors/neovim.nix b/home/editors/neovim/default.nix similarity index 56% rename from home/editors/neovim.nix rename to home/editors/neovim/default.nix index 2e5e65c..e5de43b 100644 --- a/home/editors/neovim.nix +++ b/home/editors/neovim/default.nix @@ -2,16 +2,14 @@ let neovim-unwrapped = pkgs.neovim-unwrapped.overrideAttrs (oldAttrs: rec { - version = "2020-09-16"; + version = "2020-09-24"; src = pkgs.fetchFromGitHub { owner = "neovim"; repo = "neovim"; - rev = "c3f4610922b3f26c952281481f65d255ad352ac5"; - sha256 = "1pcrngx26mkxpcdz897nps1v6hvwq9phrx92bsyixsva5z9h468h"; + rev = "a958039f0ad7cd4f6a139fde18795c88c623a30e"; + sha256 = "04xkms6vvfa0zafvijw6mc88adfsmrksan8hg2p6jp0kwc5i9kqq"; }; - nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ - pkgs.utf8proc - ]; + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.utf8proc ]; }); buildVimPluginFrom2Nix = pkgs.vimUtils.buildVimPluginFrom2Nix; @@ -26,8 +24,27 @@ let sha256 = "15ysbbvxlgy1qx8rjv2i9pgjshldcs3m1ff0my2y5mnr3cpqb3s6"; }; }; -in -{ + + # not very stable yet, no existing netcoredbg config + nvim-dap = buildVimPluginFrom2Nix { + pname = "nvim-dap"; + version = "2020-09-14"; + src = pkgs.fetchFromGitHub { + owner = "mfussenegger"; + repo = "nvim-dap"; + rev = "d3af0f3b470ee8a46aabb3837b97193dc16046e0"; + sha256 = "0j09i8hhls8y5xd57vp4sbpp0gvdmwd6wmb355w5j2cda84xagmd"; + }; + }; + + vimLua = lua: '' + lua << EOF + ${lua} + EOF + ''; +in { + home.packages = with pkgs; [ graphviz ]; + programs.neovim = { enable = true; package = neovim-unwrapped; @@ -56,6 +73,7 @@ in wmgraphviz-vim nvim-lsp + nvim-dap # might require :UpdateRemotePlugins deoplete-nvim @@ -64,10 +82,12 @@ in vim-orgmode ]; extraConfig = with builtins; - readFile ./init.vim + - readFile ./vim-surround-fix.vim + - readFile ./which-key.vim + - readFile ./lsp.vim; + readFile ./init.vim + readFile ./vim-surround-fix.vim + + readFile ./which-key.vim + vimLua (readFile ./lsp/extensions.lua) + + readFile ./lsp/lsp.vim + '' + packloadall " https://github.com/neovim/neovim/issues/11409 + ${vimLua (readFile ./lsp/lsp.lua)} + ''; withNodeJs = true; withPython = false; }; diff --git a/home/editors/init.vim b/home/editors/neovim/init.vim similarity index 100% rename from home/editors/init.vim rename to home/editors/neovim/init.vim diff --git a/home/editors/neovim/lsp/extensions.lua b/home/editors/neovim/lsp/extensions.lua new file mode 100644 index 0000000..26f9af0 --- /dev/null +++ b/home/editors/neovim/lsp/extensions.lua @@ -0,0 +1,18 @@ +-- extensions for lsp functionality + +local function preview_location_callback(_, method, result) + if result == nil or vim.tbl_isempty(result) then + vim.lsp.log.info(method, 'No location found') + return nil + end + if vim.tbl_islist(result) then + vim.lsp.util.preview_location(result[1]) + else + vim.lsp.util.preview_location(result) + end +end + +function peek_definition() + local params = vim.lsp.util.make_position_params() + return vim.lsp.buf_request(0, 'textDocument/definition', params, preview_location_callback) +end diff --git a/home/editors/neovim/lsp/lsp.lua b/home/editors/neovim/lsp/lsp.lua new file mode 100644 index 0000000..897d5b9 --- /dev/null +++ b/home/editors/neovim/lsp/lsp.lua @@ -0,0 +1,151 @@ +local nvim_lsp = require'nvim_lsp' +local configs = require'nvim_lsp/configs' +local util = require'nvim_lsp/util' + +-- format on save +-- TODO often takes way longer to save than 1000 ms (e.g. 7000 ms in fitnesspilot-web) +local diagnosticls_on_attach = function(_, bufnr) + vim.api.nvim_command("au BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000)") +end + +nvim_lsp.bashls.setup{} +nvim_lsp.jsonls.setup{} +nvim_lsp.yamlls.setup{} +nvim_lsp.html.setup{} +nvim_lsp.cssls.setup{} +nvim_lsp.vimls.setup{} +nvim_lsp.dockerls.setup{} +nvim_lsp.rnix.setup{} +nvim_lsp.tsserver.setup{} +nvim_lsp.omnisharp.setup{ + cmd = {"omnisharp", "--languageserver"}; +} +nvim_lsp.pyls.setup{} +nvim_lsp.terraformls.setup{} +nvim_lsp.hls.setup{} + +-- based on: https://github.com/mikew/vimrc/blob/master/src/nvim/coc-settings.json +-- multiple LSP's currently not supported: https://github.com/neovim/neovim/issues/12755 +-- nvim_lsp.diagnosticls.setup{ +-- on_attach = diagnosticls_on_attach; +-- filetypes = { +-- "javascript", +-- "javascript.jsx", +-- "javascriptreact", +-- "typescript", +-- "typescript.jsx", +-- "typescriptreact", +-- "json", +-- "yaml", +-- "markdown", +-- "html", +-- "css" +-- }; +-- init_options = { +-- linters = { +-- eslint = { +-- command = "eslint"; +-- args = { +-- "--stdin", +-- "--stdin-filename", +-- "%filepath", +-- "--format", +-- "json" +-- }; +-- rootPatterns = {".git"}; +-- debounce = 50; +-- sourceName = "eslint"; +-- parseJson = { +-- errorsRoot = "[0].messages"; +-- line = "line"; +-- column = "column"; +-- endLine = "endLine"; +-- endColumn = "endColumn"; +-- message = "${message} [${ruleId}]"; +-- security = "severity"; +-- }; +-- securities = { +-- ["2"] = "error"; +-- ["1"] = "warning"; +-- }; +-- }; +-- stylelint = { +-- command = "stylelint"; +-- args = { +-- "--stdin", +-- "--formatter", +-- "json", +-- "--file", +-- "%filepath" +-- }; +-- rootPatterns = {".git"}; +-- debounce = 50; +-- sourceName = "stylelint"; +-- parseJson = { +-- errorsRoot = "[0].warnings"; +-- line = "line"; +-- column = "column"; +-- message = "${text}"; +-- security = "severity"; +-- }; +-- securities = { +-- error = "error"; +-- warning = "warning"; +-- }; +-- }; +-- }; +-- filetypes = { +-- javascript = {"eslint"}; +-- ["javascript.jsx"] = {"eslint"}; +-- javascriptreact = {"eslint"}; +-- typescript = {"eslint"}; +-- ["typescript.jsx"] = {"eslint"}; +-- typescriptreact = {"eslint"}; +-- css = {"stylelint"}; +-- }; +-- formatters = { +-- eslint = { +-- command = "eslint"; +-- args = { +-- "--fix", +-- "%file" +-- }; +-- rootPatterns = {".git"}; +-- isStdout = 1; +-- doesWriteToFile = 1; +-- }; +-- stylelint = { +-- command = "stylelint"; +-- args = { +-- "--stdin", +-- "--fix", +-- "--file", +-- "%filepath" +-- }; +-- rootPatterns = {".git"}; +-- }; +-- prettier = { +-- command = "prettier"; +-- args = { +-- "--stdin", +-- "--stdin-filepath", +-- "%filepath" +-- }; +-- rootPatterns = {".git"}; +-- }; +-- }; +-- formatFiletypes = { +-- javascript = {"eslint"}; +-- ["javascript.jsx"] = {"eslint"}; +-- javascriptreact = {"eslint"}; +-- typescript = {"eslint"}; +-- ["typescript.jsx"] = {"eslint"}; +-- typescriptreact = {"eslint"}; +-- json = {"prettier"}; +-- yaml = {"prettier"}; +-- markdown = {"prettier"}; +-- html = {"prettier"}; +-- css = {"stylelint"}; +-- }; +-- }; +-- } diff --git a/home/editors/neovim/lsp/lsp.vim b/home/editors/neovim/lsp/lsp.vim new file mode 100644 index 0000000..644cd45 --- /dev/null +++ b/home/editors/neovim/lsp/lsp.vim @@ -0,0 +1,39 @@ +" autocomplete config +set completeopt=menu,preview,menuone,noinsert +set omnifunc=v:lua.vim.lsp.omnifunc + +let g:deoplete#enable_at_startup = 1 +let g:deoplete#smart_case = 1 + +" Use to trigger completion. +inoremap deoplete#manual_complete() + +" Autocomplete and cycle from top-to-bottom of suggestions using . +inoremap pumvisible() ? "\" : "\" + +" : completion. +inoremap + \ pumvisible() ? "\" : + \ check_back_space() ? "\" : + \ deoplete#manual_complete() +inoremap pumvisible() ? "\" : "\" + +function! s:check_back_space() abort + let col = col('.') - 1 + return !col || getline('.')[col - 1] =~# '\s' +endfunction + +" maps +nnoremap gd lua vim.lsp.buf.definition() +nnoremap gp lua peek_definition() +nnoremap gy lua vim.lsp.buf.type_definition() +nnoremap gi lua vim.lsp.buf.implementation() +nnoremap gr lua vim.lsp.buf.references() +nnoremap gD lua vim.lsp.buf.declaration() +nnoremap K lua vim.lsp.buf.hover() +nnoremap lua vim.lsp.buf.signature_help() +nnoremap sd lua vim.lsp.buf.document_symbol() +nnoremap sw lua vim.lsp.buf.workspace_symbol() +nnoremap f lua vim.lsp.buf.formatting() +nnoremap a lua vim.lsp.buf.code_action() +nnoremap r lua vim.lsp.buf.rename() diff --git a/home/editors/vim-surround-fix.vim b/home/editors/neovim/vim-surround-fix.vim similarity index 100% rename from home/editors/vim-surround-fix.vim rename to home/editors/neovim/vim-surround-fix.vim diff --git a/home/editors/which-key.vim b/home/editors/neovim/which-key.vim similarity index 100% rename from home/editors/which-key.vim rename to home/editors/neovim/which-key.vim