Skip to content

Commit

Permalink
fix: shorter description and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
lazytanuki committed Jun 10, 2022
1 parent ba8b8c5 commit 33461ba
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl MappableCommand {
code_action, "Perform code action",
buffer_picker, "Open buffer picker",
symbol_picker, "Open symbol picker",
select_references_to_symbol_under_cursor, "Select references to symbol under cursor",
select_references_to_symbol_under_cursor, "Select symbol references",
workspace_symbol_picker, "Open workspace symbol picker",
last_picker, "Open last picker",
prepend_to_line, "Insert at start of line",
Expand Down
56 changes: 25 additions & 31 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use helix_lsp::{

use super::{align_view, push_jump, Align, Context, Editor};

use helix_core::{Selection, SmallVec};
use helix_core::Selection;
use helix_view::editor::Action;

use crate::{
Expand Down Expand Up @@ -734,37 +734,31 @@ pub fn select_references_to_symbol_under_cursor(cx: &mut Context) {
cx.callback(
future,
move |editor, _compositor, response: Option<Vec<lsp::DocumentHighlight>>| {
if let Some(document_highlights) = response {
if !document_highlights.is_empty() {
let (view, doc) = current!(editor);
let language_server = language_server!(editor, doc);
let offset_encoding = language_server.offset_encoding();
let text = doc.text();
let pos = doc.selection(view.id).primary().head;

let mut ranges = SmallVec::with_capacity(document_highlights.len());

// We must find the range that contains our primary cursor to prevent our primary cursor to move
let mut primary_index = 0;
let mut i = 0;

for document_highlight in document_highlights {
let lsp_range: lsp::Range = document_highlight.range;
let range =
helix_lsp::util::lsp_range_to_range(text, lsp_range, offset_encoding);
if let Some(range) = range {
if range.contains(pos) || range.head == pos {
primary_index = i;
}
ranges.push(range);
i += 1;
}
}
let document_highlights = match response {
Some(highlights) if !highlights.is_empty() => highlights,
_ => return,
};
let (view, doc) = current!(editor);
let language_server = language_server!(editor, doc);
let offset_encoding = language_server.offset_encoding();
let text = doc.text();
let pos = doc.selection(view.id).primary().head;

let selection = Selection::new(ranges, primary_index);
doc.set_selection(view.id, selection);
}
}
// We must find the range that contains our primary cursor to prevent our primary cursor to move
let mut primary_index = 0;
let ranges = document_highlights
.iter()
.filter_map(|highlight| lsp_range_to_range(text, highlight.range, offset_encoding))
.enumerate()
.map(|(i, range)| {
if range.contains(pos) {
primary_index = i;
}
range
})
.collect();
let selection = Selection::new(ranges, primary_index);
doc.set_selection(view.id, selection);
},
);
}

0 comments on commit 33461ba

Please sign in to comment.