Skip to content

Commit 13801fc

Browse files
authored
git plugin: skip buffer if it's not git-tracked (#1029)
* Minor refactoring: introduce Id in rpc types * Add optional jsonrpc field for future compatiability * Adjust RpcRequest and RpcNotification for later usage * Add jsonrpc field * Separate out vim.rs in rpc crate * Initial lsp module * Initial lsp plugin * Rename rpc/types.rs to jsonrpc.rs * Move lsp into a separate crate * Move lsp module to lsp_handler * goto-definition * Impl goto-locations * Ignore buffer if the file is not tracked * handle_locations() * Add is_initialized() in LSP client * Refine FileLocation * Rename clap#exit() to clap#exit_provider() * Refactor lsp plugin * . * clippy fixes
1 parent 5a15526 commit 13801fc

File tree

25 files changed

+2343
-283
lines changed

25 files changed

+2343
-283
lines changed

Cargo.lock

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ python-dynamic-module:
1111
config-md:
1212
cd crates/config_gen && cargo run
1313

14-
.PHONY: all maple python-dynamic-module config-md
14+
clippy:
15+
cd crates && cargo clippy --workspace -- -D warnings
16+
17+
.PHONY: all maple python-dynamic-module config-md clippy

autoload/clap.vim

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function! clap#_init() abort
155155
call g:clap.display.setbufvar('&filetype', '')
156156
endfunction
157157

158-
function! clap#_exit() abort
158+
function! clap#_exit_provider() abort
159159
call g:clap.provider.jobstop()
160160
call clap#maple#notify_exit_provider()
161161

@@ -182,10 +182,10 @@ function! clap#_for(provider_id_or_alias) abort
182182
call clap#for(a:provider_id_or_alias)
183183
endfunction
184184

185-
" Sometimes we don't need to go back to the start window, hence clap#_exit() is extracted.
186-
function! clap#exit() abort
185+
" Sometimes we don't need to go back to the start window, hence clap#_exit_provider() is extracted.
186+
function! clap#exit_provider() abort
187187
call g:clap.start.goto_win()
188-
call clap#_exit()
188+
call clap#_exit_provider()
189189
endfunction
190190

191191
function! clap#should_use_raw_cwd() abort
@@ -360,6 +360,9 @@ function! clap#(bang, ...) abort
360360
endfunction
361361

362362
function! clap#run(provider) abort
363+
if !exists('g:clap')
364+
call clap#init#()
365+
endif
363366
let id = has_key(a:provider, 'id') ? a:provider['id'] : 'run'
364367
let g:clap_provider_{id} = a:provider
365368
if s:inject_default_impl_is_ok(g:clap_provider_{id})

autoload/clap/handler.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ endfunction
107107

108108
function! s:internal_exit() abort
109109
call clap#selection#reset()
110-
call clap#exit()
110+
call clap#exit_provider()
111111
endfunction
112112

113113
" clap#handler#exit() = s:internal_exit() + external on_exit hook

autoload/clap/plugin/git.vim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ scriptencoding utf-8
55
let s:save_cpo = &cpoptions
66
set cpoptions&vim
77

8+
highlight ClapSignAdd ctermfg=70 guifg=#67b11d
9+
highlight ClapSignDelete ctermfg=196 guifg=#f2241f
10+
highlight ClapSignChange ctermfg=173 guifg=#e18254
11+
12+
highlight default link ClapGitSignAdd ClapSignAdd
13+
highlight default link ClapGitSignDelete ClapSignDelete
14+
highlight default link ClapGitSignChange ClapSignChange
15+
816
highlight default link ClapBlameInfo SpecialComment
917

1018
let s:git_signs = {
11-
\ 'added': { 'text': '+', 'texthl': 'DiffAdd' },
12-
\ 'modified': { 'text': '~', 'texthl': 'DiffChange' },
13-
\ 'removed': { 'text': '_', 'texthl': 'DiffDelete' },
14-
\ 'modified_removed': { 'text': '~_', 'texthl': 'DiffDelete' },
15-
\ 'removed_above_and_below': { 'text': '_-', 'texthl': 'DiffDelete' },
19+
\ 'added': { 'text': '+', 'texthl': 'ClapGitSignAdd' },
20+
\ 'modified': { 'text': '~', 'texthl': 'ClapGitSignChange' },
21+
\ 'removed': { 'text': '_', 'texthl': 'ClapGitSignDelete' },
22+
\ 'modified_removed': { 'text': '~_', 'texthl': 'ClapGitSignDelete' },
23+
\ 'removed_above_and_below': { 'text': '_-', 'texthl': 'ClapGitSignDelete' },
1624
\ }
1725

1826
if exists('g:clap_plugin_git_signs')

autoload/clap/plugin/lsp.vim

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
" Author: liuchengxu <[email protected]>
2+
3+
scriptencoding utf-8
4+
5+
let s:save_cpo = &cpoptions
6+
set cpoptions&vim
7+
8+
function! s:jump_to(location) abort
9+
execute 'edit' a:location.path
10+
noautocmd call setpos('.', [bufnr(''), a:location.row, a:location.column, 0])
11+
normal! zz
12+
endfunction
13+
14+
function! s:to_quickfix_entry(location) abort
15+
return { 'filename': a:location.path, 'lnum': a:location.row, 'col': a:location.column, 'text': a:location.text }
16+
endfunction
17+
18+
function! clap#plugin#lsp#handle_locations(id, locations) abort
19+
if len(a:locations) == 1
20+
call s:jump_to(a:locations[0])
21+
return
22+
endif
23+
24+
let mode = 'quickfix'
25+
26+
if mode ==# 'quickfix'
27+
let entries = map(a:locations, 's:to_quickfix_entry(v:val)')
28+
call clap#sink#open_quickfix(entries)
29+
else
30+
let provider = {
31+
\ 'id': a:id,
32+
\ 'source': map(a:locations, 'printf("%s:%s:%s", v:val["path"], v:val["row"], v:val["column"])'),
33+
\ 'sink': 'e',
34+
\ }
35+
36+
call clap#run(provider)
37+
endif
38+
endfunction
39+
40+
function! clap#plugin#lsp#open_picker() abort
41+
let provider = {
42+
\ 'id': 'lsp',
43+
\ 'on_typed': { -> clap#client#notify_provider('on_typed') },
44+
\ 'sink': 'e',
45+
\ }
46+
call clap#run(provider)
47+
endfunction
48+
49+
function! clap#plugin#lsp#provider_context() abort
50+
let params = {
51+
\ 'provider_id': 'lsp',
52+
\ 'input': { 'bufnr': g:clap.input.bufnr, 'winid': g:clap.input.winid },
53+
\ 'start': { 'bufnr': g:clap.start.bufnr, 'winid': g:clap.start.winid },
54+
\ 'display': { 'bufnr': g:clap.display.bufnr, 'winid': g:clap.display.winid },
55+
\ 'cwd': clap#rooter#working_dir(),
56+
\ 'icon': g:clap_enable_icon ? get(g:clap.provider._(), 'icon', 'Null') : 'Null',
57+
\ 'no_cache': has_key(g:clap.context, 'no-cache') ? v:true : v:false,
58+
\ 'start_buffer_path': expand('#'.g:clap.start.bufnr.':p'),
59+
\ 'source_is_list': v:false,
60+
\ }
61+
endfunction
62+
63+
let &cpoptions = s:save_cpo
64+
unlet s:save_cpo

autoload/clap/selection.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function! clap#selection#try_open(action) abort
8686
for line in s:get_opaque_lines()
8787
execute open_cmd line
8888
endfor
89-
call clap#_exit()
89+
call clap#_exit_provider()
9090

9191
elseif g:clap.provider.support_open_action()
9292

@@ -96,7 +96,7 @@ function! clap#selection#try_open(action) abort
9696
call g:clap.provider.sink(line)
9797
endfor
9898
call remove(g:clap, 'open_action')
99-
call clap#_exit()
99+
call clap#_exit_provider()
100100

101101
endif
102102
silent doautocmd <nomodeline> User ClapOnExit

autoload/clap/state.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ function! clap#state#clear_pre() abort
283283
call clap#indicator#reset()
284284
endfunction
285285

286-
" Clear temp state on clap#_exit()
286+
" Clear temp state on clap#_exit_provider()
287287
function! clap#state#clear_post() abort
288288
call s:remove_provider_tmp_vars([
289289
\ 'args',

crates/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"ide",
1111
"maple_core",
1212
"maple_derive",
13+
"maple_lsp",
1314
"matcher",
1415
"matcher/extracted_fzy",
1516
"paths",
@@ -76,6 +77,7 @@ icon = { path = "./icon" }
7677
ide = { path = "./ide" }
7778
maple_core = { path = "./maple_core" }
7879
maple_derive = { path = "./maple_derive" }
80+
maple_lsp = { path = "./maple_lsp" }
7981
matcher = { path = "./matcher" }
8082
paths = { path = "./paths" }
8183
pattern = { path = "./pattern" }

crates/maple_core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ maple_derive = { workspace = true }
4545
filter = { workspace = true }
4646
icon = { workspace = true }
4747
ide = { workspace = true }
48+
maple_lsp = { workspace = true }
4849
matcher = { workspace = true }
4950
paths = { workspace = true }
5051
pattern = { workspace = true }

0 commit comments

Comments
 (0)