Skip to content

Commit f8f3690

Browse files
martskinsautozimu
authored andcommitted
Show code lenses in fzf
1 parent cf43a9f commit f8f3690

File tree

1 file changed

+57
-20
lines changed

1 file changed

+57
-20
lines changed

src/language_server_protocol.rs

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,18 @@ impl LanguageClient {
965965
}
966966
}
967967
}
968+
"rust-analyzer.showReferences" => {
969+
let locations = cmd
970+
.arguments
971+
.clone()
972+
.unwrap_or(vec![])
973+
.get(2)
974+
.cloned()
975+
.unwrap_or(Value::Array(vec![]));
976+
let locations: Vec<Location> = serde_json::from_value(locations)?;
977+
978+
self.display_locations(&locations, "References")?;
979+
}
968980
"rust-analyzer.selectAndApplySourceChange" => {
969981
if let Some(ref edits) = cmd.arguments {
970982
for edit in edits {
@@ -1979,22 +1991,38 @@ impl LanguageClient {
19791991
return Ok(Value::Null);
19801992
}
19811993

1982-
if code_lens.len() > 1 {
1983-
warn!("Multiple actions associated with this codeLens");
1984-
return Ok(Value::Null);
1985-
}
1994+
self.update(|state| {
1995+
let actions: Fallible<Vec<_>> = code_lens
1996+
.iter()
1997+
.map(|cl| match &cl.command {
1998+
None => bail!("no command, skipping"),
1999+
Some(cmd) => Ok(CodeAction {
2000+
kind: Some(cmd.title.clone()),
2001+
title: cmd.command.clone(),
2002+
command: cl.clone().command,
2003+
diagnostics: None,
2004+
edit: None,
2005+
is_preferred: None,
2006+
}),
2007+
})
2008+
.filter(|c| c.is_ok())
2009+
.collect();
2010+
state.stashed_codeAction_actions = actions?;
2011+
Ok(())
2012+
})?;
19862013

1987-
if let Some(code_lens_action) = code_lens.get(0) {
1988-
if let Some(command) = &code_lens_action.command {
1989-
if !self.try_handle_command_by_client(&command)? {
1990-
let params = json!({
1991-
"command": command.command,
1992-
"arguments": command.arguments,
1993-
});
1994-
self.workspace_executeCommand(&params)?;
1995-
}
1996-
}
1997-
}
2014+
let source: Fallible<Vec<_>> = code_lens
2015+
.iter()
2016+
.map(|cl| match &cl.command {
2017+
None => bail!("no command, skipping"),
2018+
Some(cmd) => Ok(format!("{}: {}", cmd.title, cmd.command)),
2019+
})
2020+
.filter(|c| c.is_ok())
2021+
.collect();
2022+
2023+
self.vim()?
2024+
.rpcclient
2025+
.notify("s:FZF", json!([source?, NOTIFICATION__FZFSinkCommand]))?;
19982026

19992027
Ok(Value::Null)
20002028
}
@@ -2015,6 +2043,7 @@ impl LanguageClient {
20152043
let initialize_result: InitializeResult =
20162044
serde_json::from_value(initialize_result.clone())?;
20172045
let capabilities = initialize_result.capabilities;
2046+
20182047
if let Some(code_lens_provider) = capabilities.code_lens_provider {
20192048
info!("Begin {}", lsp::request::CodeLensRequest::METHOD);
20202049
let client = self.get_client(&Some(language_id))?;
@@ -3056,11 +3085,19 @@ impl LanguageClient {
30563085

30573086
for cl in code_lenses {
30583087
if let Some(command) = cl.command {
3059-
virtual_texts.push(VirtualText {
3060-
line: cl.range.start.line,
3061-
text: command.title,
3062-
hl_group: "Comment".into(),
3063-
})
3088+
let line = cl.range.start.line;
3089+
let text = command.title;
3090+
3091+
match virtual_texts.iter().position(|v| v.line == line) {
3092+
Some(idx) => virtual_texts[idx]
3093+
.text
3094+
.push_str(format!(" | {}", text).as_str()),
3095+
None => virtual_texts.push(VirtualText {
3096+
line,
3097+
text,
3098+
hl_group: "Comment".into(),
3099+
}),
3100+
}
30643101
}
30653102
}
30663103
}

0 commit comments

Comments
 (0)