Record derive helper attributes, resolve them in IDE layer

This commit is contained in:
Lukas Wirth 2022-07-24 14:05:37 +02:00
parent 4e60db2d07
commit aa1491ecde
22 changed files with 144 additions and 58 deletions

View file

@ -190,7 +190,8 @@ pub(crate) fn resolve_doc_path_for_def(
| Definition::SelfType(_)
| Definition::Local(_)
| Definition::GenericParam(_)
| Definition::Label(_) => None,
| Definition::Label(_)
| Definition::DeriveHelper(_) => None,
}
.map(Definition::from)
}
@ -515,7 +516,8 @@ fn filename_and_frag_for_def(
| Definition::GenericParam(_)
| Definition::Label(_)
| Definition::BuiltinAttr(_)
| Definition::ToolModule(_) => return None,
| Definition::ToolModule(_)
| Definition::DeriveHelper(_) => return None,
};
Some((def, res, None))

View file

@ -370,6 +370,8 @@ pub(super) fn definition(
// FIXME: We should be able to show more info about these
Definition::BuiltinAttr(it) => return render_builtin_attr(db, it),
Definition::ToolModule(it) => return Some(Markup::fenced_block(&it.name(db))),
// FIXME: it.name(db)
Definition::DeriveHelper(_it) => ("derive-helper".to_owned(), None),
};
let docs = match config.documentation {

View file

@ -196,6 +196,8 @@ impl TryToNav for Definition {
Definition::BuiltinType(_) => None,
Definition::ToolModule(_) => None,
Definition::BuiltinAttr(_) => None,
// FIXME: The focus range should be set to the helper declaration
Definition::DeriveHelper(it) => it.derive().try_to_nav(db),
}
}
}

View file

@ -237,7 +237,8 @@ fn signature_help_for_generics(
| hir::PathResolution::Local(_)
| hir::PathResolution::TypeParam(_)
| hir::PathResolution::ConstParam(_)
| hir::PathResolution::SelfType(_) => return None,
| hir::PathResolution::SelfType(_)
| hir::PathResolution::DeriveHelper(_) => return None,
};
generic_def

View file

@ -107,6 +107,7 @@ pub struct HlRange {
// builtinType:: Emitted for builtin types like `u32`, `str` and `f32`.
// comment:: Emitted for comments.
// constParameter:: Emitted for const parameters.
// deriveHelper:: Emitted for derive helper attributes.
// enumMember:: Emitted for enum variants.
// generic:: Emitted for generic tokens that have no mapping.
// keyword:: Emitted for keywords.

View file

@ -472,6 +472,7 @@ fn highlight_def(
Definition::Label(_) => Highlight::new(HlTag::Symbol(SymbolKind::Label)),
Definition::BuiltinAttr(_) => Highlight::new(HlTag::Symbol(SymbolKind::BuiltinAttr)),
Definition::ToolModule(_) => Highlight::new(HlTag::Symbol(SymbolKind::ToolModule)),
Definition::DeriveHelper(_) => Highlight::new(HlTag::Symbol(SymbolKind::DeriveHelper)),
};
let def_crate = def.krate(db);

View file

@ -270,6 +270,7 @@ fn module_def_to_hl_tag(def: Definition) -> HlTag {
Definition::Label(_) => SymbolKind::Label,
Definition::BuiltinAttr(_) => SymbolKind::BuiltinAttr,
Definition::ToolModule(_) => SymbolKind::ToolModule,
Definition::DeriveHelper(_) => SymbolKind::DeriveHelper,
};
HlTag::Symbol(symbol)
}

View file

@ -134,6 +134,7 @@ impl HlTag {
SymbolKind::Const => "constant",
SymbolKind::ConstParam => "const_param",
SymbolKind::Derive => "derive",
SymbolKind::DeriveHelper => "derive_helper",
SymbolKind::Enum => "enum",
SymbolKind::Field => "field",
SymbolKind::Function => "function",