mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
Add support for primitives in "jump to definition" feature
This commit is contained in:
parent
1cd17addad
commit
8f3fd3d08c
@ -5,6 +5,7 @@
|
||||
//!
|
||||
//! Use the `render_with_highlighting` to highlight some rust code.
|
||||
|
||||
use crate::clean::PrimitiveType;
|
||||
use crate::html::escape::Escape;
|
||||
use crate::html::render::Context;
|
||||
|
||||
@ -584,6 +585,13 @@ fn string<T: Display>(
|
||||
.ok()
|
||||
.map(|(url, _, _)| url)
|
||||
}
|
||||
LinkFromSrc::Primitive(prim) => format::href_with_root_path(
|
||||
PrimitiveType::primitive_locations(context.tcx())[&prim],
|
||||
context,
|
||||
Some(context_info.root_path),
|
||||
)
|
||||
.ok()
|
||||
.map(|(url, _, _)| url),
|
||||
}
|
||||
})
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::clean;
|
||||
use crate::clean::{self, PrimitiveType};
|
||||
use crate::html::sources;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
@ -22,6 +22,7 @@ use std::path::{Path, PathBuf};
|
||||
crate enum LinkFromSrc {
|
||||
Local(clean::Span),
|
||||
External(DefId),
|
||||
Primitive(PrimitiveType),
|
||||
}
|
||||
|
||||
/// This function will do at most two things:
|
||||
@ -73,17 +74,20 @@ impl<'tcx> SpanMapVisitor<'tcx> {
|
||||
Some(def_id)
|
||||
}
|
||||
Res::Local(_) => None,
|
||||
Res::PrimTy(p) => {
|
||||
// FIXME: Doesn't handle "path-like" primitives like arrays or tuples.
|
||||
let span = path_span.unwrap_or(path.span);
|
||||
self.matches.insert(span, LinkFromSrc::Primitive(PrimitiveType::from(p)));
|
||||
return;
|
||||
}
|
||||
Res::Err => return,
|
||||
_ => return,
|
||||
};
|
||||
if let Some(span) = self.tcx.hir().res_span(path.res) {
|
||||
self.matches.insert(
|
||||
path_span.unwrap_or_else(|| path.span),
|
||||
LinkFromSrc::Local(clean::Span::new(span)),
|
||||
);
|
||||
} else if let Some(def_id) = info {
|
||||
self.matches
|
||||
.insert(path_span.unwrap_or_else(|| path.span), LinkFromSrc::External(def_id));
|
||||
.insert(path_span.unwrap_or(path.span), LinkFromSrc::Local(clean::Span::new(span)));
|
||||
} else if let Some(def_id) = info {
|
||||
self.matches.insert(path_span.unwrap_or(path.span), LinkFromSrc::External(def_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user