almost at parity now, can dog food

Needs:
- surrond?
- diagnostics icons
- cmp still seems to shit the bed sometimes
- lspsaga breadcrumbs on lualine
- more which-key config!!
- tests on svelte / web dev
This commit is contained in:
Anish Lakhwara 2024-08-26 23:09:08 -07:00
parent 0709b64a71
commit 10f6614348
10 changed files with 184 additions and 261 deletions

View file

@ -0,0 +1,11 @@
(import-macros {: do-req } :lib/macros)
(do-req :conform :setup
{:formatters_by_ft {:lua ["stylua"]
:nix ["nixfmt"]
; :go ["goimports" "gofmt"] ; Go handled in special case
:terraform ["terraform_fmt"]
:sh ["shfmt"]
:bazel ["buildifier"]}
:format_on_save {:lsp_format "fallback"
:timeout_ms 500}})

View file

@ -25,7 +25,6 @@
(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
@ -36,5 +35,13 @@
(require :conf.mappings)
(require :conf.lsp)
(require :conf.plugins.cmp)
; (require :conf.formatting)
(require :conf.formatting)
; (require :conf.kitaab)
; Spelling
(vim.api.nvim_create_autocmd ["BufRead" "BufNewFile"]
{:pattern ["*.wiki" "*.txt" "*.md" "*.tex"]
:command "setlocal spell"})
(vim.api.nvim_create_autocmd ["FileType"]
{:pattern ["mail"]
:command "setlocal spell"})

View file

@ -1,10 +1,31 @@
; (local lspfuzzy (require :lspfuzzy))
(import-macros {: do-req } :lib/macros)
(local lspkind (require :lspkind))
(local lspconfig (require :lspconfig))
(local lspsaga (require :lspsaga))
(local cmp (require :cmp))
(local nvim (require :lib/nvim))
; (local lspfuzzy (require :lspfuzzy))
; (local sg (require :sg))
; (local lsputil (require :lspconfig/util))
; (local navic (require :nvim-navic))
(lspsaga.setup {:border_style "rounded"
:code_action_icon ""
:code_action_num_shortcut true
:code_action_lightbulb {
:enable false
}
; show outline
:show_outline {
:win_position "right"
:auto_enter true
:auto_preview true
:virt_text "┃"
:jump_key "o"
; auto refresh when change buffer
:auto_refresh true
}
})
(tset vim.lsp.handlers
:textDocument/hover
@ -66,53 +87,14 @@
:rangeVariableTypes true}
:on_attach on-attach})
(local lsps [:nil_ls :terraform_lsp :fennel_ls :tsserver])
(each [index lsp (ipairs lsps)]
((. (. lspconfig lsp) :setup) {}))
; # 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
; null-ls
(let [null-ls (require :null-ls)]
(null-ls.setup {:sources [;null-ls.builtins.diagnostics.shellcheck
null-ls.builtins.diagnostics.commitlint]}))
;null-ls.builtins.diagnostics.jsonlint]}))
;(null-ls.builtins.diagnostics.proselint.with {:filetypes ["vimwiki" "mail"]})]}))
; 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',
; },
; })

View file

@ -1,4 +1,6 @@
(local nvim (require :lib/nvim))
(import-macros {: do-req } :lib/macros)
(local wk (require :which-key))
;; Convenient way to indent stuff in visual mode
@ -30,8 +32,13 @@
(nvim.keymap [:n] "gt" ":BufferNext<CR>" {:silent true :noremap true})
(nvim.keymap [:n] "gj" ":BufferPick<CR>" {:silent true :noremap true})
(nvim.keymap [:n] "gb" ":Telescope buffers<CR>" {:silent true :noremap true})
(nvim.keymap [:n] "gq" ":BufferClosoe<CR>" {:silent true :noremap true})
(nvim.keymap [:n] "gq" ":BufferClose<CR>" {:silent true :noremap true})
; Flash
(vim.api.nvim_create_user_command "Flash" (fn [_] (do-req :flash :jump)) {})
(vim.api.nvim_create_user_command "FlashTreesitter" (fn [] (do-req :flash :treesitter)) {})
(nvim.keymap [:n] "f" "<cmd>Flash<CR>")
(nvim.keymap [:n] "s" "<cmd>FlashTreesitter<CR>")
(local
normal-map-leader
@ -111,9 +118,10 @@
"Rename Symbol"]
:h [":Lspsaga hover_doc<CR>"
"Hover doc"]
:o [":LSoutlineToggle<CR>"
:o ["<cmd>AerialToggle!<CR>"
"Outline"]
:t [":call v:lua.toggle_diagnostics()<CR>"]}
:t [":LspDiagnostics 0"
"Find Errors in Buffer"]}
; Kitaab
"z" {:name "Kitaab"
:n [":ZettelNew<CR>"

View file

@ -2,3 +2,29 @@
(nvim.g :tidal_target "terminal")
(nvim.g :scnvim_snippet_format "luasnip")
; -- supercollider
; local scnvim = require 'scnvim'
; local map = scnvim.map
; local map_expr = scnvim.map_expr
; scnvim.setup {
; keymaps = {
; ['<localleader>e'] = map('editor.send_line', {'i', 'n'}),
; ['<localleader>s'] = map_expr('CmdPeriod.run', {'i', 'n'}),
; ['<localleader>t'] = {
; map('editor.send_block', {'i', 'n'}),
; map('editor.send_selection', 'x'),
; },
; ['<CR>'] = map('postwin.toggle'),
; ['<M-CR>'] = map('postwin.toggle', 'i'),
; ['<M-L>'] = map('postwin.clear', {'n', 'i'}),
; ['<C-k>'] = map('signature.show', {'n', 'i'}),
; ['<F12>'] = map('sclang.hard_stop', {'n', 'x', 'i'}),
; ['<leader>st'] = map('sclang.start'),
; ['<leader>sk'] = map('sclang.recompile'),
; ['<F1>'] = map_expr('s.boot'),
; ['<F2>'] = map_expr('s.meter'),
; }
; }
; -- You gotta run :SCNvimGenerateAssets for this first
; -- require("luasnip").add_snippets("supercollider", require("scnvim/utils").get_snippets())

View file

@ -1,13 +1,14 @@
(local nvim (require :lib/nvim))
(local navic (require :nvim-navic))
(import-macros {: do-req } :lib/macros)
(let [lualine (require :lualine)]
(lualine.setup {:options {:theme "ayu"}
:sections {:lualine_c [:filename {1 navic.get_location
:cond navic.is_available}]
:lualine_y [(fn []
; TODO broken?
; TODO broken
(let [msg "No Active Lsp"
buf_ft (vim.api.nvim_buf_get_option 0 "filetype")
clients (vim.lsp.get_active_clients)]
@ -19,3 +20,25 @@
:lualine_x [:filetype]}}))
(require :neo-tree)
(do-req :gitsigns :setup)
(do-req :marks :setup)
(do-req :mini.pairs :setup)
(do-req :mini.diff :setup)
(do-req :mini.ai :setup)
;TODO (do-req :mini.surround :setup)
(do-req :todo-comments :setup)
(do-req :ibl :setup)
(do-req :nvim-treesitter.configs :setup {:highlight {:enable true}
:textobjects {:enable true}
:indent {:enable true}})
(do-req :treesitter-context :setup {:max_lines 5})
(do-req :auto-session :setup {:log_level "info"
:auto_session_suppress_dirs ["~/"]})
(nvim.opt :sessionoptions "blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal")
(do-req :aerial :setup {:on_attach (fn [bufnr]
(do
(vim.keymap.set "n" "{" "<cmd>AerialPrev<CR>" { :buffer bufnr})
(vim.keymap.set "n" "}" "<cmd>AerialNext<CR>" { :buffer bufnr})))})

View file

@ -11,47 +11,21 @@
(= (: (: 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)))}
(let [lspkind (require :lspkind)]
(cmp.setup {:formatting {:format lspkind.cmp_format
:show_labelDetails true}
;: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 {"<C-d>" (cmp.mapping.scroll_docs -4)
"<C-u>" (cmp.mapping.scroll_docs 4)
"<Up>" (cmp.mapping (cmp.mapping.select_prev_item) [:i :c])
"<Down>" (cmp.mapping (cmp.mapping.select_next_item) [:i :c])
"<C-g>" (cmp.mapping.close)
"<CR>" (cmp.mapping.confirm {:select true})
"<Tab>" (cmp.mapping tab [:i :s])
"<S-Tab>" (cmp.mapping stab [:i :s])}}))
"<CR>" (cmp.mapping.confirm {:select true})}}))
; "<Tab>" (cmp.mapping tab [:i :s])
; "<S-Tab>" (cmp.mapping stab [:i :s])}}))

View file

@ -1,5 +1,10 @@
; Kitaab is why I'm so tied to vim.
; If only I could find a nice notes editor...
(local nvim (require :lib/nvim))
(import-macros {: do-req } :lib/macros)
(nvim.g :vimwiki_list [{:path "~/kitaab/vimwiki"
:auto_tags 1
:auto_diary_index 1
@ -9,3 +14,22 @@
:nix "nix"
:bash "sh"}}])
(nvim.g :zettel_format "%y%m%d-%H%M")
; Custom functions
(fn update_date []
(var written false)
(let [time (os.date "%Y-%m-%d %H:%M")
message (.. "%update " time)
lines (vim.api.nvim_buf_get_lines 0 0 4 false)]
(each [index line (ipairs lines)]
(if (and (= (length line) 0) (not written))
(do
(vim.api.nvim_buf_set_lines 0 (- index 1) index false [message ""])
(set written true)))
(if (and (= index 4) (not written))
(vim.api.nvim_buf_set_lines 0 3 index false [message])))))
(vim.api.nvim_create_autocmd "BufWritePre" {:pattern ["*.wiki"]
:callback update_date})
(do-req :hologram :setup {:auto_display false})

View file

@ -0,0 +1,6 @@
(fn do-req [mod key ...]
`(let [name# (require ,mod)
fun# (. name# ,key)]
(fun# ,...)))
{: do-req}

View file

@ -22,6 +22,7 @@
{
home.sessionVariables.EDITOR = "nvim";
home.shellAliases = {
vim = "nvim";
k = "cd ~/kitaab/vimwiki; vim -c :VimwikiIndex; cd $OLDPWD";
# kitaab zettel
kz = "cd ~/kitaab/vimwiki; vim -c :VimwikiIndex -c :ZettelNew; cd $OLDPWD";
@ -48,7 +49,6 @@
# filetype plugin on
# set shortmess+=c
# " always show signcolumns
# " Pasting
# :map <leader>sy :!xclip -i<CR><CR>
@ -59,22 +59,8 @@
# lua <<EOF
# local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
# function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
# opts = opts or {}
# opts.border = opts.border or 'rounded'
# return orig_util_open_floating_preview(contents, syntax, opts, ...)
# end
# -- autopairs
# require('nvim-autopairs').setup{}
# -- marks
# require('marks').setup{}
# -- Setup nvim-cmp.
# local luasnip = require("luasnip")
# local lspkind = require("lspkind")
# local t = function(str)
@ -85,26 +71,9 @@
# return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil
# end
# -- null-ls
# -- being very janky
# local null_ls = require("null-ls")
# null_ls.setup({
# sources = {
# null_ls.builtins.diagnostics.shellcheck,
# null_ls.builtins.diagnostics.proselint.with({ filetypes = { "vimwiki", "mail", }, }),
# null_ls.builtins.diagnostics.commitlint,
# null_ls.builtins.diagnostics.jsonlint,
# -- null_ls.builtins.code_actions.statix,
# -- null_ls.builtins.diagnostics.clj_kondo,
# -- null_ls.builtins.formatting.isort,
# -- null_ls.builtins.formatting.black,
# },
# })
# -- Setup lspconfig
# require("lsp-format").setup {}
# require("nvim-navic").setup {}
# local format = require("lsp-format")
# local navic = require("nvim-navic")
# -- lspsaga, code_action lightbulb is annoying
@ -140,19 +109,6 @@
# },
# })
# -- fennel-ls is bleeding edge
# local lspconfig = require('lspconfig')
# require("lspconfig.configs")["fennel-ls"] = {
# default_config = {
# cmd = {"fennel-ls"},
# filetypes = {"fennel"},
# root_dir = function(dir) return lspconfig.util.find_git_ancestor(dir) end,
# settings = {}
# }
# }
# -- fennel-ls doesn't support gps
# lspconfig['fennel-ls'].setup {
# on_attach = function(client, bufnr)
@ -186,17 +142,6 @@
# -- },
# -- }
# require('gitsigns').setup { sign_priority=80 }
# -- treesitter
# require('nvim-treesitter.configs').setup {
# -- parser_install_dir = "~/.local/share/nvim/site/parser/",
# -- ensure_installed={'nix', 'clojure', 'python', 'fennel', 'lua', 'html', 'css', 'regex', 'supercollider', 'beancount', 'janet'},
# highlight = { enabled = true, additional_vim_regex_highting = true, },
# textobjects = { enabled = true },
# }
# -- 'glsl' needs c++ compiler lol
# -- lualine
# local navic = require("nvim-navic")
# require('lualine').setup {
@ -226,81 +171,6 @@
# }
# }
# -- nvim-lint
# -- require('lint').linters_by_ft = {
# -- markdown = {'vale'},
# -- }
# -- Custom functions
# function update_date()
# local time = os.date("%Y-%m-%d %H:%M")
# local message = "%update " .. time
# local lines = vim.api.nvim_buf_get_lines(0, 0,4,false)
# for i=1,4,1 do
# if (lines[i]:len() == 0) then
# vim.api.nvim_buf_set_lines(0, i-1, i, false, {message, ""})
# return
# end
# end
# if (lines[4]:len() ~= 0) then
# vim.api.nvim_buf_set_lines(0, 3, 4, false, {message})
# end
# return
# end
# vim.api.nvim_create_autocmd(
# "BufWritePre",
# { pattern = { "*.wiki" }, callback = update_date}
# )
# -- set spelling for text files
# vim.api.nvim_create_autocmd(
# { "BufRead", "BufNewFile" },
# { pattern = { "*.wiki", "*.txt", "*.md", "*.tex" },
# command = "setlocal spell" }
# )
# vim.api.nvim_create_autocmd(
# "FileType",
# { pattern = { "mail" },
# command = "setlocal spell" }
# )
# -- auto session
# require('auto-session').setup {
# log_level = 'info',
# auto_session_suppress_dirs = {'~/'}
# }
# vim.o.sessionoptions="blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal"
# require("which-key").setup{}
# require('leap').set_default_keymaps()
#
# -- supercollider
# local scnvim = require 'scnvim'
# local map = scnvim.map
# local map_expr = scnvim.map_expr
# scnvim.setup {
# keymaps = {
# ['<localleader>e'] = map('editor.send_line', {'i', 'n'}),
# ['<localleader>s'] = map_expr('CmdPeriod.run', {'i', 'n'}),
# ['<localleader>t'] = {
# map('editor.send_block', {'i', 'n'}),
# map('editor.send_selection', 'x'),
# },
# ['<CR>'] = map('postwin.toggle'),
# ['<M-CR>'] = map('postwin.toggle', 'i'),
# ['<M-L>'] = map('postwin.clear', {'n', 'i'}),
# ['<C-k>'] = map('signature.show', {'n', 'i'}),
# ['<F12>'] = map('sclang.hard_stop', {'n', 'x', 'i'}),
# ['<leader>st'] = map('sclang.start'),
# ['<leader>sk'] = map('sclang.recompile'),
# ['<F1>'] = map_expr('s.boot'),
# ['<F2>'] = map_expr('s.meter'),
# }
# }
# -- You gotta run :SCNvimGenerateAssets for this first
# -- require("luasnip").add_snippets("supercollider", require("scnvim/utils").get_snippets())
# -- zen mode
# require('zen-mode').setup{
@ -347,10 +217,6 @@
# }
# require('twilight').setup{}
# -- hologram
# require('hologram').setup{
# auto_display = false -- WIP automatic markdown image display, may be prone to breaking
# }
# EOF
@ -358,19 +224,20 @@
extraPackages = with pkgs; [
# used to compile tree-sitter grammar
# python-with-my-packages
nodejs
clojure-lsp
clojure
clj-kondo
# nodejs
# clojure-lsp
# clojure
# clj-kondo
terraform-lsp
nil
gopls
gcc
shellcheck
proselint
statix
nodePackages.typescript
nodePackages.typescript-language-server
luajitPackages.lua-lsp
# statix
# nodePackages.typescript
# nodePackages.typescript-language-server
# luajitPackages.lua-lsp
fennel-ls
# starpls-bin # TODO find this!!
];
@ -386,33 +253,32 @@
nvim-web-devicons
telescope-nvim
plenary-nvim
nvim-navic
FTerm-nvim
barbar-nvim
# TODO
# neotree
neovim-ayu
rainbow_parentheses-vim
vim-surround
undotree
(nvim-treesitter.withPlugins (p: [ p.nix p.clojure p.fennel p.lua p.html p.css p.regex p.supercollider p.beancount p.markdown p.glsl p.yaml p.toml p.dockerfile p.json ]))
nvim-treesitter-context
auto-session
which-key-nvim
zen-mode-nvim
twilight-nvim
aerial-nvim
todo-comments-nvim
indent-blankline-nvim
# TODO remove?
vim-dasht
# Tree sitter
(nvim-treesitter.withPlugins (p: [ p.nix p.clojure p.fennel p.lua p.html p.css p.regex p.supercollider p.beancount p.markdown_inline p.markdown p.glsl p.yaml p.toml p.dockerfile p.json p.go ]))
nvim-treesitter-context
nvim-treesitter-textobjects
# TODO
nvim-navic
undotree
marks-nvim
# language
vim-nix
emmet-vim
csv-vim
direnv-vim
conjure
# conjure
# kitaab stuff
vimwiki
@ -420,24 +286,20 @@
hologram-nvim
# lsp stuff
# nvim-lint
null-ls-nvim
nvim-lspconfig
nvim-cmp
cmp-nvim-lsp
cmp-treesitter
nvim-lsp-ts-utils
lspsaga-nvim
cmp-conjure
# cmp-conjure
cmp-buffer
cmp-path
cmp-spell
nvim-autopairs
cmp_luasnip
luasnip
lsp-format-nvim
friendly-snippets
lspkind-nvim
conform-nvim
none-ls-nvim
mini-nvim
lspsaga-nvim
# nvim-lspfuzzy
# git stuff
vim-fugitive
@ -454,7 +316,7 @@
# experimental
nvim-luapad
scnvim
leap-nvim
flash-nvim
vim-beancount
# vimtex
# custom