Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show erased terms on hover #435

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 51 additions & 35 deletions lang/driver/src/info/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,24 @@
/// Every syntax node which implements this trait can be traversed and
/// make source-code indexed information available for the LSP server.
trait CollectInfo {
fn collect_info(&self, _db: &Database, _collector: &mut InfoCollector);
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
self.collect_info_erased(db, collector, false)
}

Check warning on line 83 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L81-L83

Added lines #L81 - L83 were not covered by tests
/// The information whether a syntax node is erased is not always annotated in the syntax node itself,
/// but in the surrounding "Arg" or "Param" node. We therefore have to pass through the information whether
/// a syntax node for which we want to generate a "Info" struct is erased.
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, _erased: bool) {
self.collect_info(db, collector);
}

Check warning on line 89 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L87-L89

Added lines #L87 - L89 were not covered by tests
}

// Generic implementations
//
//

impl<T: CollectInfo> CollectInfo for Box<T> {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
(**self).collect_info(db, collector)
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {
(**self).collect_info_erased(db, collector, erased)

Check warning on line 98 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L97-L98

Added lines #L97 - L98 were not covered by tests
}
}

Expand Down Expand Up @@ -253,33 +261,34 @@
//

impl CollectInfo for Exp {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 264 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L264

Added line #L264 was not covered by tests
match self {
Exp::Variable(e) => e.collect_info(db, collector),
Exp::TypCtor(e) => e.collect_info(db, collector),
Exp::Call(e) => e.collect_info(db, collector),
Exp::DotCall(e) => e.collect_info(db, collector),
Exp::Hole(e) => e.collect_info(db, collector),
Exp::TypeUniv(e) => e.collect_info(db, collector),
Exp::Anno(e) => e.collect_info(db, collector),
Exp::LocalMatch(e) => e.collect_info(db, collector),
Exp::LocalComatch(e) => e.collect_info(db, collector),
Exp::Variable(e) => e.collect_info_erased(db, collector, erased),
Exp::TypCtor(e) => e.collect_info_erased(db, collector, erased),
Exp::Call(e) => e.collect_info_erased(db, collector, erased),
Exp::DotCall(e) => e.collect_info_erased(db, collector, erased),
Exp::Hole(e) => e.collect_info_erased(db, collector, erased),
Exp::TypeUniv(e) => e.collect_info_erased(db, collector, erased),
Exp::Anno(e) => e.collect_info_erased(db, collector, erased),
Exp::LocalMatch(e) => e.collect_info_erased(db, collector, erased),
Exp::LocalComatch(e) => e.collect_info_erased(db, collector, erased),

Check warning on line 274 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L266-L274

Added lines #L266 - L274 were not covered by tests
}
}
}

impl CollectInfo for Variable {
fn collect_info(&self, _db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, _db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 280 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L280

Added line #L280 was not covered by tests
let Variable { span, inferred_type, name, .. } = self;
if let (Some(span), Some(typ)) = (span, inferred_type) {
let info = VariableInfo { typ: typ.print_to_string(None), name: name.clone().id };
let info =
VariableInfo { typ: typ.print_to_string(None), name: name.clone().id, erased };

Check warning on line 284 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L283-L284

Added lines #L283 - L284 were not covered by tests
collector.add_info(*span, info)
}
}
}

impl CollectInfo for TypCtor {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 291 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L291

Added line #L291 was not covered by tests
let TypCtor { span, args, name } = self;
if let Some(span) = span {
let decl = lookup_decl(db, name);
Expand All @@ -296,15 +305,15 @@
}
_ => (None, None),
};
let info = TypeCtorInfo { name: name.clone().id, definition_site, doc };
let info = TypeCtorInfo { name: name.clone().id, definition_site, doc, erased };

Check warning on line 308 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L308

Added line #L308 was not covered by tests
collector.add_info(*span, info)
}
args.collect_info(db, collector)
}
}

impl CollectInfo for Call {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 316 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L316

Added line #L316 was not covered by tests
let Call { span, kind, args, inferred_type, name } = self;
if let (Some(span), Some(typ)) = (span, inferred_type) {
let (definition_site, doc) = match kind {
Expand Down Expand Up @@ -340,6 +349,7 @@
typ: typ.print_to_string(None),
name: name.clone().id,
definition_site,
erased,

Check warning on line 352 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L352

Added line #L352 was not covered by tests
};
collector.add_info(*span, info)
}
Expand All @@ -348,7 +358,7 @@
}

impl CollectInfo for DotCall {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 361 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L361

Added line #L361 was not covered by tests
let DotCall { span, kind, exp, args, inferred_type, name } = self;
if let (Some(span), Some(typ)) = (span, inferred_type) {
let (definition_site, doc) = match kind {
Expand All @@ -375,6 +385,7 @@
name: name.clone().id,
typ: typ.print_to_string(None),
definition_site,
erased,

Check warning on line 388 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L388

Added line #L388 was not covered by tests
};
collector.add_info(*span, info)
}
Expand All @@ -384,7 +395,7 @@
}

impl CollectInfo for Hole {
fn collect_info(&self, _db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, _db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 398 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L398

Added line #L398 was not covered by tests
let Hole { span, kind: _, metavar, inferred_type, inferred_ctx, args, solution: _ } = self;
if let Some(span) = span {
let metavar_state = collector
Expand All @@ -405,40 +416,43 @@
.map(|subst| subst.iter().map(|exp| exp.print_to_string(None)).collect())
.collect(),
metavar_state: metavar_str,
erased,

Check warning on line 419 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L419

Added line #L419 was not covered by tests
};
collector.add_info(*span, info)
}
}
}

impl CollectInfo for TypeUniv {
fn collect_info(&self, _db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, _db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 427 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L427

Added line #L427 was not covered by tests
let TypeUniv { span } = self;
if let Some(span) = span {
let info = TypeUnivInfo {};
let info = TypeUnivInfo { erased };

Check warning on line 430 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L430

Added line #L430 was not covered by tests
collector.add_info(*span, info)
}
}
}

impl CollectInfo for Anno {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 437 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L437

Added line #L437 was not covered by tests
let Anno { span, exp, typ, normalized_type } = self;
if let (Some(span), Some(typ)) = (span, normalized_type) {
let info = AnnoInfo { typ: typ.print_to_string(None) };
let info = AnnoInfo { typ: typ.print_to_string(None), erased };

Check warning on line 440 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L440

Added line #L440 was not covered by tests
collector.add_info(*span, info)
}
exp.collect_info(db, collector);
typ.collect_info(db, collector)
// We pass through the erased flag to the annotated expression.
exp.collect_info_erased(db, collector, erased);
// We always mark the type argument as erased in the LSP!
typ.collect_info_erased(db, collector, true)

Check warning on line 446 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L444-L446

Added lines #L444 - L446 were not covered by tests
}
}

impl CollectInfo for LocalMatch {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 451 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L451

Added line #L451 was not covered by tests
let LocalMatch { span, on_exp, ret_typ, cases, inferred_type, .. } = self;
if let (Some(span), Some(typ)) = (span, inferred_type) {
// Add info
let info = LocalMatchInfo { typ: typ.print_to_string(None) };
let info = LocalMatchInfo { typ: typ.print_to_string(None), erased };

Check warning on line 455 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L455

Added line #L455 was not covered by tests
collector.add_info(*span, info)
}
on_exp.collect_info(db, collector);
Expand All @@ -448,11 +462,11 @@
}

impl CollectInfo for LocalComatch {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
fn collect_info_erased(&self, db: &Database, collector: &mut InfoCollector, erased: bool) {

Check warning on line 465 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L465

Added line #L465 was not covered by tests
let LocalComatch { span, cases, inferred_type, .. } = self;
if let (Some(span), Some(typ)) = (span, inferred_type) {
// Add info
let info = LocalComatchInfo { typ: typ.print_to_string(None) };
let info = LocalComatchInfo { typ: typ.print_to_string(None), erased };

Check warning on line 469 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L469

Added line #L469 was not covered by tests
collector.add_info(*span, info)
}
cases.collect_info(db, collector)
Expand Down Expand Up @@ -493,9 +507,11 @@
impl CollectInfo for Arg {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
match self {
Arg::UnnamedArg { arg, .. } => arg.collect_info(db, collector),
Arg::NamedArg { arg, .. } => arg.collect_info(db, collector),
Arg::InsertedImplicitArg { hole, .. } => hole.collect_info(db, collector),
Arg::UnnamedArg { arg, erased, .. } => arg.collect_info_erased(db, collector, *erased),
Arg::NamedArg { arg, erased, .. } => arg.collect_info_erased(db, collector, *erased),
Arg::InsertedImplicitArg { hole, erased, .. } => {
hole.collect_info_erased(db, collector, *erased)

Check warning on line 513 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L510-L513

Added lines #L510 - L513 were not covered by tests
}
}
}
}
Expand All @@ -508,8 +524,8 @@

impl CollectInfo for Param {
fn collect_info(&self, db: &Database, collector: &mut InfoCollector) {
let Param { typ, .. } = self;
typ.collect_info(db, collector)
let Param { typ, erased, .. } = self;
typ.collect_info_erased(db, collector, *erased)

Check warning on line 528 in lang/driver/src/info/collect.rs

View check run for this annotation

Codecov / codecov/patch

lang/driver/src/info/collect.rs#L527-L528

Added lines #L527 - L528 were not covered by tests
}
}

Expand Down
12 changes: 11 additions & 1 deletion lang/driver/src/info/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl From<LetInfo> for InfoContent {
pub struct VariableInfo {
pub name: String,
pub typ: String,
pub erased: bool,
}

impl From<VariableInfo> for InfoContent {
Expand All @@ -181,6 +182,7 @@ pub struct TypeCtorInfo {
/// Doc comment from the definition site
pub doc: Option<Vec<String>>,
pub name: String,
pub erased: bool,
}

impl From<TypeCtorInfo> for InfoContent {
Expand All @@ -200,6 +202,7 @@ pub struct CallInfo {
pub kind: CallKind,
pub name: String,
pub typ: String,
pub erased: bool,
}

impl From<CallInfo> for InfoContent {
Expand All @@ -219,6 +222,7 @@ pub struct DotCallInfo {
pub kind: DotCallKind,
pub name: String,
pub typ: String,
pub erased: bool,
}

impl From<DotCallInfo> for InfoContent {
Expand All @@ -229,7 +233,9 @@ impl From<DotCallInfo> for InfoContent {

/// Information for type universes
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeUnivInfo {}
pub struct TypeUnivInfo {
pub erased: bool,
}

impl From<TypeUnivInfo> for InfoContent {
fn from(value: TypeUnivInfo) -> Self {
Expand All @@ -241,6 +247,7 @@ impl From<TypeUnivInfo> for InfoContent {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AnnoInfo {
pub typ: String,
pub erased: bool,
}

impl From<AnnoInfo> for InfoContent {
Expand Down Expand Up @@ -276,6 +283,7 @@ impl From<CaseInfo> for InfoContent {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LocalMatchInfo {
pub typ: String,
pub erased: bool,
}

impl From<LocalMatchInfo> for InfoContent {
Expand All @@ -288,6 +296,7 @@ impl From<LocalMatchInfo> for InfoContent {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LocalComatchInfo {
pub typ: String,
pub erased: bool,
}

impl From<LocalComatchInfo> for InfoContent {
Expand All @@ -305,6 +314,7 @@ pub struct HoleInfo {
pub args: Vec<Vec<String>>,
/// `Some(e)` if the solution`e` has been found for the metavariable.
pub metavar_state: Option<String>,
pub erased: bool,
}

impl From<HoleInfo> for InfoContent {
Expand Down
Loading
Loading