Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'src/sym.rs')
-rw-r--r--src/sym.rs164
1 files changed, 101 insertions, 63 deletions
diff --git a/src/sym.rs b/src/sym.rs
index 1ceb2b4..fbffbef 100644
--- a/src/sym.rs
+++ b/src/sym.rs
@@ -5,10 +5,12 @@ use std::path::{Path, PathBuf};
use Default::default;
use dsb::Cell;
use dsb::cell::Style;
-use itern::Iter3;
+use itern::{Iter3, Iter4};
use lsp_types::*;
+use url::Url;
use crate::FG;
+use crate::complete::i;
use crate::gotolist::At;
pub use crate::gotolist::GoTo;
use crate::menu::generic::{GenericMenu, MenuData};
@@ -32,38 +34,48 @@ impl MenuData for Symb {
(r, tree, bmks, _, origin): &Self::Data,
) -> impl Iterator<Item = Self::Element<'_>> {
match r {
- SymbolsList::Document(DocumentSymbolResponse::Flat(x)) =>
- Iter3::A(x.iter().map(UsedSI::from)),
- SymbolsList::Document(DocumentSymbolResponse::Nested(x)) =>
- Iter3::B(
- gen {
- for bmk in &**bmks {
- yield UsedSI {
- name: &bmk.text,
- kind: SymbolKind::BOOKMARK,
- tags: None,
- at: GoTo {
- path: origin.into(),
- at: At::P(bmk.position),
- },
- right: None,
- }
+ SymbolsList::Document(
+ DocumentSymbolResponse::SymbolInformationList(x),
+ ) => Iter4::A(x.iter().map(UsedSI::from)),
+ SymbolsList::Document(
+ DocumentSymbolResponse::DocumentSymbolList(x),
+ ) => Iter4::B(
+ gen {
+ for bmk in &**bmks {
+ yield UsedSI {
+ name: &bmk.text,
+ // kind: SymbolKind::Bookmark,
+ kind: SymbolKind::Class, // FIXME
+ tags: None,
+ at: GoTo {
+ path: origin.into(),
+ at: At::P(bmk.position),
+ },
+ right: None,
}
}
- .chain(x.iter().flat_map(
- move |x| gen move {
- let mut q = VecDeque::with_capacity(12);
- q.push_back(x);
- while let Some(x) = q.pop_front() {
- q.extend(x.children.iter().flatten());
- yield (x, origin).into();
- }
- },
- )),
- ),
- SymbolsList::Workspace(WorkspaceSymbolResponse::Flat(x)) =>
- Iter3::C(chain(tree, x.iter()).map(UsedSI::from)),
- _ => unreachable!("please no"),
+ }
+ .chain(x.iter().flat_map(
+ move |x| gen move {
+ let mut q = VecDeque::with_capacity(12);
+ q.push_back(x);
+ while let Some(x) = q.pop_front() {
+ q.extend(x.children.iter().flatten());
+ yield (x, origin).into();
+ }
+ },
+ )),
+ ),
+ SymbolsList::Workspace(
+ WorkspaceSymbolResponse::WorkspaceSymbolList(x),
+ ) => Iter4::C(chain(
+ tree.iter().map(UsedSI::from),
+ x.iter().map(UsedSI::from),
+ )),
+ SymbolsList::Workspace(
+ WorkspaceSymbolResponse::SymbolInformationList(x),
+ ) => Iter4::D(chain(tree, x.iter()).map(UsedSI::from)),
+ // _ => unreachable!("please no"),
}
}
@@ -97,7 +109,7 @@ pub struct UsedSI<'a> {
impl<'a> std::hash::Hash for UsedSI<'a> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.name.hash(state);
- self.kind.0.hash(state);
+ self.kind.hash(state);
self.at.hash(state);
self.right.hash(state);
}
@@ -105,11 +117,9 @@ impl<'a> std::hash::Hash for UsedSI<'a> {
impl<'a> From<&'a SymbolInformation> for UsedSI<'a> {
fn from(
SymbolInformation {
- name,
- kind,
- tags,
+ base_symbol_information:
+ BaseSymbolInformation { name, kind, tags, container_name },
location,
- container_name,
..
}: &'a SymbolInformation,
) -> Self {
@@ -122,6 +132,24 @@ impl<'a> From<&'a SymbolInformation> for UsedSI<'a> {
}
}
}
+impl<'a> From<&'a WorkspaceSymbol> for UsedSI<'a> {
+ fn from(
+ WorkspaceSymbol {
+ location,
+ data: _,
+ base_symbol_information:
+ BaseSymbolInformation { name, kind, tags, container_name },
+ }: &'a WorkspaceSymbol,
+ ) -> Self {
+ UsedSI {
+ name,
+ kind: *kind,
+ tags: tags.as_deref(),
+ at: location.into(),
+ right: container_name.as_deref(),
+ }
+ }
+}
impl<'a> From<(&'a DocumentSymbol, &'a PathBuf)> for UsedSI<'a> {
fn from(
(
@@ -160,7 +188,9 @@ pub enum SymbolsList {
}
impl Default for SymbolsList {
fn default() -> Self {
- Self::Workspace(WorkspaceSymbolResponse::Flat(vec![]))
+ Self::Workspace(WorkspaceSymbolResponse::WorkspaceSymbolList(
+ vec![],
+ ))
}
}
@@ -169,8 +199,17 @@ impl GenericMenu<Symb> {
let tree = tree
.iter()
.map(|x| SymbolInformation {
- name: x.file_name().unwrap().to_str().unwrap().to_string(),
- kind: SymbolKind::FILE,
+ base_symbol_information: BaseSymbolInformation {
+ name: x
+ .file_name()
+ .unwrap()
+ .to_str()
+ .unwrap()
+ .to_string(),
+ kind: SymbolKind::File,
+ container_name: None,
+ tags: None,
+ },
location: Location {
range: lsp_types::Range {
end: default(),
@@ -178,10 +217,9 @@ impl GenericMenu<Symb> {
},
uri: Url::from_file_path(&x).unwrap(),
},
- container_name: None,
+
#[allow(deprecated)]
deprecated: None,
- tags: None,
})
.collect();
Self { data: (default(), tree, bmk, default(), orig), ..default() }
@@ -211,35 +249,35 @@ fn r<'a>(
const MAP: [([u8; 3], [u8; 3], &str); 85] = {
(
amap::amap! {
- const { SymbolKind::FILE.0 as usize } => ("#9a9b9a", "󰈙 "),
- const { SymbolKind::METHOD.0 as usize } | const { SymbolKind::FUNCTION.0 as usize } => ("#FFD173", "λ "),
- const { SymbolKind::CONSTRUCTOR.0 as usize } => ("#FFAD66", "->"),
- const { SymbolKind::FIELD.0 as usize } => ("#E06C75", "x."),
- const { SymbolKind::VARIABLE.0 as usize } => ("#E06C75", "x "),
- const { SymbolKind::MODULE.0 as usize } => ("#D5FF80", "::"),
- const { SymbolKind::PROPERTY.0 as usize } => ("#e6e1cf", "x."),
- // const { SymbolKind::VALUE.0 as usize } => ("#DFBFFF", "4 "),
- const { SymbolKind::ENUM.0 as usize } => ("#73b9ff", "u󰓹"),
- const { SymbolKind::ENUM_MEMBER.0 as usize } => ("#73b9ff", ":󰓹"),
- // const { SymbolKind::SNIPPET.0 as usize } => ("#9a9b9a", "! "),
- const { SymbolKind::INTERFACE.0 as usize } => ("#E5C07B", "t "),
- // const { SymbolKind::REFERENCE.0 as usize } => ("#9a9b9a", "& "),
- const { SymbolKind::CONSTANT.0 as usize } => ("#DFBFFF", "N "),
- const { SymbolKind::STRUCT.0 as usize } => ("#73D0FF", "X{"),
- const { SymbolKind::OPERATOR.0 as usize } => ("#F29E74", "+ "),
- const { SymbolKind::TYPE_PARAMETER.0 as usize } => ("#9a9b9a", "T "),
- // const { SymbolKind::KEYWORD.0 as usize } => ("#FFAD66", "as"),
+ const { i(SymbolKind::File) } => ("#9a9b9a", "󰈙 "),
+ const { i(SymbolKind::Method) } | const { i(SymbolKind::Function) } => ("#FFD173", "λ "),
+ const { i(SymbolKind::Constructor) } => ("#FFAD66", "->"),
+ const { i(SymbolKind::Field) } => ("#E06C75", "x."),
+ const { i(SymbolKind::Variable) } => ("#E06C75", "x "),
+ const { i(SymbolKind::Module) } => ("#D5FF80", "::"),
+ const { i(SymbolKind::Property) } => ("#e6e1cf", "x."),
+ // const { SymbolKind::Val.0 as usize } => ("#DFBFFF", "4 "),
+ const { i(SymbolKind::Enum) } => ("#73b9ff", "u󰓹"),
+ const { i(SymbolKind::EnumMember) } => ("#73b9ff", ":󰓹"),
+ // const { SymbolKind::Snipp.0 as usize } => ("#9a9b9a", "! "),
+ const { i(SymbolKind::Interface) } => ("#E5C07B", "t "),
+ // const { SymbolKind::Referen.0 as usize } => ("#9a9b9a", "& "),
+ const { i(SymbolKind::Constant) } => ("#DFBFFF", "N "),
+ const { i(SymbolKind::Struct) } => ("#73D0FF", "X{"),
+ const { i(SymbolKind::Operator) } => ("#F29E74", "+ "),
+ const { i(SymbolKind::TypeParameter) } => ("#9a9b9a", "T "),
+ // const { SymbolKind::Keyword.0 as usize } => ("#FFAD66", "as"),
- const { SymbolKind::MACRO.0 as usize } => ("#f28f74", "! "),
- const { SymbolKind::PROC_MACRO.0 as usize } => ("#f28f74", "r!"),
- const { SymbolKind::BOOKMARK.0 as usize } => ("#73D0FF", "󰃀 "),
+ // const { SymbolKind::Macro.0 as usize } => ("#f28f74", "! "),
+ // const { SymbolKind::ProcMacro.0 as usize } => ("#f28f74", "r!"),
+ // const { SymbolKind::Bookmark.0 as usize } => ("#73D0FF", "󰃀 "),
_ => ("#9a9b9a", " ")
})
.map(
const |(x, y)| (set_a(color_(x), 0.5), color_(x), y),
)
};
- let (bgt, col, ty) = MAP[x.kind.0 as usize];
+ let (bgt, col, ty) = MAP[i(x.kind)];
b.iter_mut().zip(ty.chars()).for_each(|(x, c)| {
*x = (Style::new(col, bgt) | Style::BOLD).basic(c)
});