From 83d6bc7113080c9bf3fd70bed1b89c6b4795d826 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Fri, 16 Oct 2020 06:38:32 -0300 Subject: Add HighlightModifier::Callable and add it for locals --- crates/ide/src/syntax_highlighting.rs | 3 +++ crates/ide/src/syntax_highlighting/tags.rs | 3 +++ 2 files changed, 6 insertions(+) (limited to 'crates/ide/src') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index b35c03162..3982838d5 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -763,6 +763,9 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { if local.is_mut(db) || local.ty(db).is_mutable_reference() { h |= HighlightModifier::Mutable; } + if local.ty(db).as_callable(db).is_some() { + h |= HighlightModifier::Callable; + } return h; } } diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index c1b817f06..e8f78ad52 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -64,6 +64,7 @@ pub enum HighlightModifier { Mutable, Consuming, Unsafe, + Callable, } impl HighlightTag { @@ -122,6 +123,7 @@ impl HighlightModifier { HighlightModifier::Mutable, HighlightModifier::Consuming, HighlightModifier::Unsafe, + HighlightModifier::Callable, ]; fn as_str(self) -> &'static str { @@ -134,6 +136,7 @@ impl HighlightModifier { HighlightModifier::Mutable => "mutable", HighlightModifier::Consuming => "consuming", HighlightModifier::Unsafe => "unsafe", + HighlightModifier::Callable => "callable", } } -- cgit v1.2.3 From a483b5545dad2d36336c1e9a4f5dc991d2c8460b Mon Sep 17 00:00:00 2001 From: GrayJack Date: Fri, 16 Oct 2020 07:52:18 -0300 Subject: Add Callable modifier for variables that implements Fnonce --- crates/ide/src/syntax_highlighting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 3982838d5..750848467 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -763,7 +763,7 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { if local.is_mut(db) || local.ty(db).is_mutable_reference() { h |= HighlightModifier::Mutable; } - if local.ty(db).as_callable(db).is_some() { + if local.ty(db).as_callable(db).is_some() || local.ty(db).impls_fnonce(db) { h |= HighlightModifier::Callable; } return h; -- cgit v1.2.3 From a35ff6edf44519cc3b07869d8e5754c607b913cd Mon Sep 17 00:00:00 2001 From: GrayJack Date: Wed, 21 Oct 2020 01:54:51 -0300 Subject: Add tests for callable modifier --- .../syntax_highlighting/test_data/highlighting.html | 19 +++++++++++++++++++ crates/ide/src/syntax_highlighting/tests.rs | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'crates/ide/src') diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index 0bb0928e4..0cb84866d 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html @@ -44,6 +44,17 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd pub trait Copy {} } +pub mod ops { + #[lang = "fn_once"] + pub trait FnOnce<Args> {} + + #[lang = "fn_mut"] + pub trait FnMut<Args>: FnOnce<Args> {} + + #[lang = "fn"] + pub trait Fn<Args>: FnMut<Args> {} +} + struct Foo { pub x: i32, @@ -99,6 +110,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd foo::<'a, i32>() } +use ops::Fn; +fn baz<F: Fn() -> ()>(f: F) { + f() +} + macro_rules! def_fn { ($($tt:tt)*) => {$($tt)*} } @@ -157,6 +173,9 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd copy.quop(); copy.qux(); copy.baz(copy); + + let a = |x| x; + let bar = Foo::baz; } enum Option<T> { diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 126363b8b..da20c300e 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -18,6 +18,17 @@ pub mod marker { pub trait Copy {} } +pub mod ops { + #[lang = "fn_once"] + pub trait FnOnce {} + + #[lang = "fn_mut"] + pub trait FnMut: FnOnce {} + + #[lang = "fn"] + pub trait Fn: FnMut {} +} + struct Foo { pub x: i32, @@ -73,6 +84,11 @@ fn foo<'a, T>() -> T { foo::<'a, i32>() } +use ops::Fn; +fn baz ()>(f: F) { + f() +} + macro_rules! def_fn { ($($tt:tt)*) => {$($tt)*} } @@ -131,6 +147,9 @@ fn main() { copy.quop(); copy.qux(); copy.baz(copy); + + let a = |x| x; + let bar = Foo::baz; } enum Option { -- cgit v1.2.3 From d86863aeb404b042a3ba1a60d5d961f392b8cb64 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 21 Oct 2020 14:17:00 +0200 Subject: Rewrite algo::diff to support insertion and deletion --- crates/ide/src/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide/src') diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 90574cb35..232074c3d 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -613,7 +613,7 @@ fn main() { pub struct Foo { pub a: i32, pub b: i32 } "#, r#" -fn {a:42, b: ()} {} +fn some(, b: ()} {} fn items() {} fn here() {} -- cgit v1.2.3