Skip to content

Commit

Permalink
Fix index out of range issue.
Browse files Browse the repository at this point in the history
In the case buffer is deleted, `getbufline` returns empty array.
  • Loading branch information
autozimu committed Feb 5, 2019
1 parent 6a171be commit 73da84a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion autoload/LSP.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function! LSP#text(...) abort
let l:buf = get(a:000, 0, '')

let l:lines = getbufline(l:buf, 1, '$')
if l:lines[-1] !=# '' && &fixendofline
if len(l:lines) > 0 && l:lines[-1] !=# '' && &fixendofline
let l:lines += ['']
endif
return l:lines
Expand Down
8 changes: 3 additions & 5 deletions src/language_server_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1833,17 +1833,15 @@ impl LanguageClient {

pub fn textDocument_didChange(&self, params: &Value) -> Fallible<()> {
info!("Begin {}", lsp::notification::DidChangeTextDocument::METHOD);
let (bufnr, languageId, filename): (u64, String, String) = self.gather_args(
&[VimVar::Bufnr, VimVar::LanguageId, VimVar::Filename],
params,
)?;
let (languageId, filename): (String, String) =
self.gather_args(&[VimVar::LanguageId, VimVar::Filename], params)?;
if !self.get(|state| state.text_documents.contains_key(&filename))? {
info!("Not opened yet. Switching to didOpen.");
return self.textDocument_didOpen(params);
}

let (text,): (Vec<String>,) =
self.gather_args(&[format!("LSP#text({})", bufnr)], params)?;
self.gather_args(&[format!("LSP#text('{}')", filename)], params)?;

let text = text.join("\n");
let text_state = self.get(|state| {
Expand Down
4 changes: 3 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ impl State {
Ok(State {
tx,

clients: HashMap::new(),
clients: hashmap! {
None => client.clone(),
},

vim: Vim::new(client),

Expand Down

0 comments on commit 73da84a

Please sign in to comment.