From 95907d42de1b77f38f49134895ded3cb5b822653 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 2 Jun 2025 17:15:49 +0200 Subject: [PATCH 1/4] Migrate name --- .../cursorless-engine/src/languages/latex.ts | 6 ---- queries/latex.scm | 36 +++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/cursorless-engine/src/languages/latex.ts b/packages/cursorless-engine/src/languages/latex.ts index 7ad103dbb6..de39accbd6 100644 --- a/packages/cursorless-engine/src/languages/latex.ts +++ b/packages/cursorless-engine/src/languages/latex.ts @@ -11,7 +11,6 @@ import { cascadingMatcher, createPatternMatchers, matcher, - patternMatcher, } from "../util/nodeMatchers"; const COMMANDS = [ @@ -140,11 +139,6 @@ const nodeMatchers: Partial< matcher(patternFinder(...COMMANDS, "begin", "end")), matcher(patternFinder(...sectioningCommand), extendToNamedSiblingIfExists), ), - - name: cascadingMatcher( - matcher(patternFinder(...sectioningText), unwrapGroupParens), - patternMatcher("begin[name][text]", "end[name][text]"), - ), }; export default createPatternMatchers(nodeMatchers); diff --git a/queries/latex.scm b/queries/latex.scm index 2b044cd777..4c1ef30c60 100644 --- a/queries/latex.scm +++ b/queries/latex.scm @@ -50,3 +50,39 @@ (begin) @collectionItem.iteration.start.endOf (end) @collectionItem.iteration.end.startOf ) @collectionItem.iteration.domain + +;;!! \section{foo bar} +;;! ^^^^^^^ +( + (_ + text: (_ + (_) @name + ) @name.removal + ) @name.domain + (#type? + @name.domain + subparagraph + paragraph + subsubsection + subsection + section + chapter + part + ) +) + +;;!! \begin{quote} +;; ! ^^^^^ +(begin + name: (_ + text: (_) @name + ) +) @_.domain + +;;!! \end{quote} +;; ! ^^^^^ +(end + name: (_ + text: (_) @name + ) +) @_.domain From 59bc1b4e7f7a940c3e73ad6f5db8e99e9681a166 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 2 Jun 2025 17:33:12 +0200 Subject: [PATCH 2/4] Migrate function call --- .../cursorless-engine/src/languages/latex.ts | 6 -- queries/latex.scm | 74 +++++++++++++++++++ 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/packages/cursorless-engine/src/languages/latex.ts b/packages/cursorless-engine/src/languages/latex.ts index de39accbd6..104ae12140 100644 --- a/packages/cursorless-engine/src/languages/latex.ts +++ b/packages/cursorless-engine/src/languages/latex.ts @@ -79,7 +79,6 @@ const SECTIONING = [ ]; const sectioningText = SECTIONING.map((s) => `${s}[text]`); -const sectioningCommand = SECTIONING.map((s) => `${s}[command]`); function unwrapGroupParens( editor: TextEditor, @@ -134,11 +133,6 @@ const nodeMatchers: Partial< unwrapGroupParens, ), ), - - functionCall: cascadingMatcher( - matcher(patternFinder(...COMMANDS, "begin", "end")), - matcher(patternFinder(...sectioningCommand), extendToNamedSiblingIfExists), - ), }; export default createPatternMatchers(nodeMatchers); diff --git a/queries/latex.scm b/queries/latex.scm index 4c1ef30c60..96a9e325d0 100644 --- a/queries/latex.scm +++ b/queries/latex.scm @@ -86,3 +86,77 @@ text: (_) @name ) ) @_.domain + +[ + (displayed_equation) + (generic_command) + (inline_formula) + (block_comment) + (package_include) + (class_include) + (latex_include) + (biblatex_include) + (bibtex_include) + (graphics_include) + (svg_include) + (inkscape_include) + (verbatim_include) + (import_include) + (caption) + (citation) + (label_definition) + (label_reference) + (label_reference_range) + (label_number) + (new_command_definition) + (old_command_definition) + (let_command_definition) + (environment_definition) + (glossary_entry_definition) + (glossary_entry_reference) + (acronym_definition) + (acronym_reference) + (theorem_definition) + (color_definition) + (color_set_definition) + (color_reference) + (tikz_library_import) + (begin) + (end) +] @functionCall + +(subparagraph + command: _ @functionCall.start + . + (_)? @functionCall.end +) +(paragraph + command: _ @functionCall.start + . + (_)? @functionCall.end +) +(subsubsection + command: _ @functionCall.start + . + (_)? @functionCall.end +) +(subsection + command: _ @functionCall.start + . + (_)? @functionCall.end +) +(section + command: _ @functionCall.start + . + (_)? @functionCall.end +) +(chapter + command: _ @functionCall.start + . + (_)? @functionCall.end +) +(part + command: _ @functionCall.start + . + (_)? @functionCall.end +) From 685f0f800dca9ab818b927fc6eca80ddae144962 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 2 Jun 2025 17:36:15 +0200 Subject: [PATCH 3/4] Clean up --- .../cursorless-engine/src/languages/latex.ts | 21 -------- queries/latex.scm | 49 ++++++------------- 2 files changed, 15 insertions(+), 55 deletions(-) diff --git a/packages/cursorless-engine/src/languages/latex.ts b/packages/cursorless-engine/src/languages/latex.ts index 104ae12140..ec56bfbd08 100644 --- a/packages/cursorless-engine/src/languages/latex.ts +++ b/packages/cursorless-engine/src/languages/latex.ts @@ -98,27 +98,6 @@ function unwrapGroupParens( }; } -function extendToNamedSiblingIfExists( - editor: TextEditor, - node: Node, -): SelectionWithContext { - const startIndex = node.startIndex; - let endIndex = node.endIndex; - const sibling = node.nextNamedSibling; - - if (sibling != null && sibling.isNamed) { - endIndex = sibling.endIndex; - } - - return { - selection: new Selection( - editor.document.positionAt(startIndex), - editor.document.positionAt(endIndex), - ), - context: {}, - }; -} - const nodeMatchers: Partial< Record > = { diff --git a/queries/latex.scm b/queries/latex.scm index 96a9e325d0..98f4f6e4a1 100644 --- a/queries/latex.scm +++ b/queries/latex.scm @@ -125,38 +125,19 @@ (end) ] @functionCall -(subparagraph - command: _ @functionCall.start - . - (_)? @functionCall.end -) -(paragraph - command: _ @functionCall.start - . - (_)? @functionCall.end -) -(subsubsection - command: _ @functionCall.start - . - (_)? @functionCall.end -) -(subsection - command: _ @functionCall.start - . - (_)? @functionCall.end -) -(section - command: _ @functionCall.start - . - (_)? @functionCall.end -) -(chapter - command: _ @functionCall.start - . - (_)? @functionCall.end -) -(part - command: _ @functionCall.start - . - (_)? @functionCall.end +( + (_ + command: _ @functionCall.start + . + (_)? @functionCall.end + ) @_dummy + (#type? + @_dummy + paragraph + subsubsection + subsection + section + chapter + part + ) ) From 2244577c44ee7ea38ebe575f38311b9f3b821404 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 2 Jun 2025 18:01:29 +0200 Subject: [PATCH 4/4] Migrate argument --- .../src/languages/LegacyLanguageId.ts | 2 +- .../src/languages/getNodeMatcher.ts | 2 - .../cursorless-engine/src/languages/latex.ts | 117 ------------------ queries/latex.scm | 81 ++++++++++-- 4 files changed, 71 insertions(+), 131 deletions(-) delete mode 100644 packages/cursorless-engine/src/languages/latex.ts diff --git a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts index f439cc2f16..83864b9bae 100644 --- a/packages/cursorless-engine/src/languages/LegacyLanguageId.ts +++ b/packages/cursorless-engine/src/languages/LegacyLanguageId.ts @@ -2,6 +2,6 @@ * The language IDs that we have full tree-sitter support for using our legacy * modifiers. */ -export const legacyLanguageIds = ["latex", "rust"] as const; +export const legacyLanguageIds = ["rust"] as const; export type LegacyLanguageId = (typeof legacyLanguageIds)[number]; diff --git a/packages/cursorless-engine/src/languages/getNodeMatcher.ts b/packages/cursorless-engine/src/languages/getNodeMatcher.ts index 91c5fef7ec..390e1dfde9 100644 --- a/packages/cursorless-engine/src/languages/getNodeMatcher.ts +++ b/packages/cursorless-engine/src/languages/getNodeMatcher.ts @@ -8,7 +8,6 @@ import type { } from "../typings/Types"; import { notSupported } from "../util/nodeMatchers"; import { selectionWithEditorFromRange } from "../util/selectionUtils"; -import latex from "./latex"; import type { LegacyLanguageId } from "./LegacyLanguageId"; import rust from "./rust"; @@ -40,7 +39,6 @@ export const languageMatchers: Record< LegacyLanguageId, Partial> > = { - latex, rust, }; diff --git a/packages/cursorless-engine/src/languages/latex.ts b/packages/cursorless-engine/src/languages/latex.ts deleted file mode 100644 index ec56bfbd08..0000000000 --- a/packages/cursorless-engine/src/languages/latex.ts +++ /dev/null @@ -1,117 +0,0 @@ -import type { SimpleScopeTypeType, TextEditor } from "@cursorless/common"; -import { Selection } from "@cursorless/common"; -import type { Node } from "web-tree-sitter"; -import type { - NodeMatcherAlternative, - SelectionWithContext, -} from "../typings/Types"; -import { patternFinder } from "../util/nodeFinders"; -import { - ancestorChainNodeMatcher, - cascadingMatcher, - createPatternMatchers, - matcher, -} from "../util/nodeMatchers"; - -const COMMANDS = [ - "command", - "displayed_equation", - "generic_command", - "inline_formula", - "math_set", - "block_comment", - "package_include", - "class_include", - "latex_include", - "biblatex_include", - "bibtex_include", - "graphics_include", - "svg_include", - "inkscape_include", - "verbatim_include", - "import_include", - "caption", - "citation", - "label_definition", - "label_reference", - "label_reference_range", - "label_number", - "new_command_definition", - "old_command_definition", - "let_command_definition", - "environment_definition", - "glossary_entry_definition", - "glossary_entry_reference", - "acronym_definition", - "acronym_reference", - "theorem_definition", - "color_definition", - "color_set_definition", - "color_reference", - "tikz_library_import", -]; - -const GROUPS = [ - "curly_group", - "curly_group_text", - "curly_group_text_list", - "curly_group_path", - "curly_group_path_list", - "curly_group_command_name", - "curly_group_key_value", - "curly_group_glob_pattern", - "curly_group_impl", - "brack_group", - "brack_group_text", - "brack_group_argc", - "brack_group_key_value", - "mixed_group", -]; - -const SECTIONING = [ - "subparagraph", - "paragraph", - "subsubsection", - "subsection", - "section", - "chapter", - "part", -]; - -const sectioningText = SECTIONING.map((s) => `${s}[text]`); - -function unwrapGroupParens( - editor: TextEditor, - node: Node, -): SelectionWithContext { - return { - selection: new Selection( - editor.document.positionAt(node.startIndex + 1), - editor.document.positionAt(node.endIndex - 1), - ), - context: { - removalRange: new Selection( - editor.document.positionAt(node.startIndex), - editor.document.positionAt(node.endIndex), - ), - }, - }; -} - -const nodeMatchers: Partial< - Record -> = { - argumentOrParameter: cascadingMatcher( - ancestorChainNodeMatcher( - [patternFinder(...COMMANDS), patternFinder(...GROUPS)], - 1, - unwrapGroupParens, - ), - matcher( - patternFinder("begin[name]", "end[name]", ...sectioningText), - unwrapGroupParens, - ), - ), -}; - -export default createPatternMatchers(nodeMatchers); diff --git a/queries/latex.scm b/queries/latex.scm index 98f4f6e4a1..b357165ce1 100644 --- a/queries/latex.scm +++ b/queries/latex.scm @@ -56,8 +56,8 @@ ( (_ text: (_ - (_) @name - ) @name.removal + (_) @name @argumentOrParameter + ) @_.removal ) @name.domain (#type? @name.domain @@ -75,17 +75,17 @@ ;; ! ^^^^^ (begin name: (_ - text: (_) @name - ) -) @_.domain + text: (_) @name @argumentOrParameter + ) @_.removal +) @name.domain ;;!! \end{quote} ;; ! ^^^^^ (end name: (_ - text: (_) @name - ) -) @_.domain + text: (_) @name @argumentOrParameter + ) @_.removal +) @name.domain [ (displayed_equation) @@ -123,16 +123,17 @@ (tikz_library_import) (begin) (end) -] @functionCall +] @functionCall @argumentOrParameter.iteration ( (_ - command: _ @functionCall.start + command: _ @functionCall.start @argumentOrParameter.iteration.start . - (_)? @functionCall.end + (_)? @functionCall.end @argumentOrParameter.iteration.end ) @_dummy (#type? @_dummy + subparagraph paragraph subsubsection subsection @@ -141,3 +142,61 @@ part ) ) + +( + (_ + [ + (curly_group) + (curly_group_text) + (curly_group_text_list) + (curly_group_path) + (curly_group_path_list) + (curly_group_command_name) + (curly_group_key_value) + (curly_group_glob_pattern) + (curly_group_impl) + (brack_group) + (brack_group_text) + (brack_group_argc) + (brack_group_key_value) + ] @argumentOrParameter @_.removal + ) @_dummy + (#character-range! @argumentOrParameter 1 -1) + (#type? + @_dummy + displayed_equation + generic_command + inline_formula + math_set + block_comment + package_include + class_include + latex_include + biblatex_include + bibtex_include + graphics_include + svg_include + inkscape_include + verbatim_include + import_include + caption + citation + label_definition + label_reference + label_reference_range + label_number + new_command_definition + old_command_definition + let_command_definition + environment_definition + glossary_entry_definition + glossary_entry_reference + acronym_definition + acronym_reference + theorem_definition + color_definition + color_set_definition + color_reference + tikz_library_import + ) +)