use built-in nvim diagnostics and lsp for linting

pull/2/head
Alpha Chen 3 years ago
parent 0c42a169cf
commit 07aedad8cb

@ -1,6 +1,8 @@
(vim.cmd "colorscheme paramount") (vim.cmd "colorscheme paramount")
(set vim.opt.list true) (set vim.opt.list true)
;; fnlfmt: skip
(set vim.opt.listchars {:tab "\\u21e5 " (set vim.opt.listchars {:tab "\\u21e5 "
:trail "\\u2423" :trail "\\u2423"
:extends "\\u21c9" :extends "\\u21c9"
@ -11,33 +13,23 @@
(set vim.g.mapleader " ") (set vim.g.mapleader " ")
; (let [{: keymap} vim ;; move the cursor to the first non-blank character with H
; nnoremap #(keymap.set :n $1 $2 {:noremap true}) (vim.keymap.set :n :H "^" {:noremap true})
; inoremap #(keymap.set :i $1 $2 {:noremap true})]
; ; clear hl
; (nnoremap :<leader>/ ":nohlsearch<cr>")
;; quick save ;; quick save
; (nnoremap "\\\\" ":write<cr>")
; (inoremap "\\\\" "<esc>:write<cr>")
; ; fzf
; (nnoremap :<leader>b ":Buffers<cr>")
; (nnoremap :<leader>f ":Files<cr>")
; (nnoremap :<leader>t ":Tags<cr>"))
(vim.keymap.set :n "\\\\" ":write<cr>" {:noremap true}) (vim.keymap.set :n "\\\\" ":write<cr>" {:noremap true})
(vim.keymap.set :i "\\\\" "<esc>:write<cr>" {:noremap true}) (vim.keymap.set :i "\\\\" "<esc>:write<cr>" {:noremap true})
;; clear highlight
(vim.keymap.set :n :<leader>/ ":nohlsearch<cr>" {:noremap true}) (vim.keymap.set :n :<leader>/ ":nohlsearch<cr>" {:noremap true})
;; restore cursor location ;;; restore cursor location
;;
;; https://github.com/vim/vim/blob/master/runtime/defaults.vim#L108 ;; https://github.com/vim/vim/blob/master/runtime/defaults.vim#L108
(let [{: nvim_command : nvim_create_autocmd : nvim_create_augroup} vim.api (let [{: nvim_command : nvim_create_autocmd : nvim_create_augroup} vim.api
au-group (nvim_create_augroup :nvim-startup {}) au-group (nvim_create_augroup :nvim-startup {})
cb (fn [] cb (fn []
(when (and (>= (vim.fn.line "'\"") 1) (when (and (< 0 (vim.fn.line "'\""))
(<= (vim.fn.line "'\"") (vim.fn.line "$")) (<= (vim.fn.line "'\"") (vim.fn.line "$"))
(not (string.find vim.bo.filetype :commit))) (not (string.find vim.bo.filetype :commit)))
(nvim_command "normal! g`\"")))] (nvim_command "normal! g`\"")))]
@ -49,62 +41,74 @@
(nvim_command "filetype plugin indent on") (nvim_command "filetype plugin indent on")
(nvim_create_autocmd :BufReadPost {:callback cb :group au-group})) (nvim_create_autocmd :BufReadPost {:callback cb :group au-group}))
;; ftplugins in fennel ;;; ftplugins in fennel
;;
;; https://github.com/rktjmp/hotpot.nvim/discussions/41#discussioncomment-3050564 ;; https://github.com/rktjmp/hotpot.nvim/discussions/41#discussioncomment-3050564
(let [{: nvim_create_autocmd : nvim_create_augroup} vim.api (let [{: nvim_create_autocmd : nvim_create_augroup} vim.api
au-group (nvim_create_augroup :hotpot-ft {}) au-group (nvim_create_augroup :hotpot-ft {})
cb #(pcall require (.. :ftplugin. (vim.fn.expand :<amatch>)))] cb #(pcall require (.. :ftplugin. (vim.fn.expand :<amatch>)))]
(nvim_create_autocmd :FileType {:callback cb :group au-group})) (nvim_create_autocmd :FileType {:callback cb :group au-group}))
;; ale ;; (require :ale)
(require :fzf)
(set vim.g.ale_fix_on_save 1)
(set vim.g.ale_floating_preview 1) ;;; lint
;; fzf (let [lint (require :lint)
{: linters :linters_by_ft linters-by-ft :try_lint try-lint} lint
(when (vim.fn.executable :fzf) {:fennel fennel-linter} linters
(when (vim.fn.isdirectory :/opt/homebrew/opt/fzf/plugin) {: nvim_create_autocmd} vim.api]
(vim.opt.rtp:append :/opt/homebrew/opt/fzf)) (tset linters-by-ft :fennel [:fennel])
(vim.keymap.set :n :<leader>b ":Buffers<cr>" {:noremap true}) (tset fennel-linter :globals [:vim]) ; hack
(vim.keymap.set :n :<leader>f ":Files<cr>" {:noremap true}) (nvim_create_autocmd :BufWritePost {:callback #(try-lint)}))
(vim.keymap.set :n :<leader>t ":Tags<cr>" {:noremap true})
;;; lspconfig
; https://coreyja.com/vim-spelling-suggestions-fzf/
(let [{: nvim_command : nvim_create_user_command} vim.api ;; (vim.lsp.set_log_level :debug)
{: expand : spellsuggest} vim.fn
fzf-run (. vim.fn "fzf#run") (let [opts {:noremap true :silent true}]
sink #(nvim_command (.. "normal! \"_ciw" $1)) (vim.keymap.set :n :<leader>e vim.diagnostic.open_float opts)
fzf-spell #(fzf-run {:source (spellsuggest (expand :<cword>)) (vim.keymap.set :n "[d" vim.diagnostic.goto_prev opts)
: sink (vim.keymap.set :n "]d" vim.diagnostic.goto_next opts)
:window {:width 0.9 :height 0.6}})] (vim.keymap.set :n :<leader>q vim.diagnostic.setloclist opts))
(nvim_create_user_command :FzfSpell fzf-spell {})
(vim.keymap.set :n :z= ":FzfSpell<cr>"))) (fn on_attach [client bufnr]
(vim.api.nvim_buf_set_option bufnr :omnifunc "v:lua.vim.lsp.omnifunc")
;; lspconfig (let [bufopts {:noremap true :silent true :buffer bufnr}]
; (let [opts {:noremap true :silent true}] (vim.keymap.set :n :gD vim.lsp.buf.declaration bufopts)
; (vim.keymap.set :n :<leader>e vim.diagnostic.open_float opts) (vim.keymap.set :n :gd vim.lsp.buf.definition bufopts)
; (vim.keymap.set :n "[d" vim.diagnostic.goto_prev opts) (vim.keymap.set :n :K vim.lsp.buf.hover bufopts)
; (vim.keymap.set :n "]d" vim.diagnostic.goto_next opts) (vim.keymap.set :n :gi vim.lsp.buf.implementation bufopts)
; (vim.keymap.set :n :<leader>q vim.diagnostic.setloclist opts)) (vim.keymap.set :n :<C-k> vim.lsp.buf.signature_help bufopts)
(vim.keymap.set :n :<leader>wa vim.lsp.buf.add_workspace_folder bufopts)
; (fn on_attach [client bufnr] (vim.keymap.set :n :<leader>wr vim.lsp.buf.remove_workspace_folder bufopts)
; (vim.api.nvim_buf_set_option bufnr :omnifunc "v:lua.vim.lsp.omnifunc") (vim.keymap.set :n :<leader>wl
; (let [bufopts {:noremap true :silent true :buffer bufnr}] (fn []
; (vim.keymap.set :n :gD vim.lsp.buf.declaration bufopts) (print (vim.inspect (vim.lsp.buf.list_workspace_folders))))
; (vim.keymap.set :n :gd vim.lsp.buf.definition bufopts) bufopts)
; (vim.keymap.set :n :K vim.lsp.buf.hover bufopts) (vim.keymap.set :n :<leader>D vim.lsp.buf.type_definition bufopts)
; (vim.keymap.set :n :gi vim.lsp.buf.implementation bufopts) (vim.keymap.set :n :<leader>rn vim.lsp.buf.rename bufopts)
; (vim.keymap.set :n :<C-k> vim.lsp.buf.signature_help bufopts) (vim.keymap.set :n :<leader>ca vim.lsp.buf.code_action bufopts)
; (vim.keymap.set :n :<leader>wa vim.lsp.buf.add_workspace_folder bufopts) (vim.keymap.set :n :gr vim.lsp.buf.references bufopts)
; (vim.keymap.set :n :<leader>wr vim.lsp.buf.remove_workspace_folder bufopts) (vim.keymap.set :n :<leader>f vim.lsp.buf.formatting bufopts)))
; (vim.keymap.set :n :<leader>wl
; (fn [] (let [{: rust_analyzer} (require :lspconfig)]
; (print (vim.inspect (vim.lsp.buf.list_workspace_folders)))) ((. rust_analyzer :setup) {: on_attach
; bufopts) :settings {:rust-analyzer {:checkOnSave {:command :clippy}}}}))
; (vim.keymap.set :n :<leader>D vim.lsp.buf.type_definition bufopts)
; (vim.keymap.set :n :<leader>rn vim.lsp.buf.rename bufopts) ;;; netrw
; (vim.keymap.set :n :<leader>ca vim.lsp.buf.code_action bufopts)
; (vim.keymap.set :n :gr vim.lsp.buf.references bufopts) (set vim.g.netrw_fastbrowse 0)
; (vim.keymap.set :n :<leader>f vim.lsp.buf.formatting bufopts)))
; https://github.com/tpope/vim-vinegar/issues/13
(set vim.g.netrw_home "~/.nvim_tmp")
;;; generate help files
; Load all plugins now.
; Plugins need to be added to runtimepath before helptags can be generated.
(vim.api.nvim_command :packloadall)
; Load all of the helptags now, after plugins have been loaded.
; All messages and errors will be ignored.
(vim.api.nvim_command "silent! helptags ALL")

6
.gitmodules vendored

@ -165,9 +165,6 @@
[submodule ".local/share/nvim/site/pack/kejadlen/start/surround"] [submodule ".local/share/nvim/site/pack/kejadlen/start/surround"]
path = .local/share/nvim/site/pack/kejadlen/start/surround path = .local/share/nvim/site/pack/kejadlen/start/surround
url = https://github.com/tpope/vim-surround.git url = https://github.com/tpope/vim-surround.git
[submodule ".local/share/nvim/site/pack/kejadlen/start/ale"]
path = .local/share/nvim/site/pack/kejadlen/start/ale
url = https://github.com/dense-analysis/ale.git
[submodule ".local/share/nvim/site/pack/kejadlen/start/fzf"] [submodule ".local/share/nvim/site/pack/kejadlen/start/fzf"]
path = .local/share/nvim/site/pack/kejadlen/start/fzf path = .local/share/nvim/site/pack/kejadlen/start/fzf
url = https://github.com/junegunn/fzf.vim.git url = https://github.com/junegunn/fzf.vim.git
@ -177,3 +174,6 @@
[submodule ".local/share/nvim/site/pack/kejadlen/start/tabular"] [submodule ".local/share/nvim/site/pack/kejadlen/start/tabular"]
path = .local/share/nvim/site/pack/kejadlen/start/tabular path = .local/share/nvim/site/pack/kejadlen/start/tabular
url = https://github.com/godlygeek/tabular.git url = https://github.com/godlygeek/tabular.git
[submodule ".local/share/nvim/site/pack/kejadlen/start/lint"]
path = .local/share/nvim/site/pack/kejadlen/start/lint
url = https://github.com/mfussenegger/nvim-lint.git

@ -1 +0,0 @@
Subproject commit 39d1a1058908396be61579a13e75a272cc527c57

@ -0,0 +1 @@
Subproject commit 5249977a585c3c17d94afdc8f0255a689d3a0057
Loading…
Cancel
Save