Skip to content

Commit 53ac313

Browse files
committed
Enable setting and updating diagnostics on a single quickfix list
1 parent 04bdd56 commit 53ac313

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

autoload/LSP.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
" TODO: make buffer aware.
22

3+
function! LSP#GetQfListIdForTitle(title)
4+
echom a:title
5+
let headnr=getqflist({ 'id':0 ,'nr':'$', 'title': 0}).nr
6+
while headnr >= 0
7+
let qflistat= getqflist({'id':0,'nr':headnr,'title':0})
8+
if qflistat.title==a:title
9+
return qflistat.id
10+
endif
11+
let headnr = headnr-1
12+
endwhile
13+
return-1 "not found
14+
endfunction
15+
316
function! LSP#filename() abort
417
" When executing autocommand, `%` might have already changed.
518
let l:filename = expand('<afile>:p')

src/language_server_protocol.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,15 @@ impl LanguageClient {
496496
let diagnosticsList = self.get(|state| state.diagnosticsList)?;
497497
match diagnosticsList {
498498
DiagnosticsList::Quickfix => {
499-
self.vim()?.setqflist(&qflist, "r", title)?;
499+
//Has to be atomic
500+
self.update(|state| {
501+
let id = state.vim.getqfid(title)?;
502+
if id != -1 {
503+
state.vim.updateqflist(&qflist,title,id)
504+
}else {
505+
state.vim.addnewqflist(&qflist, title)
506+
}
507+
})?;
500508
}
501509
DiagnosticsList::Location => {
502510
self.vim()?.setloclist(&qflist, "r", title)?;

src/vim.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,25 @@ impl Vim {
153153
Ok(())
154154
}
155155

156+
pub fn updateqflist(&self, list: &[QuickfixEntry],title: &str, id: i32) -> Fallible<()> {
157+
info!("Begin updateqflist");
158+
let parms = json!([[], "r" ,{"title":title,"id":id, "items":list}]);
159+
self.rpcclient.notify("setqflist", parms)?;
160+
Ok(())
161+
}
162+
163+
pub fn addnewqflist(&self, list: &[QuickfixEntry],title: &str) -> Fallible<()> {
164+
info!("Begin addnewqflist");
165+
let parms = json!([[], " ",{"title":title, "items":list}]);
166+
self.rpcclient.notify("setqflist", parms)?;
167+
Ok(())
168+
}
169+
170+
pub fn getqfid(&self, title: &str) -> Fallible<i32> {
171+
info!("Begin getqfid");
172+
self.rpcclient.call("LSP#GetQfListIdForTitle",title)
173+
}
174+
156175
pub fn setqflist(&self, list: &[QuickfixEntry], action: &str, title: &str) -> Fallible<()> {
157176
info!("Begin setqflist");
158177
let parms = json!([list, action]);

0 commit comments

Comments
 (0)