Skip to content

Commit

Permalink
Fix detection of imports with trailing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ks-korovina committed Apr 30, 2024
1 parent 559bd2f commit 4886027
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/Kotlin.JSON-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
"imports": {
"patterns": [
{
"match": "^\\s*(import)\\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\\s+(as)\\s+([`][^$`]+[`]|[^` $.]+))?$",
"match": "^\\s*(import)\\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\\s+(as)\\s+([`][^$`]+[`]|[^` $.]+))?",
"captures": {
"1": {
"name": "keyword.other.import.kotlin"
Expand Down
2 changes: 1 addition & 1 deletion dist/Kotlin.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ repository:
imports:
patterns:
-
match: '^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?$'
match: '^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?'
captures:
'1': {name: keyword.other.import.kotlin}
'2': {name: storage.modifier.import.kotlin}
Expand Down
2 changes: 1 addition & 1 deletion dist/Kotlin.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@
<array>
<dict>
<key>match</key>
<string>^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?$</string>
<string>^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?</string>
<key>captures</key>
<dict>
<key>1</key>
Expand Down
2 changes: 1 addition & 1 deletion src/imports.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ repository:
imports:
patterns:
-
match: '^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?$'
match: '^\s*(import)\s+((?:[`][^$`]+[`]|[^` $.]+)(?:\.(?:[`][^$`]+[`]|[^` $.]+))*)(?:\s+(as)\s+([`][^$`]+[`]|[^` $.]+))?'
captures:
'1':
name: keyword.other.import.kotlin
Expand Down
2 changes: 0 additions & 2 deletions src/literals.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ repository:
-
include: '#string-content'
repository:
# https://kotlinlang.org/docs/strings.html#raw-strings
# Raw strings do not contain escape sequences.
raw-string-content:
patterns:
-
Expand Down
19 changes: 18 additions & 1 deletion test/Imports.test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,21 @@
// ^ source.kotlin meta.import.kotlin
// ^^ source.kotlin meta.import.kotlin keyword.other.kotlin
// ^ source.kotlin meta.import.kotlin
// ^^^^ source.kotlin meta.import.kotlin entity.name.type
// ^^^^ source.kotlin meta.import.kotlin entity.name.type

import com.google.test.CommentedClass // comment
//^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin
// ^ source.kotlin meta.import.kotlin
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin
// ^^ source.kotlin punctuation.definition.comment.kotlin comment.line.double-slash.kotlin

import com.google.test.CommentedClass /*comment*/ as Another
//^^^^^^ source.kotlin meta.import.kotlin keyword.other.import.kotlin
// ^ source.kotlin meta.import.kotlin
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.kotlin meta.import.kotlin storage.modifier.import.kotlin
// ^^ source.kotlin comment.block.kotlin punctuation.definition.comment.begin.kotlin
// ^^ source.kotlin comment.block.kotlin punctuation.definition.comment.end.kotlin
// ^ source.kotlin
// ^^ source.kotlin keyword.operator.kotlin
// ^ source.kotlin
// ^^^^^^^ source.kotlin entity.name.type.class.kotlin

0 comments on commit 4886027

Please sign in to comment.