From c8a0a3bd51c6bab5e182c8e1045f86a1b9f7879c Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 16 Nov 2024 14:51:51 +0100 Subject: [PATCH 1/2] Proper handing of raw strings in rust --- .../scopes/rust/string.singleLine.scope | 20 +++++++++++++++++++ .../rust/textFragment.string.singleLine.scope | 20 +++++++++++++++++++ .../common/src/scopeSupportFacets/rust.ts | 2 ++ queries/rust.scm | 12 +++++++---- 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 data/fixtures/scopes/rust/string.singleLine.scope create mode 100644 data/fixtures/scopes/rust/textFragment.string.singleLine.scope diff --git a/data/fixtures/scopes/rust/string.singleLine.scope b/data/fixtures/scopes/rust/string.singleLine.scope new file mode 100644 index 0000000000..3176dfd515 --- /dev/null +++ b/data/fixtures/scopes/rust/string.singleLine.scope @@ -0,0 +1,20 @@ +r#"hello"# +"world" +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:0-0:10 + >----------< +0| r#"hello"# + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 1:0-1:7 + >-------< +1| "world" + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/rust/textFragment.string.singleLine.scope b/data/fixtures/scopes/rust/textFragment.string.singleLine.scope new file mode 100644 index 0000000000..061198476b --- /dev/null +++ b/data/fixtures/scopes/rust/textFragment.string.singleLine.scope @@ -0,0 +1,20 @@ +r#"hello"# +"world" +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:3-0:8 + >-----< +0| r#"hello"# + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 1:1-1:6 + >-----< +1| "world" + +[#2 Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/rust.ts b/packages/common/src/scopeSupportFacets/rust.ts index 125b6a5dd6..c8e7f844a8 100644 --- a/packages/common/src/scopeSupportFacets/rust.ts +++ b/packages/common/src/scopeSupportFacets/rust.ts @@ -7,4 +7,6 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const rustScopeSupport: LanguageScopeSupportFacetMap = { ifStatement: supported, disqualifyDelimiter: supported, + "string.singleLine": supported, + "textFragment.string.singleLine": supported, }; diff --git a/queries/rust.scm b/queries/rust.scm index a49b0aba0f..7b9f6010af 100644 --- a/queries/rust.scm +++ b/queries/rust.scm @@ -5,14 +5,18 @@ (if_let_expression) ] @ifStatement +;;!! "hello" ( - [ - (raw_string_literal) - (string_literal) - ] @string @textFragment + (string_literal) @string @textFragment (#child-range! @textFragment 0 -1 true true) ) +;;!! r#"foobar"# +( + (raw_string_literal) @string @textFragment + (#character-range! @textFragment 3 -2) +) + [ (line_comment) (block_comment) From 33c8459af9a7334a6ab3276828b22dace53ded19 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sat, 16 Nov 2024 15:30:12 +0100 Subject: [PATCH 2/2] Support multiple hashes --- .../scopes/rust/string.singleLine.scope | 26 +++++++++++++------ .../rust/textFragment.string.singleLine.scope | 26 +++++++++++++------ queries/rust.scm | 3 ++- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/data/fixtures/scopes/rust/string.singleLine.scope b/data/fixtures/scopes/rust/string.singleLine.scope index 3176dfd515..68b4966a86 100644 --- a/data/fixtures/scopes/rust/string.singleLine.scope +++ b/data/fixtures/scopes/rust/string.singleLine.scope @@ -1,20 +1,30 @@ -r#"hello"# -"world" +"aaa" +r#"bbb"# +r##"ccc"## --- [#1 Content] = [#1 Removal] = -[#1 Domain] = 0:0-0:10 - >----------< -0| r#"hello"# +[#1 Domain] = 0:0-0:5 + >-----< +0| "aaa" [#1 Insertion delimiter] = " " [#2 Content] = [#2 Removal] = -[#2 Domain] = 1:0-1:7 - >-------< -1| "world" +[#2 Domain] = 1:0-1:8 + >--------< +1| r#"bbb"# [#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 2:0-2:10 + >----------< +2| r##"ccc"## + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/rust/textFragment.string.singleLine.scope b/data/fixtures/scopes/rust/textFragment.string.singleLine.scope index 061198476b..9d115cbc7b 100644 --- a/data/fixtures/scopes/rust/textFragment.string.singleLine.scope +++ b/data/fixtures/scopes/rust/textFragment.string.singleLine.scope @@ -1,20 +1,30 @@ -r#"hello"# -"world" +"aaa" +r#"bbb"# +r##"ccc"## --- [#1 Content] = [#1 Removal] = -[#1 Domain] = 0:3-0:8 - >-----< -0| r#"hello"# +[#1 Domain] = 0:1-0:4 + >---< +0| "aaa" [#1 Insertion delimiter] = " " [#2 Content] = [#2 Removal] = -[#2 Domain] = 1:1-1:6 - >-----< -1| "world" +[#2 Domain] = 1:3-1:6 + >---< +1| r#"bbb"# [#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 2:4-2:7 + >---< +2| r##"ccc"## + +[#3 Insertion delimiter] = " " diff --git a/queries/rust.scm b/queries/rust.scm index 7b9f6010af..22dfafefce 100644 --- a/queries/rust.scm +++ b/queries/rust.scm @@ -14,7 +14,8 @@ ;;!! r#"foobar"# ( (raw_string_literal) @string @textFragment - (#character-range! @textFragment 3 -2) + (#shrink-to-match! @textFragment "r#+\"(?.*)\"#+") + ) [