From 4caefdb3fda70f03c65ef9fff387c4be8df0cbe8 Mon Sep 17 00:00:00 2001 From: Alex Povel Date: Fri, 16 Aug 2024 22:04:04 +0200 Subject: [PATCH] feat(rust): Scope type identifiers --- README.md | 1 + src/scoping/langs/rust.rs | 3 + tests/langs/mod.rs | 5 + ...r#mod__langs__base.rs_type-identifier.snap | 199 ++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 tests/langs/snapshots/r#mod__langs__base.rs_type-identifier.snap diff --git a/README.md b/README.md index 6609545c..6bd21ae2 100644 --- a/README.md +++ b/README.md @@ -1564,6 +1564,7 @@ Language scopes: - mod-tests: `mod tests` blocks - type-def: Type definitions (`struct`, `enum`, `union`) - identifier: Identifiers + - type-identifier: Identifiers for types - closure: Closure definitions --rust-query diff --git a/src/scoping/langs/rust.rs b/src/scoping/langs/rust.rs index a44f7d13..895f35d5 100644 --- a/src/scoping/langs/rust.rs +++ b/src/scoping/langs/rust.rs @@ -92,6 +92,8 @@ pub enum PreparedRustQuery { TypeDef, /// Identifiers. Identifier, + /// Identifiers for types. + TypeIdentifier, /// Closure definitions. Closure, } @@ -305,6 +307,7 @@ impl From for TSQuery { " } PreparedRustQuery::Identifier => "(identifier) @identifier", + PreparedRustQuery::TypeIdentifier => "(type_identifier) @identifier", PreparedRustQuery::Closure => "(closure_expression) @closure", }, ) diff --git a/tests/langs/mod.rs b/tests/langs/mod.rs index c4410fa5..5a67a78a 100644 --- a/tests/langs/mod.rs +++ b/tests/langs/mod.rs @@ -367,6 +367,11 @@ impl InScopeLinePart { include_str!("rust/base.rs"), Rust::new(CodeQuery::Prepared(PreparedRustQuery::Identifier)), )] +#[case( + "base.rs_type-identifier", + include_str!("rust/base.rs"), + Rust::new(CodeQuery::Prepared(PreparedRustQuery::TypeIdentifier)), +)] #[case( "base.rs_closure", include_str!("rust/base.rs"), diff --git a/tests/langs/snapshots/r#mod__langs__base.rs_type-identifier.snap b/tests/langs/snapshots/r#mod__langs__base.rs_type-identifier.snap new file mode 100644 index 00000000..a597472b --- /dev/null +++ b/tests/langs/snapshots/r#mod__langs__base.rs_type-identifier.snap @@ -0,0 +1,199 @@ +--- +source: tests/langs/mod.rs +expression: inscope_parts +--- +- n: 28 + l: "static TEST_VAR: AtomicI32 = AtomicI32::new(10);\n" + m: " ^^^^^^^^^ " +- n: 42 + l: "fn func_decorator(func: F)\n" + m: " ^ " +- n: 42 + l: "fn func_decorator(func: F)\n" + m: " ^ " +- n: 44 + l: " F: Fn() + 'static,\n" + m: " ^ " +- n: 44 + l: " F: Fn() + 'static,\n" + m: " ^^ " +- n: 47 + l: " fn wrapper(func: F)\n" + m: " ^ " +- n: 47 + l: " fn wrapper(func: F)\n" + m: " ^ " +- n: 49 + l: " F: Fn(),\n" + m: " ^ " +- n: 49 + l: " F: Fn(),\n" + m: " ^^ " +- n: 70 + l: "struct TestStruct {\n" + m: " ^^^^^^^^^^ " +- n: 71 + l: " instance_var: String,\n" + m: " ^^^^^^ " +- n: 74 + l: "impl TestStruct {\n" + m: " ^^^^^^^^^^ " +- n: 75 + l: " fn new() -> Self {\n" + m: " ^^^^ " +- n: 76 + l: " TestStruct {\n" + m: " ^^^^^^^^^^ " +- n: 86 + l: " fn static_decorator(func: F) -> impl Fn()\n" + m: " ^ " +- n: 86 + l: " fn static_decorator(func: F) -> impl Fn()\n" + m: " ^ " +- n: 86 + l: " fn static_decorator(func: F) -> impl Fn()\n" + m: " ^^ " +- n: 88 + l: " F: Fn(),\n" + m: " ^ " +- n: 88 + l: " F: Fn(),\n" + m: " ^^ " +- n: 111 + l: "enum TestEnum {\n" + m: " ^^^^^^^^ " +- n: 113 + l: " VariantTwo(String),\n" + m: " ^^^^^^ " +- n: 114 + l: " VariantThree { a: String, b: u64 },\n" + m: " ^^^^^^ " +- n: 117 + l: "impl TestEnum {\n" + m: " ^^^^^^^^ " +- n: 118 + l: " fn match_statement(x: TestEnum) {\n" + m: " ^^^^^^^^ " +- n: 182 + l: "async fn async_main() -> Result<(), ()> {\n" + m: " ^^^^^^ " +- n: 197 + l: "pub async fn async_pub_fn() -> Result<(), ()> {\n" + m: " ^^^^^^ " +- n: 231 + l: " let mut instance = TestStruct {\n" + m: " ^^^^^^^^^^ " +- n: 270 + l: "pub struct PubStruct {}\n" + m: " ^^^^^^^^^ " +- n: 271 + l: "pub(crate) struct PubCrateStruct {}\n" + m: " ^^^^^^^^^^^^^^ " +- n: 272 + l: "pub(self) struct PubSelfStruct {}\n" + m: " ^^^^^^^^^^^^^ " +- n: 273 + l: "pub(super) struct PubSuperStruct {}\n" + m: " ^^^^^^^^^^^^^^ " +- n: 275 + l: "pub enum PubEnum {}\n" + m: " ^^^^^^^ " +- n: 276 + l: "pub(crate) enum PubCrateEnum {}\n" + m: " ^^^^^^^^^^^^ " +- n: 277 + l: "pub(self) enum PubSelfEnum {}\n" + m: " ^^^^^^^^^^^ " +- n: 278 + l: "pub(super) enum PubSuperEnum {}\n" + m: " ^^^^^^^^^^^^ " +- n: 281 + l: "union MyUnion {\n" + m: " ^^^^^^^ " +- n: 301 + l: "impl Y {}\n" + m: " ^ " +- n: 302 + l: "impl Y {}\n" + m: " ^ " +- n: 302 + l: "impl Y {}\n" + m: " ^ " +- n: 302 + l: "impl Y {}\n" + m: " ^ " +- n: 304 + l: "trait Convertible {\n" + m: " ^^^^^^^^^^^ " +- n: 304 + l: "trait Convertible {\n" + m: " ^ " +- n: 305 + l: " fn convert(&self) -> T;\n" + m: " ^ " +- n: 308 + l: "impl Convertible for T\n" + m: " ^ " +- n: 308 + l: "impl Convertible for T\n" + m: " ^ " +- n: 308 + l: "impl Convertible for T\n" + m: " ^^^^^^^^^^^ " +- n: 308 + l: "impl Convertible for T\n" + m: " ^ " +- n: 308 + l: "impl Convertible for T\n" + m: " ^ " +- n: 310 + l: " T: AsRef,\n" + m: " ^ " +- n: 310 + l: " T: AsRef,\n" + m: " ^^^^^ " +- n: 311 + l: " U: From,\n" + m: " ^ " +- n: 311 + l: " U: From,\n" + m: " ^^^^ " +- n: 311 + l: " U: From,\n" + m: " ^^^^^^ " +- n: 313 + l: " fn convert(&self) -> U {\n" + m: " ^ " +- n: 318 + l: "impl X for Y {}\n" + m: " ^ " +- n: 318 + l: "impl X for Y {}\n" + m: " ^ " +- n: 319 + l: "impl X for Y {}\n" + m: " ^ " +- n: 319 + l: "impl X for Y {}\n" + m: " ^ " +- n: 319 + l: "impl X for Y {}\n" + m: " ^ " +- n: 319 + l: "impl X for Y {}\n" + m: " ^ " +- n: 320 + l: "impl X for Y {}\n" + m: " ^ " +- n: 320 + l: "impl X for Y {}\n" + m: " ^ " +- n: 320 + l: "impl X for Y {}\n" + m: " ^ " +- n: 320 + l: "impl X for Y {}\n" + m: " ^ " +- n: 322 + l: "impl PubStruct {\n" + m: " ^^^^^^^^^ "