From 0709b64a716a89010323065cafb3cf503a62c06a Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Sun, 25 Aug 2024 23:44:07 -0700 Subject: [PATCH] gopls configured, but cmp broken --- home/profiles/nvim/config/fnl/conf/init.fnl | 13 +- home/profiles/nvim/config/fnl/conf/lsp.fnl | 111 +++++++++ .../nvim/config/fnl/conf/mappings.fnl | 51 ++++- home/profiles/nvim/config/fnl/conf/music.fnl | 4 + .../profiles/nvim/config/fnl/conf/plugins.fnl | 3 +- .../nvim/config/fnl/conf/plugins/cmp.fnl | 57 +++++ .../nvim/config/fnl/conf/plugins/kitaab.fnl | 11 + home/profiles/nvim/config/fnl/lib/nvim.fnl | 4 +- home/profiles/nvim/default.nix | 213 +----------------- 9 files changed, 250 insertions(+), 217 deletions(-) create mode 100644 home/profiles/nvim/config/fnl/conf/plugins/cmp.fnl create mode 100644 home/profiles/nvim/config/fnl/conf/plugins/kitaab.fnl diff --git a/home/profiles/nvim/config/fnl/conf/init.fnl b/home/profiles/nvim/config/fnl/conf/init.fnl index ab48e1b7..2408d1f3 100644 --- a/home/profiles/nvim/config/fnl/conf/init.fnl +++ b/home/profiles/nvim/config/fnl/conf/init.fnl @@ -16,6 +16,15 @@ (nvim.opt :showtabline 2) (nvim.opt :expandtab true) (nvim.opt :autowriteall true) +(nvim.opt :cmdheight 2) +(nvim.opt :spelllang "en_gb") +(nvim.opt :ignorecase true) +(nvim.opt :smartcase true) +(nvim.opt :incsearch true) +(nvim.opt :updatetime 300) ; Diagnostics response time +(nvim.opt :signcolumn "yes") +(nvim.opt :cursorline true) + (nvim.opt :lisp true) ; include - in word to move better in snake-case) (nvim.g :sexp_filetypes "clojure,scheme,lisp,janet,fennel,yuck") ; include the lisps I use @@ -26,4 +35,6 @@ (require :conf.plugins) (require :conf.mappings) (require :conf.lsp) -(require :conf.formatting) +(require :conf.plugins.cmp) +; (require :conf.formatting) +; (require :conf.kitaab) diff --git a/home/profiles/nvim/config/fnl/conf/lsp.fnl b/home/profiles/nvim/config/fnl/conf/lsp.fnl index a9eb8fe0..db20ecab 100644 --- a/home/profiles/nvim/config/fnl/conf/lsp.fnl +++ b/home/profiles/nvim/config/fnl/conf/lsp.fnl @@ -1,7 +1,118 @@ +; (local lspfuzzy (require :lspfuzzy)) +(local lspkind (require :lspkind)) +(local lspconfig (require :lspconfig)) +(local cmp (require :cmp)) +(local nvim (require :lib/nvim)) +; (local sg (require :sg)) +; (local lsputil (require :lspconfig/util)) +(tset vim.lsp.handlers + :textDocument/hover + (vim.lsp.with vim.lsp.handlers.hover + {:focusable false :border "rounded"})) + +(tset vim.lsp.handlers + :textDocument/signatureHelp + (vim.lsp.with vim.lsp.handlers.signature_help + {:focusable false :border "rounded"})) + +(local capabilities (let [cmp_nvim_lsp (require :cmp_nvim_lsp)] + (cmp_nvim_lsp.default_capabilities))) + +(local formatting-augroup (nvim.augroup :LspFormatting)) + +(fn goimports [wait-ms] + (let [params (vim.lsp.util.make_range_params) + result (do + (tset params :context {:only [:source.organizeImports]}) + (vim.lsp.buf_request_sync 0 :textDocument/codeAction params wait-ms))] + (each [_ res (pairs (or result {}))] + (each [_ r (pairs (or res.result {}))] + (if r.edit + (vim.lsp.util.apply_workspace_edit r.edit "utf-16") + (vim.lsp.buf.execute_command r.command)))) + (vim.lsp.buf.format))) + +(fn on-attach [client bufnr] + (let [filetype (vim.api.nvim_buf_get_option 0 "filetype")] + (if (client.supports_method "textDocument/formatting") + (do (nvim.autocmd "BufWritePre" + {:group formatting-augroup + :buffer bufnr + :callback (fn [_] (if (= filetype "go") + (goimports 2000) + (vim.lsp.buf.format {:bufnr bufnr})))}))))) + +(lspconfig.gopls.setup + {:capabilities capabilities + :codelens {:generate true :gc_details true} + :semanticTokens true + :flags { :debounce_text_changes 200} + :analyses {:unusedparams true + :unusedvariables true + :unusedwrite true + :nilness true + :unusedwrite true + :useany true} + :completeUnimported true + :staticcheck true + :experimentalPostfixCompletions true + :hints {:constantValues true + :functionTypeParameters true + :assignVariablesTypes true + :compositeLiteralTypes true + :compositeLiteralFields true + :parameterNames true + :rangeVariableTypes true} + :on_attach on-attach}) + + +; # local servers = { 'clojure_lsp', 'terraform_lsp', 'zls', 'pyright', 'rust_analyzer', 'tsserver', 'lua_ls', 'nil_ls', 'gopls'} +; # for _, lsp in ipairs(servers) do +; # lspconfig[lsp].setup {} +; # on_attach = function(client, bufnr) +; # format.on_attach(client) +; # navic.attach(client, bufnr) +; # end, +; # capabilities = capabilities, +; # +; # end) +;; Diagnostics Config I don't yet understand ; Set Diagnostics ; local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } ; for type, icon in pairs(signs) do ; local hl = "DiagnosticSign" .. type ; vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl}) ; end + +; vim.g.diagnostics_active = true +; function _G.toggle_diagnostics() +; if vim.g.diagnostics_active then +; vim.g.diagnostics_active = false +; vim.lsp.diagnostic.clear(0) +; vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end +; else +; vim.g.diagnostics_active = true +; vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( +; vim.lsp.diagnostic.on_publish_diagnostics, { +; virtual_text = true, +; signs = true, +; underline = true, +; update_in_insert = false, +; } +; ) +; end +; end +; +; vim.diagnostic.config({ +; signs = true, +; update_in_insert = false, +; underline = false, +; severity_sort = true, +; float = { +; focusable = false, +; style = 'minimal', +; border = 'rounded', +; source = 'always', +; }, +; }) diff --git a/home/profiles/nvim/config/fnl/conf/mappings.fnl b/home/profiles/nvim/config/fnl/conf/mappings.fnl index b21806a4..97633298 100644 --- a/home/profiles/nvim/config/fnl/conf/mappings.fnl +++ b/home/profiles/nvim/config/fnl/conf/mappings.fnl @@ -5,13 +5,33 @@ (nvim.keymap [:v] "<" "" ">gv" {:noremap true}) (nvim.keymap [:n] "" "" {:noremap true :silent true}) +;; Convenient way to move stuff in visual mode +(nvim.keymap [:v] "J" ":m '>+1gv=gv" {:noremap true}) +(nvim.keymap [:v] "K" ":m '>-2gv=gv" {:noremap true}) +;; Convientent screen shifting +(nvim.keymap [:n] "n" "nzzzv" {:noremap true}) +(nvim.keymap [:n] "N" "Nzzzv" {:noremap true}) +(nvim.keymap [:n] "J" "mzJ'z" {:noremap true}) +; Fix Y +(nvim.keymap [:n] "Y" "y$") +; Unmap Q +(nvim.keymap [] "Q" "") +; FTerm (vim.api.nvim_create_user_command "FTermToggle" (fn [_] ((-> (require :FTerm) (. :toggle)))) {:bang true}) (nvim.keymap [:t] "" ":FTermToggle") -(nvim.keymap [:n] "" ":FTermToggle" {:nnoremap true}) +(nvim.keymap [:n] "" ":FTermToggle" {:noremap true}) + +; Buffer Movement +(nvim.keymap [:n] "gT" ":BufferPrevious" {:silent true :noremap true}) +(nvim.keymap [:n] "gt" ":BufferNext" {:silent true :noremap true}) +(nvim.keymap [:n] "gj" ":BufferPick" {:silent true :noremap true}) +(nvim.keymap [:n] "gb" ":Telescope buffers" {:silent true :noremap true}) +(nvim.keymap [:n] "gq" ":BufferClosoe" {:silent true :noremap true}) + (local normal-map-leader @@ -23,6 +43,8 @@ "Quit"] "r" [":RainbowParenthesesToggleAll" "Toggle Rainbow Parens"] + "u" [":UndotreeToggle" + "Toggle Undo Tree"] ; Telescope "f" {:name "Files" :f ["Telescope find_files" @@ -51,16 +73,17 @@ "Git Diff"] "h" ["" "Commit Hunk under Cursor"]} - ; nmap gl :diffget //3 - ; nmap gh :diffget //2 - ; nnoremap gc :G commit -v -q %:p + ; For handling merges + ; nmap gl :diffget //3 + ; nmap gh :diffget //2 + ; nnoremap gc :G commit -v -q %:p ; Buffers "b" {:name "Buffer" - :a ["" - "Buffer Add"] - :q ["" + :b [":Telescope buffers" + "Buffer List"] + :q [":BufferClose" "Buffer Quit"] - :n ["" + :n [":BufferNext" "Buffer Next"] :N [":tabp" "Buffer Previous"] @@ -89,8 +112,16 @@ :h [":Lspsaga hover_doc" "Hover doc"] :o [":LSoutlineToggle" - "Outline"]} + "Outline"] + :t [":call v:lua.toggle_diagnostics()"]} ; Kitaab - "z" {:name "Kitaab"}}) + "z" {:name "Kitaab" + :n [":ZettelNew" + "Zettel New"]} + "v" {:name "Tabs" + :v [":vnew" + "Vertical Split"] + :h [":new" + "Horizontal Split"]}}) (wk.register normal-map-leader {:prefix ""}) diff --git a/home/profiles/nvim/config/fnl/conf/music.fnl b/home/profiles/nvim/config/fnl/conf/music.fnl index e69de29b..81136de1 100644 --- a/home/profiles/nvim/config/fnl/conf/music.fnl +++ b/home/profiles/nvim/config/fnl/conf/music.fnl @@ -0,0 +1,4 @@ +(local nvim (require :lib/nvim)) + +(nvim.g :tidal_target "terminal") +(nvim.g :scnvim_snippet_format "luasnip") diff --git a/home/profiles/nvim/config/fnl/conf/plugins.fnl b/home/profiles/nvim/config/fnl/conf/plugins.fnl index c2f7003a..9b9ef6f1 100644 --- a/home/profiles/nvim/config/fnl/conf/plugins.fnl +++ b/home/profiles/nvim/config/fnl/conf/plugins.fnl @@ -1,7 +1,5 @@ (local nvim (require :lib/nvim)) -(nvim.g :tidal_target "terminal") - (local navic (require :nvim-navic)) (let [lualine (require :lualine)] @@ -9,6 +7,7 @@ :sections {:lualine_c [:filename {1 navic.get_location :cond navic.is_available}] :lualine_y [(fn [] + ; TODO broken? (let [msg "No Active Lsp" buf_ft (vim.api.nvim_buf_get_option 0 "filetype") clients (vim.lsp.get_active_clients)] diff --git a/home/profiles/nvim/config/fnl/conf/plugins/cmp.fnl b/home/profiles/nvim/config/fnl/conf/plugins/cmp.fnl new file mode 100644 index 00000000..0ccead0c --- /dev/null +++ b/home/profiles/nvim/config/fnl/conf/plugins/cmp.fnl @@ -0,0 +1,57 @@ +(local cmp (require :cmp)) + +(fn has-words-before [] + (let [(line col) (unpack (vim.api.nvim_win_get_cursor 0)) + cur-line (. (vim.api.nvim_buf_get_lines 0 + (- line 1) + line + true + 1))] + (and (not= col 0) + (= (: (: cur-line :sub col col) :match "%s") + nil)))) + +(fn tab [fallback] + (let [cmp (require :cmp) + luasnip (require :luasnip)] + (if (cmp.visible) + (cmp.select_next_item) + (let [available (luasnip.expand_or_jumpable)] + (if (= (available) true) + (luasnip.expand_or_jump) + (if (has-words-before) + (cmp.complete) + (fallback))))))) + +(fn stab [fallback] + (let [cmp (require :cmp) + luasnip (require :luasnip)] + (if (cmp.visible) + (cmp.select_prev_item) + (let [available (luasnip.jumpable -1)] + (if (= (available) true) + (luasnip.jump -1) + (if (has-words-before) + (cmp.complete) + (fallback))))))) + +(let [lspkind (require :lspkind) + luasnip_loaders (require :luasnip.loaders.from_vscode)] + (luasnip_loaders.lazy_load) + (cmp.setup {:formatting {:format lspkind.cmp_format} + :snippet {:expand (fn [args] + (let [luasnip (require :luasnip)] + (luasnip.lsp_expand args.body)))} + :sources [{:name "buffer"} {:name "nvim_lsp"} + {:name "look"} {:name "path"} + {:name "calc"} {:name "spell"} + {:name "cmp-conjure"} {:name "luasnip"} + {:name "tags"}] + :mapping {"" (cmp.mapping.scroll_docs -4) + "" (cmp.mapping.scroll_docs 4) + "" (cmp.mapping (cmp.mapping.select_prev_item) [:i :c]) + "" (cmp.mapping (cmp.mapping.select_next_item) [:i :c]) + "" (cmp.mapping.close) + "" (cmp.mapping.confirm {:select true}) + "" (cmp.mapping tab [:i :s]) + "" (cmp.mapping stab [:i :s])}})) diff --git a/home/profiles/nvim/config/fnl/conf/plugins/kitaab.fnl b/home/profiles/nvim/config/fnl/conf/plugins/kitaab.fnl new file mode 100644 index 00000000..990752e1 --- /dev/null +++ b/home/profiles/nvim/config/fnl/conf/plugins/kitaab.fnl @@ -0,0 +1,11 @@ +(local nvim (require :lib/nvim)) + +(nvim.g :vimwiki_list [{:path "~/kitaab/vimwiki" + :auto_tags 1 + :auto_diary_index 1 + :auto_generate_links 0 + :nested_syntaxes {:python "python" + :c++ "cpp" + :nix "nix" + :bash "sh"}}]) +(nvim.g :zettel_format "%y%m%d-%H%M") diff --git a/home/profiles/nvim/config/fnl/lib/nvim.fnl b/home/profiles/nvim/config/fnl/lib/nvim.fnl index c62cbe3e..a79d3013 100644 --- a/home/profiles/nvim/config/fnl/lib/nvim.fnl +++ b/home/profiles/nvim/config/fnl/lib/nvim.fnl @@ -8,13 +8,13 @@ (fn augroup [name ?opts] "Create autocommand group" - (vim.api.nvim_create_augroup name (or opts {}))) + (vim.api.nvim_create_augroup name (or ?opts {}))) (fn keymap [mode lhs rhs ?opts] "Sets a global mapping for the given mode. Ex: `(keymap [:n :i] ...)`" (let [string-mode (table.concat mode)] - (vim.api.nvim_set_keymap string-mode lhs rhs (or opts {})))) + (vim.api.nvim_set_keymap string-mode lhs rhs (or ?opts {})))) (fn opt [key value] "Set a vim option" diff --git a/home/profiles/nvim/default.nix b/home/profiles/nvim/default.nix index 65182a55..69d16bc6 100644 --- a/home/profiles/nvim/default.nix +++ b/home/profiles/nvim/default.nix @@ -28,13 +28,17 @@ # kitaab get by tagged kt = "cd /home/anish/kitaab/vimwiki; eza *_index.wiki | fzf --preview 'bat --style=numbers --color=always --terminal-width -1 ./{}';cd $OLDPWD"; }; - # Add %update to the highlight clause for vimwiki files - home.file.".config/nvim/after/syntax/vimwiki.vim".text = '' - " match with %update - syntax match VimwikiPlaceholder /^\s*%update\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite - " match with %link - syntax match VimwikiPlaceholder /^\s*%link\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite - ''; + + home.file = { + # Add %update to the highlight clause for vimwiki files + # ".config/nvim/after/syntax/vimwiki.vim".text = '' + # " match with %update + # syntax match VimwikiPlaceholder /^\s*%update\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite + # " match with %link + # syntax match VimwikiPlaceholder /^\s*%link\ze\%(\s.*\)\?$/ nextgroup=VimwikiPlaceholderParam skipwhite + # ''; + ".config/nvim".source = ./config; + }; #environment.systemPackages = with customPlugins; [ tidal ]; programs.neovim = { @@ -43,138 +47,17 @@ # extraConfig = '' # filetype plugin on - # " set spell - # set spelllang=en_gb - # set ignorecase - # set smartcase - # set incsearch - # " if hidden is not set, TextEdit might fail. - # set hidden - # " Some servers have issues with backup files, see #649 - # set nobackup - # set nowritebackup - # " Better display for messages - # set cmdheight=2 - # " You will have bad experience for diagnostic messages when it's default 4000. - # set updatetime=300 - # " don't give |ins-completion-menu| messages. # set shortmess+=c # " always show signcolumns - # set signcolumn=yes - # " highlight row - # set cursorline - # let g:conjure#filetype#fennel = "conjure.client.fennel.stdio" - # " we only use fennel with love; no we don't... - # let g:conjure#client#fennel#stdio#command = "fennel" - # " let g:conjure#extract#tree_sitter#enabled = true - # map lt :ConjureLogToggle - - # let g:rainbow_active = 0 - # autocmd BufReadPost,BufNewFile c,clj,cljs RainbowParenthesesToggleAll - - # " general commands - # nnoremap :noh - # map Q - # nnoremap Y y$ - # nnoremap n :vnew - # " center moving - # nnoremap n nzzzv - # nnoremap N Nzzzv - # nnoremap J mzJ'z - # " undo points - # inoremap , ,u - # inoremap . .u - # inoremap ? ?u - # inoremap ! !u - # inoremap ) )u - # inoremap [ [u - # inoremap ] ]u - # inoremap { {u - # inoremap ( (u - # inoremap } }u - # " moving text - # vnoremap J :m '>+1gv=gv - # vnoremap K :m '>-2gv=gv - # inoremap :m .+1== - # inoremap :m .-2== - # nnoremap j :m .+1== - # nnoremap k :m .-2== # " Pasting # :map sy :!xclip -i # :vmap sy "*y # :map sp :r!xclip -o - # " barbar - # nnoremap gT :BufferPrevious - # nnoremap gt :BufferNext - # nnoremap gj :BufferPick - # nnoremap gq :BufferClose - - # " kitaab - # map cz :VimwikiIndex:ZettelNew - # map zs :ZettelSearch - # map zn :ZettelNew - # map zo :ZettelOpen - # map zf :Telescope oldfiles only_cwd=true - # map wt :VimwikiMakeTomorrowDiaryNote - # map wd :VimwikiMakeYesterdayDiaryNote - # map zm :ZenMode:setlocal nospell - # let g:vimwiki_list = [{ 'path': '~/kitaab/vimwiki', 'auto_tags': 1, 'auto_diary_index': 1, 'auto_generate_links': 0, 'nested_syntaxes': {'python': 'python', 'c++': 'cpp', 'nix': 'nix', 'bash': 'sh'} }] - # let g:sync_taskwarrior = 0 - # let g:zettel_format = "%y%m%d-%H%M" - - - # let g:scnvim_snippet_format = "luasnip" - - # " lua config # lua <vt', ':call v:lua.toggle_diagnostics()', {noremap = true, silent = true}) - # -- autopairs # require('nvim-autopairs').setup{} @@ -193,15 +74,9 @@ # require('marks').setup{} # -- Setup nvim-cmp. - # local has_words_before = function() - # local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - # return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil - # end # local luasnip = require("luasnip") # local lspkind = require("lspkind") - # local cmp = require('cmp') - # local cmp_autopairs = require('nvim-autopairs.completion.cmp') # local t = function(str) # return vim.api.nvim_replace_termcodes(str, true, true, true) # end @@ -209,61 +84,6 @@ # local col = vim.fn.col(".") - 1 # return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil # end - # cmp.setup { - # formatting = { - # format = lspkind.cmp_format({ - # mode = 'symbol_text', - # maxwidth = 50, - # }) - # }, - # mapping = { - # [''] = cmp.mapping.select_prev_item(), - # [''] = cmp.mapping.select_next_item(), - # [''] = cmp.mapping.scroll_docs(-4), - # [''] = cmp.mapping.scroll_docs(4), - # [''] = cmp.mapping.complete(), - # [''] = cmp.mapping.close(), - # [''] = cmp.mapping.confirm({ - # behavior = cmp.ConfirmBehavior.Insert, - # select = true - # }), - # [""] = cmp.mapping(function(fallback) - # if cmp.visible() then - # cmp.select_next_item() - # elseif luasnip.expand_or_jumpable() then - # luasnip.expand_or_jump() - # elseif has_words_before() then - # cmp.complete() - # else - # fallback() - # end - # end, {"i", "s"}), - # [""] = cmp.mapping(function(fallback) - # if cmp.visible() then - # cmp.select_prev_item() - # elseif luasnip.jumpable(-1) then - # luasnip.jump(-1) - # else - # fallback() - # end - # end, { "i", "s" }), - # }, - # snippet = { - # expand = function(args) - # require'luasnip'.lsp_expand(args.body) - # end - # }, - # sources = { - # {name = 'buffer'}, {name = 'nvim_lsp'}, - # {name = "look"}, {name = "path"}, - # {name = "calc"}, {name = "spell"}, - # {name = 'cmp-conjure'}, {name = "luasnip"}, - # {name = 'tags'} - # }, - # completion = {completeopt = 'menu,menuone,noinsert'} - # } - # cmp.event:on( 'confirm_done', cmp_autopairs.on_confirm_done({ map_char = { tex = ' ' } })) - # require("luasnip.loaders.from_vscode").lazy_load() # -- null-ls # -- being very janky @@ -320,7 +140,6 @@ # }, # }) - # capabilities = require('cmp_nvim_lsp').default_capabilities() # -- fennel-ls is bleeding edge # local lspconfig = require('lspconfig') @@ -333,16 +152,6 @@ # } # } - # local servers = { 'clojure_lsp', 'terraform_lsp', 'zls', 'pyright', 'rust_analyzer', 'tsserver', 'lua_ls', 'nil_ls', 'gopls'} - # for _, lsp in ipairs(servers) do - # lspconfig[lsp].setup { - # on_attach = function(client, bufnr) - # format.on_attach(client) - # navic.attach(client, bufnr) - # end, - # capabilities = capabilities, - # } - # end # -- fennel-ls doesn't support gps # lspconfig['fennel-ls'].setup {