mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
change from krate to Option<krate> in syntax highlighting to incorporate modules which are not part of any crate
This commit is contained in:
parent
31e412c290
commit
02cd8c5c90
@ -222,10 +222,7 @@ pub(crate) fn highlight(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut hl = highlights::Highlights::new(root.text_range());
|
let mut hl = highlights::Highlights::new(root.text_range());
|
||||||
let krate = match sema.scope(&root) {
|
let krate = sema.scope(&root).map(|it| it.krate());
|
||||||
Some(it) => it.krate(),
|
|
||||||
None => return hl.to_vec(),
|
|
||||||
};
|
|
||||||
traverse(&mut hl, &sema, config, InRealFile::new(file_id, &root), krate, range_to_highlight);
|
traverse(&mut hl, &sema, config, InRealFile::new(file_id, &root), krate, range_to_highlight);
|
||||||
hl.to_vec()
|
hl.to_vec()
|
||||||
}
|
}
|
||||||
@ -235,7 +232,7 @@ fn traverse(
|
|||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
config: HighlightConfig,
|
config: HighlightConfig,
|
||||||
InRealFile { file_id, value: root }: InRealFile<&SyntaxNode>,
|
InRealFile { file_id, value: root }: InRealFile<&SyntaxNode>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
range_to_highlight: TextRange,
|
range_to_highlight: TextRange,
|
||||||
) {
|
) {
|
||||||
let is_unlinked = sema.file_to_module_def(file_id).is_none();
|
let is_unlinked = sema.file_to_module_def(file_id).is_none();
|
||||||
@ -498,7 +495,7 @@ fn string_injections(
|
|||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
config: HighlightConfig,
|
config: HighlightConfig,
|
||||||
file_id: EditionedFileId,
|
file_id: EditionedFileId,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
token: SyntaxToken,
|
token: SyntaxToken,
|
||||||
descended_token: &SyntaxToken,
|
descended_token: &SyntaxToken,
|
||||||
) -> ControlFlow<()> {
|
) -> ControlFlow<()> {
|
||||||
|
@ -15,7 +15,7 @@ use crate::{
|
|||||||
pub(super) fn highlight_format_string(
|
pub(super) fn highlight_format_string(
|
||||||
stack: &mut Highlights,
|
stack: &mut Highlights,
|
||||||
sema: &hir::Semantics<'_, ide_db::RootDatabase>,
|
sema: &hir::Semantics<'_, ide_db::RootDatabase>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
string: &ast::String,
|
string: &ast::String,
|
||||||
expanded_string: &ast::String,
|
expanded_string: &ast::String,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
|
@ -63,7 +63,7 @@ pub(super) fn token(
|
|||||||
|
|
||||||
pub(super) fn name_like(
|
pub(super) fn name_like(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
bindings_shadow_count: Option<&mut FxHashMap<hir::Name, u32>>,
|
bindings_shadow_count: Option<&mut FxHashMap<hir::Name, u32>>,
|
||||||
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
||||||
syntactic_name_ref_highlighting: bool,
|
syntactic_name_ref_highlighting: bool,
|
||||||
@ -272,7 +272,7 @@ fn keyword(token: SyntaxToken, kind: SyntaxKind) -> Highlight {
|
|||||||
|
|
||||||
fn highlight_name_ref(
|
fn highlight_name_ref(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
bindings_shadow_count: Option<&mut FxHashMap<hir::Name, u32>>,
|
bindings_shadow_count: Option<&mut FxHashMap<hir::Name, u32>>,
|
||||||
binding_hash: &mut Option<u64>,
|
binding_hash: &mut Option<u64>,
|
||||||
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
||||||
@ -401,9 +401,10 @@ fn highlight_name_ref(
|
|||||||
NameRefClass::ExternCrateShorthand { decl, krate: resolved_krate } => {
|
NameRefClass::ExternCrateShorthand { decl, krate: resolved_krate } => {
|
||||||
let mut h = HlTag::Symbol(SymbolKind::Module).into();
|
let mut h = HlTag::Symbol(SymbolKind::Module).into();
|
||||||
|
|
||||||
if resolved_krate != krate {
|
if krate.as_ref().is_some_and(|krate| resolved_krate != *krate) {
|
||||||
h |= HlMod::Library
|
h |= HlMod::Library;
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_public = decl.visibility(db) == hir::Visibility::Public;
|
let is_public = decl.visibility(db) == hir::Visibility::Public;
|
||||||
if is_public {
|
if is_public {
|
||||||
h |= HlMod::Public
|
h |= HlMod::Public
|
||||||
@ -431,7 +432,7 @@ fn highlight_name(
|
|||||||
bindings_shadow_count: Option<&mut FxHashMap<hir::Name, u32>>,
|
bindings_shadow_count: Option<&mut FxHashMap<hir::Name, u32>>,
|
||||||
binding_hash: &mut Option<u64>,
|
binding_hash: &mut Option<u64>,
|
||||||
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
name: ast::Name,
|
name: ast::Name,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
) -> Highlight {
|
) -> Highlight {
|
||||||
@ -476,7 +477,7 @@ fn calc_binding_hash(name: &hir::Name, shadow_count: u32) -> u64 {
|
|||||||
|
|
||||||
pub(super) fn highlight_def(
|
pub(super) fn highlight_def(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
def: Definition,
|
def: Definition,
|
||||||
edition: Edition,
|
edition: Edition,
|
||||||
is_ref: bool,
|
is_ref: bool,
|
||||||
@ -660,7 +661,7 @@ pub(super) fn highlight_def(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let def_crate = def.krate(db);
|
let def_crate = def.krate(db);
|
||||||
let is_from_other_crate = def_crate != Some(krate);
|
let is_from_other_crate = def_crate != krate;
|
||||||
let is_from_builtin_crate = def_crate.is_some_and(|def_crate| def_crate.is_builtin(db));
|
let is_from_builtin_crate = def_crate.is_some_and(|def_crate| def_crate.is_builtin(db));
|
||||||
let is_builtin = matches!(
|
let is_builtin = matches!(
|
||||||
def,
|
def,
|
||||||
@ -681,7 +682,7 @@ pub(super) fn highlight_def(
|
|||||||
|
|
||||||
fn highlight_method_call_by_name_ref(
|
fn highlight_method_call_by_name_ref(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
name_ref: &ast::NameRef,
|
name_ref: &ast::NameRef,
|
||||||
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
||||||
) -> Option<Highlight> {
|
) -> Option<Highlight> {
|
||||||
@ -691,7 +692,7 @@ fn highlight_method_call_by_name_ref(
|
|||||||
|
|
||||||
fn highlight_method_call(
|
fn highlight_method_call(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
method_call: &ast::MethodCallExpr,
|
method_call: &ast::MethodCallExpr,
|
||||||
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
||||||
) -> Option<Highlight> {
|
) -> Option<Highlight> {
|
||||||
@ -718,7 +719,7 @@ fn highlight_method_call(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let def_crate = func.module(sema.db).krate();
|
let def_crate = func.module(sema.db).krate();
|
||||||
let is_from_other_crate = def_crate != krate;
|
let is_from_other_crate = krate.as_ref().map_or(false, |krate| def_crate != *krate);
|
||||||
let is_from_builtin_crate = def_crate.is_builtin(sema.db);
|
let is_from_builtin_crate = def_crate.is_builtin(sema.db);
|
||||||
let is_public = func.visibility(sema.db) == hir::Visibility::Public;
|
let is_public = func.visibility(sema.db) == hir::Visibility::Public;
|
||||||
|
|
||||||
@ -791,7 +792,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
|
|||||||
fn highlight_name_ref_by_syntax(
|
fn highlight_name_ref_by_syntax(
|
||||||
name: ast::NameRef,
|
name: ast::NameRef,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
sema: &Semantics<'_, RootDatabase>,
|
||||||
krate: hir::Crate,
|
krate: Option<hir::Crate>,
|
||||||
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
is_unsafe_node: &impl Fn(AstPtr<Either<ast::Expr, ast::Pat>>) -> bool,
|
||||||
) -> Highlight {
|
) -> Highlight {
|
||||||
let default = HlTag::UnresolvedReference;
|
let default = HlTag::UnresolvedReference;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user