Handle multiline type annotation that start with & or | operator

Fixes #935 #949
This commit is contained in:
Sheetal Nandi 2023-02-09 10:48:14 -08:00
Родитель f169c9dbf5
Коммит 88a7e09e92
7 изменённых файлов: 401 добавлений и 3 удалений

Просмотреть файл

@ -2227,7 +2227,7 @@ repository:
begin: (:)
beginCaptures:
'1': { name: keyword.operator.type.annotation.ts }
end: (?<![:|&])((?=[,);\}\]]|//)|(?==[^>])|(?=^\s*$)|((?<=\S)(?=\s*$))|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))
end: (?<![:|&])((?=[,);\}\]]|\/\/)|(?==[^>])|(?=^\s*$)|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))
patterns:
- include: '#type'

Просмотреть файл

@ -6799,7 +6799,7 @@
</dict>
</dict>
<key>end</key>
<string>(?&lt;![:|&amp;])((?=[,);\}\]]|//)|(?==[^&gt;])|(?=^\s*$)|((?&lt;=\S)(?=\s*$))|((?&lt;=[\}&gt;\]\)]|[_$[:alpha:]])\s*(?=\{)))</string>
<string>(?&lt;![:|&amp;])((?=[,);\}\]]|\/\/)|(?==[^&gt;])|(?=^\s*$)|((?&lt;=[\}&gt;\]\)]|[_$[:alpha:]])\s*(?=\{)))</string>
<key>patterns</key>
<array>
<dict>

Просмотреть файл

@ -6747,7 +6747,7 @@
</dict>
</dict>
<key>end</key>
<string>(?&lt;![:|&amp;])((?=[,);\}\]]|//)|(?==[^&gt;])|(?=^\s*$)|((?&lt;=\S)(?=\s*$))|((?&lt;=[\}&gt;\]\)]|[_$[:alpha:]])\s*(?=\{)))</string>
<string>(?&lt;![:|&amp;])((?=[,);\}\]]|\/\/)|(?==[^&gt;])|(?=^\s*$)|((?&lt;=[\}&gt;\]\)]|[_$[:alpha:]])\s*(?=\{)))</string>
<key>patterns</key>
<array>
<dict>

Просмотреть файл

@ -0,0 +1,210 @@
original file
-----------------------------------
export interface FeatureControl {
enableCompletionProvider?:
string
| {
processCompletions?(completion: CustomCompletionItem): vsc.CompletionItem[]
}
}
export interface RegisterLanguageSupportOptions {
/** handle requesting position in document */
pathAutoRename?: {
glob: string
isSpecCanBeUsed?(specName): boolean | string
}
}
export interface API {
}
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>export interface FeatureControl {
^^^^^^
source.ts meta.interface.ts keyword.control.export.ts
^
source.ts meta.interface.ts
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^^^^^^^^^^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
> enableCompletionProvider?:
^^^^
source.ts meta.interface.ts meta.field.declaration.ts
^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
> string
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
> | {
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts punctuation.definition.block.ts
> processCompletions?(completion: CustomCompletionItem): vsc.CompletionItem[]
^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts
^^^^^^^^^^^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts
^^^^^^^^^^^^^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts
^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts entity.name.type.module.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts punctuation.accessor.ts
^^^^^^^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts meta.type.tuple.ts meta.brace.square.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts meta.type.tuple.ts meta.brace.square.ts
> }
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts punctuation.definition.block.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts
>
^
source.ts
>export interface RegisterLanguageSupportOptions {
^^^^^^
source.ts meta.interface.ts keyword.control.export.ts
^
source.ts meta.interface.ts
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
> /** handle requesting position in document */
^^^^
source.ts meta.interface.ts
^^^
source.ts meta.interface.ts comment.block.documentation.ts punctuation.definition.comment.ts
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
source.ts meta.interface.ts comment.block.documentation.ts
^^
source.ts meta.interface.ts comment.block.documentation.ts punctuation.definition.comment.ts
> pathAutoRename?: {
^^^^
source.ts meta.interface.ts meta.field.declaration.ts
^^^^^^^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts punctuation.definition.block.ts
> glob: string
^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.field.declaration.ts
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
> isSpecCanBeUsed?(specName): boolean | string
^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts
^^^^^^^^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.definition.method.ts entity.name.function.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts variable.parameter.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts
^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts keyword.operator.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts meta.method.declaration.ts meta.return.type.ts support.type.primitive.ts
> }
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.object.type.ts punctuation.definition.block.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts
>
^
source.ts
>export interface API {
^^^^^^
source.ts meta.interface.ts keyword.control.export.ts
^
source.ts meta.interface.ts
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts

Просмотреть файл

@ -0,0 +1,160 @@
original file
-----------------------------------
export interface PackageJson {
exports?:
| string
| Record<
string,
string | { types?: string; require?: string; import?: string }
>;
}
export function foo() { }
-----------------------------------
Grammar: TypeScript.tmLanguage
-----------------------------------
>export interface PackageJson {
^^^^^^
source.ts meta.interface.ts keyword.control.export.ts
^
source.ts meta.interface.ts
^^^^^^^^^
source.ts meta.interface.ts storage.type.interface.ts
^
source.ts meta.interface.ts
^^^^^^^^^^^
source.ts meta.interface.ts entity.name.type.interface.ts
^
source.ts meta.interface.ts
^
source.ts meta.interface.ts punctuation.definition.block.ts
> exports?:
^^^^
source.ts meta.interface.ts meta.field.declaration.ts
^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
> | string
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
> | Record<
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts entity.name.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
> string,
^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.separator.comma.ts
> string | { types?: string; require?: string; import?: string }
^^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts keyword.operator.type.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts punctuation.definition.block.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts
^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts punctuation.terminator.statement.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts
^^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts punctuation.terminator.statement.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts keyword.operator.optional.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts
^^^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts meta.field.declaration.ts meta.type.annotation.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts meta.object.type.ts punctuation.definition.block.ts
> >;
^^^^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts
^
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
^
source.ts meta.interface.ts punctuation.terminator.statement.ts
>}
^
source.ts meta.interface.ts punctuation.definition.block.ts
>
^
source.ts
>export function foo() { }
^^^^^^
source.ts meta.function.ts keyword.control.export.ts
^
source.ts meta.function.ts
^^^^^^^^
source.ts meta.function.ts storage.type.function.ts
^
source.ts meta.function.ts
^^^
source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts
^
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
^
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
^
source.ts meta.function.ts
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
^
source.ts meta.function.ts meta.block.ts
^
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts

18
tests/cases/issue935.ts Normal file
Просмотреть файл

@ -0,0 +1,18 @@
export interface FeatureControl {
enableCompletionProvider?:
string
| {
processCompletions?(completion: CustomCompletionItem): vsc.CompletionItem[]
}
}
export interface RegisterLanguageSupportOptions {
/** handle requesting position in document */
pathAutoRename?: {
glob: string
isSpecCanBeUsed?(specName): boolean | string
}
}
export interface API {
}

10
tests/cases/issue949.ts Normal file
Просмотреть файл

@ -0,0 +1,10 @@
export interface PackageJson {
exports?:
| string
| Record<
string,
string | { types?: string; require?: string; import?: string }
>;
}
export function foo() { }