Skip to content

Commit 6ee4c89

Browse files
dimblebyautozimu
authored andcommitted
support LocationLink responses for GotoDefinition
With any luck this fixes #808
1 parent 688fad3 commit 6ee4c89

File tree

1 file changed

+25
-31
lines changed

1 file changed

+25
-31
lines changed

src/language_server_protocol.rs

+25-31
Original file line numberDiff line numberDiff line change
@@ -1046,42 +1046,36 @@ impl LanguageClient {
10461046

10471047
let response: Option<GotoDefinitionResponse> = result.clone().to_lsp()?;
10481048

1049-
match response {
1050-
None => {
1051-
self.vim()?.echowarn("Not found!")?;
1052-
return Ok(Value::Null);
1053-
}
1054-
Some(GotoDefinitionResponse::Scalar(loc)) => {
1049+
let locations = match response {
1050+
None => vec![],
1051+
Some(GotoDefinitionResponse::Scalar(loc)) => vec![loc],
1052+
Some(GotoDefinitionResponse::Array(arr)) => arr,
1053+
Some(GotoDefinitionResponse::Link(links)) => links
1054+
.into_iter()
1055+
.map(|link| Location::new(link.target_uri, link.target_selection_range))
1056+
.collect(),
1057+
};
1058+
1059+
match locations.len() {
1060+
0 => self.vim()?.echowarn("Not found!")?,
1061+
1 => {
1062+
let loc = locations.get(0).ok_or_else(|| err_msg("Not found!"))?;
10551063
self.vim()?.edit(&goto_cmd, loc.uri.filepath()?)?;
10561064
self.vim()?
10571065
.cursor(loc.range.start.line + 1, loc.range.start.character + 1)?;
1066+
let cur_file: String = self.vim()?.eval("expand('%')")?;
1067+
self.vim()?.echomsg_ellipsis(format!(
1068+
"{} {}:{}",
1069+
cur_file,
1070+
loc.range.start.line + 1,
1071+
loc.range.start.character + 1
1072+
))?;
10581073
}
1059-
Some(GotoDefinitionResponse::Array(arr)) => match arr.len() {
1060-
0 => self.vim()?.echowarn("Not found!")?,
1061-
1 => {
1062-
let loc = arr.get(0).ok_or_else(|| err_msg("Not found!"))?;
1063-
self.vim()?.edit(&goto_cmd, loc.uri.filepath()?)?;
1064-
self.vim()?
1065-
.cursor(loc.range.start.line + 1, loc.range.start.character + 1)?;
1066-
let cur_file: String = self.vim()?.eval("expand('%')")?;
1067-
self.vim()?.echomsg_ellipsis(format!(
1068-
"{} {}:{}",
1069-
cur_file,
1070-
loc.range.start.line + 1,
1071-
loc.range.start.character + 1
1072-
))?;
1073-
}
1074-
_ => {
1075-
let title = format!("[LC]: search for {}", current_word);
1076-
self.display_locations(&arr, &title)?
1077-
}
1078-
},
1079-
Some(GotoDefinitionResponse::Link(_)) => {
1080-
self.vim()?
1081-
.echowarn("Definition links are not supported!")?;
1082-
return Ok(Value::Null);
1074+
_ => {
1075+
let title = format!("[LC]: search for {}", current_word);
1076+
self.display_locations(&locations, &title)?
10831077
}
1084-
};
1078+
}
10851079

10861080
info!("End {}", method);
10871081
Ok(result)

0 commit comments

Comments
 (0)