Skip to content

Commit 0853e83

Browse files
committed
Enable setting and updating diagnostics on a single quickfix list
1 parent 0e0f99d commit 0853e83

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
@@ -684,7 +684,15 @@ impl LanguageClient {
684684
let diagnostics_list = self.get(|state| state.diagnostics_list)?;
685685
match diagnostics_list {
686686
DiagnosticsList::Quickfix => {
687-
self.vim()?.setqflist(&qflist, "r", title)?;
687+
//Has to be atomic
688+
self.update(|state| {
689+
let id = state.vim.getqfid(title)?;
690+
if id != -1 {
691+
state.vim.updateqflist(&qflist,title,id)
692+
}else {
693+
state.vim.addnewqflist(&qflist, title)
694+
}
695+
})?;
688696
}
689697
DiagnosticsList::Location => {
690698
self.vim()?.setloclist(&qflist, "r", title)?;

src/vim.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,25 @@ impl Vim {
206206
Ok(())
207207
}
208208

209+
pub fn updateqflist(&self, list: &[QuickfixEntry],title: &str, id: i32) -> Result<()> {
210+
info!("Begin updateqflist");
211+
let parms = json!([[], "r" ,{"title":title,"id":id, "items":list}]);
212+
self.rpcclient.notify("setqflist", parms)?;
213+
Ok(())
214+
}
215+
216+
pub fn addnewqflist(&self, list: &[QuickfixEntry],title: &str) -> Result<()> {
217+
info!("Begin addnewqflist");
218+
let parms = json!([[], " ",{"title":title, "items":list}]);
219+
self.rpcclient.notify("setqflist", parms)?;
220+
Ok(())
221+
}
222+
223+
pub fn getqfid(&self, title: &str) -> Result<i32> {
224+
info!("Begin getqfid");
225+
self.rpcclient.call("LSP#GetQfListIdForTitle",title)
226+
}
227+
209228
pub fn setqflist(&self, list: &[QuickfixEntry], action: &str, title: &str) -> Result<()> {
210229
info!("Begin setqflist");
211230
let parms = json!([list, action]);

0 commit comments

Comments
 (0)