.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
use either::Either;
use hir::{HasAttrs, InFile, Semantics};
-use ide_db::{call_info::ActiveParameter, defs::Definition};
+use ide_db::{call_info::ActiveParameter, defs::Definition, SymbolKind};
use syntax::{
ast::{self, AstNode, AttrsOwner, DocCommentsOwner},
match_ast, AstToken, NodeOrToken, SyntaxNode, SyntaxToken, TextRange, TextSize,
intra_doc_links.extend(
extract_definitions_from_markdown(line)
.into_iter()
- .filter(|(link, ns, _)| {
- validate_intra_doc_link(sema.db, &def, link, *ns)
+ .filter_map(|(link, ns, range)| {
+ validate_intra_doc_link(sema.db, &def, &link, ns).zip(Some(range))
})
- .map(|(.., Range { start, end })| {
- TextRange::at(
- prev_range_start + TextSize::from(start as u32),
- TextSize::from((end - start) as u32),
+ .map(|(def, Range { start, end })| {
+ (
+ def,
+ TextRange::at(
+ prev_range_start + TextSize::from(start as u32),
+ TextSize::from((end - start) as u32),
+ ),
)
}),
);
}
}
- for range in intra_doc_links {
+ for (def, range) in intra_doc_links {
hl.add(HlRange {
range,
- highlight: HlTag::IntraDocLink | HlMod::Documentation,
+ highlight: module_def_to_hl_tag(def)
+ | HlMod::Documentation
+ | HlMod::Injected
+ | HlMod::IntraDocLink,
binding_hash: None,
});
}
def: &Definition,
link: &str,
ns: Option<hir::Namespace>,
-) -> bool {
+) -> Option<hir::ModuleDef> {
match def {
Definition::ModuleDef(def) => match def {
hir::ModuleDef::Module(it) => it.resolve_doc_path(db, &link, ns),
| Definition::GenericParam(_)
| Definition::Label(_) => None,
}
- .is_some()
+}
+
+fn module_def_to_hl_tag(def: hir::ModuleDef) -> HlTag {
+ let symbol = match def {
+ hir::ModuleDef::Module(_) => SymbolKind::Module,
+ hir::ModuleDef::Function(_) => SymbolKind::Function,
+ hir::ModuleDef::Adt(hir::Adt::Struct(_)) => SymbolKind::Struct,
+ hir::ModuleDef::Adt(hir::Adt::Enum(_)) => SymbolKind::Enum,
+ hir::ModuleDef::Adt(hir::Adt::Union(_)) => SymbolKind::Union,
+ hir::ModuleDef::Variant(_) => SymbolKind::Variant,
+ hir::ModuleDef::Const(_) => SymbolKind::Const,
+ hir::ModuleDef::Static(_) => SymbolKind::Static,
+ hir::ModuleDef::Trait(_) => SymbolKind::Trait,
+ hir::ModuleDef::TypeAlias(_) => SymbolKind::TypeAlias,
+ hir::ModuleDef::BuiltinType(_) => return HlTag::BuiltinType,
+ };
+ HlTag::Symbol(symbol)
}
Comment,
EscapeSequence,
FormatSpecifier,
- IntraDocLink,
Keyword,
NumericLiteral,
Operator,
Static,
/// Used for items in impls&traits.
Associated,
+ /// Used for intra doc links in doc injection.
+ IntraDocLink,
/// Keep this last!
Unsafe,
HlTag::Comment => "comment",
HlTag::EscapeSequence => "escape_sequence",
HlTag::FormatSpecifier => "format_specifier",
- HlTag::IntraDocLink => "intra_doc_link",
HlTag::Keyword => "keyword",
HlTag::Punctuation(punct) => match punct {
HlPunct::Bracket => "bracket",
HlMod::ControlFlow,
HlMod::Definition,
HlMod::Documentation,
+ HlMod::IntraDocLink,
HlMod::Injected,
HlMod::Mutable,
HlMod::Consuming,
fn as_str(self) -> &'static str {
match self {
+ HlMod::Associated => "associated",
HlMod::Attribute => "attribute",
+ HlMod::Callable => "callable",
+ HlMod::Consuming => "consuming",
HlMod::ControlFlow => "control",
HlMod::Definition => "declaration",
HlMod::Documentation => "documentation",
HlMod::Injected => "injected",
+ HlMod::IntraDocLink => "intra_doc_link",
HlMod::Mutable => "mutable",
- HlMod::Consuming => "consuming",
- HlMod::Unsafe => "unsafe",
- HlMod::Callable => "callable",
HlMod::Static => "static",
- HlMod::Associated => "associated",
+ HlMod::Unsafe => "unsafe",
}
}
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
<span class="brace">}</span>
<span class="brace">}</span>
-<span class="comment documentation">/// </span><span class="intra_doc_link documentation">[`Foo`](Foo)</span><span class="comment documentation"> is a struct</span>
-<span class="comment documentation">/// </span><span class="intra_doc_link documentation">[`all_the_links`](all_the_links)</span><span class="comment documentation"> is this function</span>
+<span class="comment documentation">/// </span><span class="struct documentation intra_doc_link injected">[`Foo`](Foo)</span><span class="comment documentation"> is a struct</span>
+<span class="comment documentation">/// </span><span class="function documentation intra_doc_link injected">[`all_the_links`](all_the_links)</span><span class="comment documentation"> is this function</span>
<span class="comment documentation">/// [`noop`](noop) is a macro below</span>
<span class="keyword">pub</span> <span class="keyword">fn</span> <span class="function declaration">all_the_links</span><span class="parenthesis">(</span><span class="parenthesis">)</span> <span class="brace">{</span><span class="brace">}</span>
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.label { color: #DFAF8F; font-style: italic; }
.comment { color: #7F9F7F; }
.documentation { color: #629755; }
-.intra_doc_link { color: #A9C577; }
+.intra_doc_link { font-style: italic; }
.injected { opacity: 0.65 ; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
(ESCAPE_SEQUENCE, "escapeSequence"),
(FORMAT_SPECIFIER, "formatSpecifier"),
(GENERIC, "generic"),
- (INTRA_DOC_LINK, "intraDocLink"),
(LABEL, "label"),
(LIFETIME, "lifetime"),
(PARENTHESIS, "parenthesis"),
(UNSAFE, "unsafe"),
(ATTRIBUTE_MODIFIER, "attribute"),
(CALLABLE, "callable"),
+ (INTRA_DOC_LINK, "intraDocLink"),
];
#[derive(Default)]
HlTag::Comment => lsp_types::SemanticTokenType::COMMENT,
HlTag::EscapeSequence => semantic_tokens::ESCAPE_SEQUENCE,
HlTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER,
- HlTag::IntraDocLink => semantic_tokens::INTRA_DOC_LINK,
HlTag::Keyword => lsp_types::SemanticTokenType::KEYWORD,
HlTag::None => semantic_tokens::GENERIC,
HlTag::Operator => lsp_types::SemanticTokenType::OPERATOR,
HlMod::Unsafe => semantic_tokens::UNSAFE,
HlMod::Callable => semantic_tokens::CALLABLE,
HlMod::Static => lsp_types::SemanticTokenModifier::STATIC,
+ HlMod::IntraDocLink => semantic_tokens::INTRA_DOC_LINK,
HlMod::Associated => continue,
};
mods |= modifier;