From 7009d5ee2bff53b9beb555b1572c97ab3882cd98 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Thu, 30 Jul 2020 10:20:06 -0400 Subject: Add new HighlightModifier variant, Consuming --- crates/ide/src/syntax_highlighting/tags.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'crates/ide/src/syntax_highlighting') diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 49ec94bdc..c1b817f06 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -62,6 +62,7 @@ pub enum HighlightModifier { Documentation, Injected, Mutable, + Consuming, Unsafe, } @@ -119,6 +120,7 @@ impl HighlightModifier { HighlightModifier::Documentation, HighlightModifier::Injected, HighlightModifier::Mutable, + HighlightModifier::Consuming, HighlightModifier::Unsafe, ]; @@ -130,6 +132,7 @@ impl HighlightModifier { HighlightModifier::Documentation => "documentation", HighlightModifier::Injected => "injected", HighlightModifier::Mutable => "mutable", + HighlightModifier::Consuming => "consuming", HighlightModifier::Unsafe => "unsafe", } } -- cgit v1.2.3 From a044ff0138d6bff9406b94de89fde43e7672ee1b Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Thu, 30 Jul 2020 11:07:13 -0400 Subject: Mark mutating functions with `mutable` modifier, and owning functions with `consuming`. --- crates/ide/src/syntax_highlighting/tests.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ide/src/syntax_highlighting') diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 94f37d773..6cb955d29 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -36,6 +36,10 @@ impl Foo { fn qux(&mut self) { self.x = 0; } + + fn quop(&self) -> i32 { + self.x + } } static mut STATIC_MUT: i32 = 0; @@ -87,6 +91,11 @@ fn main() { let Foo { x: z, y } = Foo { x: z, y }; y; + + let mut foo = Foo { x, y: x }; + foo.quop(); + foo.qux(); + foo.baz(); } enum Option { -- cgit v1.2.3 From 3456e2eec7c1e18734f8fa41924a83b4c676dc00 Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Thu, 30 Jul 2020 22:31:53 -0400 Subject: Add new method to Semantics, method_receiver_kind, which returns the kind of self The options are Shared, Mutable, Consuming, and Copied. Use this to add proper highlighting to methods based on usage. --- crates/ide/src/syntax_highlighting/tests.rs | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'crates/ide/src/syntax_highlighting') diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 6cb955d29..ccb76f552 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -12,6 +12,12 @@ fn test_highlighting() { use inner::{self as inner_mod}; mod inner {} +// Needed for function consuming vs normal +pub mod marker { + #[lang = "copy"] + pub trait Copy {} +} + #[derive(Clone, Debug)] struct Foo { pub x: i32, @@ -42,6 +48,25 @@ impl Foo { } } +#[derive(Copy, Clone)] +struct FooCopy { + x: u32, +} + +impl FooCopy { + fn baz(self) -> u32 { + self.x + } + + fn qux(&mut self) { + self.x = 0; + } + + fn quop(&self) -> u32 { + self.x + } +} + static mut STATIC_MUT: i32 = 0; fn foo<'a, T>() -> T { @@ -96,6 +121,11 @@ fn main() { foo.quop(); foo.qux(); foo.baz(); + + let mut copy = FooCopy { x }; + copy.quop(); + copy.qux(); + copy.baz(); } enum Option { -- cgit v1.2.3