Skip to content

Commit

Permalink
Overhaul plugin actions and ensure the display highlights are cleared…
Browse files Browse the repository at this point in the history
… on empty query (#1049)

* Clear display highlights when no matches found

* Remove unused deps

* Fix custom language server config

* Nits

* Add params to goto_()

* Introduce AutocmdEventType::parse() so that no missing autocmd event again

* fix buf detach params

* .

* Nits

* Add language-servers = ["clangd"] for language cpp

* Ignore coc-explorer in lsp plugin

* fix didChange params for Vim

* [vim] reduce unnecesary highlight redraw by removing all from prop_remove()

* Remove unwrap() in tree_sitter ConfigInner

* Make asset file downloading generic

In order to prepare the support for downloading various
asset files from GitHub release, pretty useful for LSP plugin.

* Refactor upgrade

* Allow overriding the default language config

* Separate out winbar module

* Introduec diagnostics plugin

* Distinguish the diagnostic error and warn highlight

* Update CHANGELOG.md

* Update CHANGELOG.md

* Move echoDiagnostics and echoDiagnosticsAtCursor to diagnostics plugin

* Rename to diagnostics.buffer and diagnostics.cursor

* Support opening lsp locations (refs, defs, etc) in fuzzy picker

* Add docs to config()

* Update config.md
  • Loading branch information
liuchengxu authored Feb 29, 2024
1 parent 6ce32d1 commit 070dcc0
Show file tree
Hide file tree
Showing 51 changed files with 1,253 additions and 852 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

## [unreleased]

- Change the syntax of plugin actions from `plugin/action` to `plugin.action` for better compatibility with other tools.
### Plugins

- Change the naming convention of plugin action from `plugin/foo-action` to `plugin.fooAction` for the compatibility with tools like coc.nvim.
- Use different highlight groups for the span of error and warn diagnostics.
- Added diagnostics plugin in order to conveniently inspect the collected diagnostics from both the linter and lsp plugin.
Now you should use `:ClapAction diagnostics.firstError` instead of `:ClapAction linter.firstError` to jump to the position of first error.

### Internal

Expand Down
17 changes: 2 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions autoload/clap/highlighter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let s:default_priority = 10
if has('nvim')
let s:tree_sitter_ns_id = nvim_create_namespace('clap_tree_sitter_highlight')
else
let s:ts_types = []
let s:ts_prop_types = []
endif

if has('nvim')
Expand Down Expand Up @@ -163,8 +163,8 @@ endfunction
function! clap#highlighter#disable_tree_sitter(bufnr) abort
if has('nvim')
call nvim_buf_clear_namespace(a:bufnr, s:tree_sitter_ns_id, 0, -1)
elseif !empty(s:ts_types)
call prop_remove({ 'types': s:ts_types, 'all': v:true, 'bufnr': a:bufnr } )
elseif !empty(s:ts_prop_types)
call prop_remove({ 'types': s:ts_prop_types, 'all': v:true, 'bufnr': a:bufnr } )
endif
endfunction

Expand All @@ -178,23 +178,23 @@ function! clap#highlighter#add_ts_highlights(bufnr, to_replace_line_ranges, high
call nvim_buf_clear_namespace(a:bufnr, s:tree_sitter_ns_id, start, end)
endfor
endif
elseif !empty(s:ts_types)
elseif !empty(s:ts_prop_types)
if empty(a:to_replace_line_ranges)
call prop_remove({ 'types': s:ts_types, 'all': v:true, 'bufnr': a:bufnr } )
call prop_remove({ 'types': s:ts_prop_types, 'all': v:true, 'bufnr': a:bufnr } )
else
for [start, end] in a:to_replace_line_ranges
" start is 0-based
call prop_remove({ 'types': s:ts_types, 'all': v:true, 'bufnr': a:bufnr }, start+1, end)
call prop_remove({ 'types': s:ts_prop_types, 'bufnr': a:bufnr }, start+1, end)
endfor
endif
endif

for [line_number, highlights] in a:highlights
for [column_start, length, group_name] in highlights
if !has('nvim')
if index(s:ts_types, group_name) == -1
call add(s:ts_types, group_name)
call prop_type_add(group_name, {'highlight': group_name})
if index(s:ts_prop_types, group_name) == -1
call add(s:ts_prop_types, group_name)
call prop_type_add(group_name, {'highlight': group_name})
endif
endif
call s:add_ts_highlight_at(a:bufnr, line_number, column_start, length, group_name)
Expand Down
1 change: 1 addition & 0 deletions autoload/clap/picker.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function! clap#picker#update(update_info) abort
call clap#indicator#update(update_info.matched, update_info.processed)

if update_info.matched == 0
call g:clap.display.clear_highlight()
call g:clap.display.set_lines([g:clap_no_matches_msg])
call g:clap.preview.clear()
if exists('g:__clap_lines_truncated_map')
Expand Down
2 changes: 1 addition & 1 deletion autoload/clap/plugin/cursorword.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hi default link ClapCursorWordTwins ClapUnderline
augroup VimClapCursorword
autocmd!

autocmd ColorScheme * call clap#client#notify('cursorword.__define-highlights', [+expand('<abuf>')])
autocmd ColorScheme * call clap#client#notify('cursorword.__defineHighlights', [+expand('<abuf>')])
augroup END

function! clap#plugin#cursorword#add_highlights(word_highlights) abort
Expand Down
25 changes: 17 additions & 8 deletions autoload/clap/plugin/linter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ let s:severity_icons = {
\ 'other': '',
\ }

hi ClapDiagnosticUnderline cterm=underline,bold gui=undercurl,italic,bold ctermfg=173 guifg=#e18254
hi ClapDiagnosticUnderlineWarn cterm=underline,bold gui=undercurl,italic,bold ctermfg=173 guifg=#e18254
hi ClapDiagnosticUnderlineError cterm=underline,bold gui=undercurl,italic,bold ctermfg=196 guifg=#f2241f

hi DiagnosticWarn ctermfg=136 guifg=#b1951d

Expand Down Expand Up @@ -153,9 +154,9 @@ function! clap#plugin#linter#display_top_right(current_diagnostics) abort
endif
endfunction

function! s:highlight_span(bufnr, span) abort
function! s:highlight_span(bufnr, span, hl_group) abort
try
call nvim_buf_add_highlight(a:bufnr, s:linter_spans_highlight_ns_id, 'ClapDiagnosticUnderline', a:span.line_start - 1, a:span.column_start - 1, a:span.column_end - 1)
call nvim_buf_add_highlight(a:bufnr, s:linter_spans_highlight_ns_id, a:hl_group, a:span.line_start - 1, a:span.column_start - 1, a:span.column_end - 1)
catch
" Span may be invalid at this moment since the buffer has been changed.
return
Expand Down Expand Up @@ -222,13 +223,18 @@ endfunction

else

function! s:highlight_span(bufnr, span) abort
function! s:highlight_span(bufnr, span, hl_group) abort
let length = a:span.column_end - a:span.column_start
" It's possible that the span across multiple lines and this can be negative.
if length < 0
let length = 1
endif
call prop_add(a:span.line_start, a:span.column_start, { 'type': 'ClapDiagnosticUnderline', 'length': length, 'bufnr': a:bufnr })
try
call prop_add(a:span.line_start, a:span.column_start, { 'type': a:hl_group, 'length': length, 'bufnr': a:bufnr })
catch
" Span may be invalid at this moment since the buffer has been changed.
return
endtry
endfunction

function! clap#plugin#linter#close_top_right() abort
Expand Down Expand Up @@ -284,17 +290,20 @@ function! clap#plugin#linter#display_top_right(current_diagnostics) abort
endif
endfunction

call prop_type_add('ClapDiagnosticUnderline', {'highlight': 'ClapDiagnosticUnderline'})
call prop_type_add('ClapDiagnosticUnderlineWarn', {'highlight': 'ClapDiagnosticUnderlineWarn'})
call prop_type_add('ClapDiagnosticUnderlineError', {'highlight': 'ClapDiagnosticUnderlineError'})

function! clap#plugin#linter#delete_highlights(bufnr) abort
call prop_remove({ 'type': 'ClapDiagnosticUnderline', 'bufnr': a:bufnr } )
call prop_remove({ 'type': 'ClapDiagnosticUnderlineWarn', 'bufnr': a:bufnr } )
call prop_remove({ 'type': 'ClapDiagnosticUnderlineError', 'bufnr': a:bufnr } )
endfunction

endif

function! clap#plugin#linter#add_highlights(bufnr, diagnostics) abort
for diagnostic in a:diagnostics
call map(diagnostic.spans, 's:highlight_span(a:bufnr, v:val)')
let hl_group = diagnostic.severity ==# 'Error' ? 'ClapDiagnosticUnderlineError' : 'ClapDiagnosticUnderlineWarn'
call map(diagnostic.spans, 's:highlight_span(a:bufnr, v:val, hl_group)')
endfor
endfunction

Expand Down
46 changes: 21 additions & 25 deletions autoload/clap/plugin/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ scriptencoding utf-8
let s:save_cpo = &cpoptions
set cpoptions&vim

function! s:jump_to(location) abort
execute 'edit' a:location.path
function! clap#plugin#lsp#jump_to(location) abort
execute 'edit!' a:location.path
noautocmd call setpos('.', [bufnr(''), a:location.row, a:location.column, 0])
normal! zz
endfunction
Expand All @@ -15,26 +15,9 @@ function! s:to_quickfix_entry(location) abort
return { 'filename': a:location.path, 'lnum': a:location.row, 'col': a:location.column, 'text': a:location.text }
endfunction

function! clap#plugin#lsp#handle_locations(id, locations) abort
if len(a:locations) == 1
call s:jump_to(a:locations[0])
return
endif

let mode = 'quickfix'

if mode ==# 'quickfix'
let entries = map(a:locations, 's:to_quickfix_entry(v:val)')
call clap#sink#open_quickfix(entries)
else
let provider = {
\ 'id': a:id,
\ 'source': map(a:locations, 'printf("%s:%s:%s", v:val["path"], v:val["row"], v:val["column"])'),
\ 'sink': 'e',
\ }

call clap#run(provider)
endif
function! clap#plugin#lsp#populate_quickfix(id, locations) abort
let entries = map(a:locations, 's:to_quickfix_entry(v:val)')
call clap#sink#open_quickfix(entries)
endfunction

function! clap#plugin#lsp#open_picker(title) abort
Expand Down Expand Up @@ -66,9 +49,15 @@ function! clap#plugin#lsp#detach(bufnr) abort
endfunction

if has('nvim')
" [bufnr, changedtick, firstline, lastline, new_lastline]
function! clap#plugin#lsp#on_lines(...) abort
call clap#client#notify('lsp.__did_change', a:000)
let [bufnr, changedtick, firstline, lastline, new_lastline] = a:000
call clap#client#notify('lsp.__didChange', {
\ 'bufnr': bufnr,
\ 'changedtick': changedtick,
\ 'firstline': firstline,
\ 'lastline': lastline,
\ 'new_lastline': new_lastline,
\ })
endfunction

function! clap#plugin#lsp#buf_attach(bufnr) abort
Expand All @@ -93,7 +82,14 @@ endfunction
else

function! clap#plugin#lsp#listener(bufnr, start, end, added, changes) abort
echom string([a:bufnr, a:start, a:end, a:added, a:changes])
call clap#client#notify('lsp.__didChange', {
\ 'bufnr': a:bufnr,
\ 'start': a:start,
\ 'end': a:end,
\ 'added': a:added,
\ 'changes': a:changes,
\ 'changedtick': getbufvar(a:bufnr, 'changedtick'),
\ })
endfunction

function! clap#plugin#lsp#buf_attach(bufnr) abort
Expand Down
4 changes: 2 additions & 2 deletions autoload/clap/popup/move_manager.vim
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function! s:move_manager.scroll_up(winid) abort
call win_execute(a:winid, 'noautocmd call clap#navigation#scroll("up")')
endfunction

" noautocmd is neccessary in that too many plugins use redir, otherwise we'll
" noautocmd is necessary in that too many plugins use redir, otherwise we'll
" see E930: Cannot use :redir inside execute().
let s:move_manager["\<C-A>"] = s:move_manager.ctrl_a
let s:move_manager["\<C-B>"] = s:move_manager.ctrl_b
Expand Down Expand Up @@ -231,7 +231,7 @@ function! s:move_manager.printable(key) abort
" Always hold a delay before reacting actually.
"
" FIXME
" If the slow renderring of vim job is resolved, this delay could be removed.
" If the slow rendering of vim job is resolved, this delay could be removed.
"
" apply_input should happen earlier than mock_input
" call s:apply_input('')
Expand Down
3 changes: 0 additions & 3 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ description = "CLI for vim-clap Rust backend"
[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
futures = { workspace = true }
itertools = { workspace = true }
num_cpus = { workspace = true }
tokio = { workspace = true, features = ["fs", "rt", "process", "macros", "rt-multi-thread", "sync", "time"] }
rayon = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
subprocess = { workspace = true }
Expand All @@ -29,7 +27,6 @@ icon = { workspace = true }
matcher = { workspace = true }
maple_config = { workspace = true }
maple_core = { workspace = true }
pattern = { workspace = true }
printer = { workspace = true }
types = { workspace = true }
utils = { workspace = true }
Expand Down
2 changes: 0 additions & 2 deletions crates/code_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ version.workspace = true
edition.workspace = true

[dependencies]
async-trait = { workspace = true }
cargo_metadata = { workspace = true }
once_cell = { workspace = true }
parking_lot = { workspace = true }
regex = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
Loading

0 comments on commit 070dcc0

Please sign in to comment.