Skip to content

Commit 9518e2f

Browse files
bors[bot]GrayJackkjeremySomeoneToIgnore
authored
5451: Highlight more cases of SyntaxKind when it is a punctuation r=matklad a=GrayJack This maybe closes #5406 Closes #5453 Separate what one expect to be a punctuation semantic token (like `,`, `;`, `(`, etc), and what is not (`&`, `::`, `+`, etc) 5463: Bump lexer r=matklad a=kjeremy Since we're now on rust 1.45 5465: Bump chalk r=matklad a=kjeremy 5466: Do not show default types in function and closure return values r=matklad a=SomeoneToIgnore Avoid things like <img width="522" alt="image" src="https://user-images.githubusercontent.com/2690773/87985936-1bbe4f80-cae5-11ea-9b8a-5383d896c296.png"> Co-authored-by: GrayJack <[email protected]> Co-authored-by: kjeremy <[email protected]> Co-authored-by: Kirill Bulatov <[email protected]>
5 parents 818aeb8 + 5ca3855 + d8eec71 + 9cfb373 + 54cc3fe commit 9518e2f

File tree

12 files changed

+141
-92
lines changed

12 files changed

+141
-92
lines changed

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_hir_ty/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ test_utils = { path = "../test_utils" }
2828

2929
scoped-tls = "1"
3030

31-
chalk-solve = { version = "0.17.0" }
32-
chalk-ir = { version = "0.17.0" }
33-
chalk-recursive = { version = "0.17.0" }
31+
chalk-solve = { version = "0.18.0" }
32+
chalk-ir = { version = "0.18.0" }
33+
chalk-recursive = { version = "0.18.0" }
3434

3535
[dev-dependencies]
3636
insta = "0.16.0"

crates/ra_hir_ty/src/display.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,12 @@ impl HirDisplay for ApplicationTy {
257257
write!(f, ")")?;
258258
let ret = sig.ret();
259259
if *ret != Ty::unit() {
260-
write!(f, " -> {}", ret.display(f.db))?;
260+
let ret_display = if f.omit_verbose_types() {
261+
ret.display_truncated(f.db, f.max_size)
262+
} else {
263+
ret.display(f.db)
264+
};
265+
write!(f, " -> {}", ret_display)?;
261266
}
262267
}
263268
TypeCtor::FnDef(def) => {
@@ -288,7 +293,12 @@ impl HirDisplay for ApplicationTy {
288293
write!(f, ")")?;
289294
let ret = sig.ret();
290295
if *ret != Ty::unit() {
291-
write!(f, " -> {}", ret.display(f.db))?;
296+
let ret_display = if f.omit_verbose_types() {
297+
ret.display_truncated(f.db, f.max_size)
298+
} else {
299+
ret.display(f.db)
300+
};
301+
write!(f, " -> {}", ret_display)?;
292302
}
293303
}
294304
TypeCtor::Adt(def_id) => {
@@ -397,7 +407,13 @@ impl HirDisplay for ApplicationTy {
397407
f.write_joined(sig.params(), ", ")?;
398408
write!(f, "|")?;
399409
};
400-
write!(f, " -> {}", sig.ret().display(f.db))?;
410+
411+
let ret_display = if f.omit_verbose_types() {
412+
sig.ret().display_truncated(f.db, f.max_size)
413+
} else {
414+
sig.ret().display(f.db)
415+
};
416+
write!(f, " -> {}", ret_display)?;
401417
} else {
402418
write!(f, "{{closure}}")?;
403419
}

crates/ra_ide/src/inlay_hints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ fn main() {
425425
//^^ Test<i32>
426426
let zz_ref = &zz;
427427
//^^^^^^ &Test<i32>
428+
let test = || zz;
429+
//^^^^ || -> Test<i32>
428430
}"#,
429431
);
430432
}

crates/ra_ide/src/syntax_highlighting.rs

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -539,21 +539,52 @@ fn highlight_element(
539539
_ => h,
540540
}
541541
}
542-
T![*] => {
543-
let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
544-
545-
let expr = prefix_expr.expr()?;
546-
let ty = sema.type_of_expr(&expr)?;
547-
if !ty.is_raw_ptr() {
548-
return None;
549-
} else {
550-
HighlightTag::Operator | HighlightModifier::Unsafe
542+
p if p.is_punct() => match p {
543+
T![::] | T![->] | T![=>] | T![&] | T![..] | T![=] | T![@] => {
544+
HighlightTag::Operator.into()
551545
}
552-
}
553-
T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
554-
Highlight::new(HighlightTag::Macro)
555-
}
556-
p if p.is_punct() => HighlightTag::Punctuation.into(),
546+
T![!] if element.parent().and_then(ast::MacroCall::cast).is_some() => {
547+
HighlightTag::Macro.into()
548+
}
549+
T![*] if element.parent().and_then(ast::PointerType::cast).is_some() => {
550+
HighlightTag::Keyword.into()
551+
}
552+
T![*] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
553+
let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?;
554+
555+
let expr = prefix_expr.expr()?;
556+
let ty = sema.type_of_expr(&expr)?;
557+
if ty.is_raw_ptr() {
558+
HighlightTag::Operator | HighlightModifier::Unsafe
559+
} else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() {
560+
HighlightTag::Operator.into()
561+
} else {
562+
HighlightTag::Punctuation.into()
563+
}
564+
}
565+
T![-] if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
566+
HighlightTag::NumericLiteral.into()
567+
}
568+
_ if element.parent().and_then(ast::PrefixExpr::cast).is_some() => {
569+
HighlightTag::Operator.into()
570+
}
571+
_ if element.parent().and_then(ast::BinExpr::cast).is_some() => {
572+
HighlightTag::Operator.into()
573+
}
574+
_ if element.parent().and_then(ast::RangeExpr::cast).is_some() => {
575+
HighlightTag::Operator.into()
576+
}
577+
_ if element.parent().and_then(ast::RangePat::cast).is_some() => {
578+
HighlightTag::Operator.into()
579+
}
580+
_ if element.parent().and_then(ast::DotDotPat::cast).is_some() => {
581+
HighlightTag::Operator.into()
582+
}
583+
_ if element.parent().and_then(ast::Attr::cast).is_some() => {
584+
HighlightTag::Attribute.into()
585+
}
586+
_ => HighlightTag::Punctuation.into(),
587+
},
557588

558589
k if k.is_keyword() => {
559590
let h = Highlight::new(HighlightTag::Keyword);

0 commit comments

Comments
 (0)