From 0853e83e42277e49b30a41e77f1302402a90c875 Mon Sep 17 00:00:00 2001 From: Ajay Vignesh K Date: Wed, 12 Feb 2020 18:42:06 +0530 Subject: [PATCH 1/3] Enable setting and updating diagnostics on a single quickfix list --- autoload/LSP.vim | 13 +++++++++++++ src/language_server_protocol.rs | 10 +++++++++- src/vim.rs | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/autoload/LSP.vim b/autoload/LSP.vim index 9cdadb22..65e2785e 100644 --- a/autoload/LSP.vim +++ b/autoload/LSP.vim @@ -1,5 +1,18 @@ " TODO: make buffer aware. +function! LSP#GetQfListIdForTitle(title) + echom a:title + let headnr=getqflist({ 'id':0 ,'nr':'$', 'title': 0}).nr + while headnr >= 0 + let qflistat= getqflist({'id':0,'nr':headnr,'title':0}) + if qflistat.title==a:title + return qflistat.id + endif + let headnr = headnr-1 + endwhile + return-1 "not found +endfunction + function! LSP#filename() abort " When executing autocommand, `%` might have already changed. let l:filename = expand(':p') diff --git a/src/language_server_protocol.rs b/src/language_server_protocol.rs index c38a8100..c86f7ea6 100644 --- a/src/language_server_protocol.rs +++ b/src/language_server_protocol.rs @@ -684,7 +684,15 @@ impl LanguageClient { let diagnostics_list = self.get(|state| state.diagnostics_list)?; match diagnostics_list { DiagnosticsList::Quickfix => { - self.vim()?.setqflist(&qflist, "r", title)?; + //Has to be atomic + self.update(|state| { + let id = state.vim.getqfid(title)?; + if id != -1 { + state.vim.updateqflist(&qflist,title,id) + }else { + state.vim.addnewqflist(&qflist, title) + } + })?; } DiagnosticsList::Location => { self.vim()?.setloclist(&qflist, "r", title)?; diff --git a/src/vim.rs b/src/vim.rs index 1c054a12..fa03018a 100644 --- a/src/vim.rs +++ b/src/vim.rs @@ -206,6 +206,25 @@ impl Vim { Ok(()) } + pub fn updateqflist(&self, list: &[QuickfixEntry],title: &str, id: i32) -> Result<()> { + info!("Begin updateqflist"); + let parms = json!([[], "r" ,{"title":title,"id":id, "items":list}]); + self.rpcclient.notify("setqflist", parms)?; + Ok(()) + } + + pub fn addnewqflist(&self, list: &[QuickfixEntry],title: &str) -> Result<()> { + info!("Begin addnewqflist"); + let parms = json!([[], " ",{"title":title, "items":list}]); + self.rpcclient.notify("setqflist", parms)?; + Ok(()) + } + + pub fn getqfid(&self, title: &str) -> Result { + info!("Begin getqfid"); + self.rpcclient.call("LSP#GetQfListIdForTitle",title) + } + pub fn setqflist(&self, list: &[QuickfixEntry], action: &str, title: &str) -> Result<()> { info!("Begin setqflist"); let parms = json!([list, action]); From c9f11de741adce74490a30b510e1f40f14744237 Mon Sep 17 00:00:00 2001 From: Ajay Vignesh K Date: Wed, 12 Feb 2020 18:49:05 +0530 Subject: [PATCH 2/3] Add abort attribute for vim function --- autoload/LSP.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/LSP.vim b/autoload/LSP.vim index 65e2785e..243fbe57 100644 --- a/autoload/LSP.vim +++ b/autoload/LSP.vim @@ -1,6 +1,6 @@ " TODO: make buffer aware. -function! LSP#GetQfListIdForTitle(title) +function! LSP#GetQfListIdForTitle(title) abort echom a:title let headnr=getqflist({ 'id':0 ,'nr':'$', 'title': 0}).nr while headnr >= 0 From c1bd434dbfeb0620e6d7b589e5b9dd033f369780 Mon Sep 17 00:00:00 2001 From: Ajay Vignesh K Date: Wed, 12 Feb 2020 18:56:32 +0530 Subject: [PATCH 3/3] cargo fmt checks fix --- src/language_server_protocol.rs | 6 +++--- src/vim.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/language_server_protocol.rs b/src/language_server_protocol.rs index c86f7ea6..95be57d1 100644 --- a/src/language_server_protocol.rs +++ b/src/language_server_protocol.rs @@ -685,11 +685,11 @@ impl LanguageClient { match diagnostics_list { DiagnosticsList::Quickfix => { //Has to be atomic - self.update(|state| { + self.update(|state| { let id = state.vim.getqfid(title)?; if id != -1 { - state.vim.updateqflist(&qflist,title,id) - }else { + state.vim.updateqflist(&qflist, title, id) + } else { state.vim.addnewqflist(&qflist, title) } })?; diff --git a/src/vim.rs b/src/vim.rs index fa03018a..7a64671b 100644 --- a/src/vim.rs +++ b/src/vim.rs @@ -206,14 +206,14 @@ impl Vim { Ok(()) } - pub fn updateqflist(&self, list: &[QuickfixEntry],title: &str, id: i32) -> Result<()> { + pub fn updateqflist(&self, list: &[QuickfixEntry], title: &str, id: i32) -> Result<()> { info!("Begin updateqflist"); let parms = json!([[], "r" ,{"title":title,"id":id, "items":list}]); self.rpcclient.notify("setqflist", parms)?; Ok(()) } - pub fn addnewqflist(&self, list: &[QuickfixEntry],title: &str) -> Result<()> { + pub fn addnewqflist(&self, list: &[QuickfixEntry], title: &str) -> Result<()> { info!("Begin addnewqflist"); let parms = json!([[], " ",{"title":title, "items":list}]); self.rpcclient.notify("setqflist", parms)?; @@ -222,7 +222,7 @@ impl Vim { pub fn getqfid(&self, title: &str) -> Result { info!("Begin getqfid"); - self.rpcclient.call("LSP#GetQfListIdForTitle",title) + self.rpcclient.call("LSP#GetQfListIdForTitle", title) } pub fn setqflist(&self, list: &[QuickfixEntry], action: &str, title: &str) -> Result<()> {