From 44a9bf7fb5b77be4ba46f8c8d338782ad0beae19 Mon Sep 17 00:00:00 2001 From: ifengqi <362254883@qq.com> Date: Wed, 2 Oct 2024 20:56:02 +0800 Subject: [PATCH] Sort and filter `Reference` (#3558) --- lapce-app/src/panel/implementation_view.rs | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lapce-app/src/panel/implementation_view.rs b/lapce-app/src/panel/implementation_view.rs index 795ce91b..5c4b9053 100644 --- a/lapce-app/src/panel/implementation_view.rs +++ b/lapce-app/src/panel/implementation_view.rs @@ -10,6 +10,7 @@ IntoView, View, ViewId, }; use im::HashMap; +use itertools::Itertools; use lapce_rpc::file_line::FileLine; use lsp_types::{request::GotoImplementationResponse, Location, SymbolKind}; @@ -203,27 +204,35 @@ pub fn init_implementation_root( items: Vec, scope: Scope, ) -> ReferencesRoot { - let mut refs_map = HashMap::new(); + let mut refs_map: HashMap> = HashMap::new(); for item in items { - let entry = refs_map.entry(item.path.clone()).or_insert(Vec::new()); - (*entry).push(Reference::Line { - location: ReferenceLocation::Line { - file_line: item, - view_id: ViewId::new(), + let entry = refs_map.entry(item.path.clone()).or_default(); + (*entry).insert( + item.position.line, + Reference::Line { + location: ReferenceLocation::Line { + file_line: item, + view_id: ViewId::new(), + }, }, - }) + ); } let mut refs = Vec::new(); for (path, items) in refs_map { let open = scope.create_rw_signal(true); + let children = items + .into_iter() + .sorted_by(|x, y| x.0.cmp(&y.0)) + .map(|x| x.1) + .collect(); let ref_item = Reference::File { location: ReferenceLocation::File { open, path, view_id: ViewId::new(), }, - children: items, + children, open, }; refs.push(ref_item);