From 5a9f1b28c6f100c8ec6db09ad402a792a40c614d Mon Sep 17 00:00:00 2001 From: benyn <105991837+benyn@users.noreply.github.com> Date: Fri, 17 Feb 2023 17:34:50 -0800 Subject: [PATCH 1/2] Update TypeScript textobjects for type definition support `interface`, `type` and `enum` declarations are now supported as class `textobject`s. Known issues: - the last semicolon (`;`) of the inner text (`interface`, `type`) or the last comma of the inner text (`enum`) are missed. - an object [declared with `as const`](https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums) isn't supported (`value: as_expression` ending with `type_identifier`) --- queries/typescript/textobjects.scm | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/queries/typescript/textobjects.scm b/queries/typescript/textobjects.scm index 04328f09..faa00776 100644 --- a/queries/typescript/textobjects.scm +++ b/queries/typescript/textobjects.scm @@ -1 +1,32 @@ ; inherits: ecma + + +;; interface declaration as class textobject +(interface_declaration) @class.outer + +(interface_declaration + body: _ @class.inner) @class.outer + +(interface_declaration + body: (object_type . "{" . _ @_start @_end _? @_end . "}" + (#make-range! "class.inner" @_start @_end))) + +;; type alias declaration as class textobject +(type_alias_declaration) @class.outer + +(type_alias_declaration + value: _ @class.inner) @class.outer + +(type_alias_declaration + value: (object_type . "{" . _ @_start @_end _? @_end . "}" + (#make-range! "class.inner" @_start @_end))) + +;; enum declaration as class text object +(enum_declaration) @class.outer + +(enum_declaration + body: (enum_body (_) @class.inner)) @class.outer + +(enum_declaration + body: (enum_body . "{" . _ @_start @_end _? @_end . "}" + (#make-range! "class.inner" @_start @_end))) From 73c20e59c62e5b3099cb75c3676e6e0b363915f0 Mon Sep 17 00:00:00 2001 From: benyn <105991837+benyn@users.noreply.github.com> Date: Sat, 18 Feb 2023 12:46:56 -0800 Subject: [PATCH 2/2] Update TypeScript textobjects for type definition `interface`, `type` and `enum` declarations are now supported as class `textobject`s. Tested and confirmed that trailing semicolons (`;`) and commas (`,`) are captured in `@class.inner`, if present. --- queries/typescript/textobjects.scm | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/queries/typescript/textobjects.scm b/queries/typescript/textobjects.scm index faa00776..8acd982f 100644 --- a/queries/typescript/textobjects.scm +++ b/queries/typescript/textobjects.scm @@ -1,32 +1,25 @@ ; inherits: ecma - ;; interface declaration as class textobject -(interface_declaration) @class.outer - (interface_declaration - body: _ @class.inner) @class.outer + body: (object_type)) @class.outer (interface_declaration - body: (object_type . "{" . _ @_start @_end _? @_end . "}" + body: (object_type . "{" . (_) @_start @_end _? @_end . "}" (#make-range! "class.inner" @_start @_end))) ;; type alias declaration as class textobject -(type_alias_declaration) @class.outer - (type_alias_declaration - value: _ @class.inner) @class.outer + value: (object_type)) @class.outer (type_alias_declaration - value: (object_type . "{" . _ @_start @_end _? @_end . "}" + value: (object_type . "{" . (_) @_start @_end _? @_end . "}" (#make-range! "class.inner" @_start @_end))) -;; enum declaration as class text object -(enum_declaration) @class.outer - +;; enum declaration as class textobject (enum_declaration - body: (enum_body (_) @class.inner)) @class.outer + body: (enum_body)) @class.outer (enum_declaration - body: (enum_body . "{" . _ @_start @_end _? @_end . "}" + body: (enum_body . "{" . (_) @_start @_end _? @_end . "}" (#make-range! "class.inner" @_start @_end)))