Skip to content

Commit

Permalink
Proper handing of raw strings in rust (#2681)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson authored Nov 16, 2024
1 parent ca31335 commit d6cc6f9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
30 changes: 30 additions & 0 deletions data/fixtures/scopes/rust/string.singleLine.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"aaa"
r#"bbb"#
r##"ccc"##
---

[#1 Content] =
[#1 Removal] =
[#1 Domain] = 0:0-0:5
>-----<
0| "aaa"

[#1 Insertion delimiter] = " "


[#2 Content] =
[#2 Removal] =
[#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] = " "
30 changes: 30 additions & 0 deletions data/fixtures/scopes/rust/textFragment.string.singleLine.scope
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"aaa"
r#"bbb"#
r##"ccc"##
---

[#1 Content] =
[#1 Removal] =
[#1 Domain] = 0:1-0:4
>---<
0| "aaa"

[#1 Insertion delimiter] = " "


[#2 Content] =
[#2 Removal] =
[#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] = " "
2 changes: 2 additions & 0 deletions packages/common/src/scopeSupportFacets/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel;
export const rustScopeSupport: LanguageScopeSupportFacetMap = {
ifStatement: supported,
disqualifyDelimiter: supported,
"string.singleLine": supported,
"textFragment.string.singleLine": supported,
};
13 changes: 9 additions & 4 deletions queries/rust.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
(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
(#shrink-to-match! @textFragment "r#+\"(?<keep>.*)\"#+")

)

[
(line_comment)
(block_comment)
Expand Down

0 comments on commit d6cc6f9

Please sign in to comment.