fix: don't panic if the client sends invalid request

This commit is contained in:
Aleksey Kladov
2021-09-04 12:27:27 +03:00
parent ac2520128d
commit 33199b7e43
2 changed files with 9 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ use crate::{
from_json,
global_state::GlobalStateSnapshot,
line_index::{LineIndex, OffsetEncoding},
lsp_ext, Result,
lsp_ext, LspError, Result,
};
pub(crate) fn abs_path(url: &lsp_types::Url) -> Result<AbsPathBuf> {
@@ -85,7 +85,10 @@ pub(crate) fn annotation(
snap: &GlobalStateSnapshot,
code_lens: lsp_types::CodeLens,
) -> Result<Annotation> {
let data = code_lens.data.unwrap();
let data = code_lens.data.ok_or_else(|| LspError {
code: lsp_server::ErrorCode::InvalidParams as i32,
message: "code lens without data".to_string(),
});
let resolve = from_json::<lsp_ext::CodeLensResolveData>("CodeLensResolveData", data)?;
match resolve {