Skip to content

Commit

Permalink
Add hover for patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
BinderDavid committed Jan 8, 2025
1 parent ca70ff0 commit d92084e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lang/driver/src/info/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::data::{
};
use super::item::Item;
use super::lookup::{lookup_codef, lookup_ctor, lookup_decl, lookup_def, lookup_dtor, lookup_let};
use super::CaseInfo;
use super::{CaseInfo, PatternInfo};

/// Traverse the program and collect information for the LSP server.
#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -459,13 +459,24 @@ impl CollectInfo for LocalComatch {
}
}

impl CollectInfo for Pattern {
fn collect_info(&self, _db: &Database, collector: &mut InfoCollector) {
let Pattern { span, name, is_copattern, .. } = self;
if let Some(span) = span {
let info = PatternInfo { is_copattern: *is_copattern, name: name.id.clone() };
collector.add_info(*span, info)
}
}
}

impl CollectInfo for Case {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
let Case { body, span, .. } = self;
let Case { body, span, pattern, .. } = self;
if let Some(span) = span {
let info = CaseInfo {};
collector.add_info(*span, info)
}
pattern.collect_info(db, collector);
body.collect_info(db, collector)
}
}
Expand Down
15 changes: 15 additions & 0 deletions lang/driver/src/info/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum InfoContent {
LocalComatchInfo(LocalComatchInfo),
// Various
CaseInfo(CaseInfo),
PatternInfo(PatternInfo),
// Toplevel Declarations
DataInfo(DataInfo),
CtorInfo(CtorInfo),
Expand Down Expand Up @@ -247,6 +248,20 @@ impl From<AnnoInfo> for InfoContent {
InfoContent::AnnoInfo(value)
}
}

// Information for patterns and copatterns
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PatternInfo {
pub name: String,
pub is_copattern: bool,
}

impl From<PatternInfo> for InfoContent {
fn from(value: PatternInfo) -> Self {
InfoContent::PatternInfo(value)
}
}

// Information for clauses in pattern and copattern matches
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CaseInfo {}
Expand Down
11 changes: 11 additions & 0 deletions lang/lsp/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl ToHoverContent for InfoContent {
InfoContent::LocalComatchInfo(i) => i.to_hover_content(),
InfoContent::HoleInfo(i) => i.to_hover_content(),
InfoContent::AnnoInfo(i) => i.to_hover_content(),
InfoContent::PatternInfo(i) => i.to_hover_content(),
InfoContent::CaseInfo(i) => i.to_hover_content(),
InfoContent::DataInfo(i) => i.to_hover_content(),
InfoContent::CtorInfo(i) => i.to_hover_content(),
Expand Down Expand Up @@ -183,6 +184,16 @@ impl ToHoverContent for AnnoInfo {
}
}

impl ToHoverContent for PatternInfo {
fn to_hover_content(self) -> HoverContents {
if self.is_copattern {
HoverContents::Array(vec![MarkedString::String(format!("Copattern: `{}`", self.name))])
} else {
HoverContents::Array(vec![MarkedString::String(format!("Pattern: `{}`", self.name))])
}
}
}

impl ToHoverContent for CaseInfo {
fn to_hover_content(self) -> HoverContents {
HoverContents::Array(vec![MarkedString::String("Clause".to_owned())])
Expand Down

0 comments on commit d92084e

Please sign in to comment.