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 7ad103dbb6..0000000000 --- a/packages/cursorless-engine/src/languages/latex.ts +++ /dev/null @@ -1,150 +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, - patternMatcher, -} 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]`); -const sectioningCommand = SECTIONING.map((s) => `${s}[command]`); - -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), - ), - }, - }; -} - -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 -> = { - argumentOrParameter: cascadingMatcher( - ancestorChainNodeMatcher( - [patternFinder(...COMMANDS), patternFinder(...GROUPS)], - 1, - unwrapGroupParens, - ), - matcher( - patternFinder("begin[name]", "end[name]", ...sectioningText), - unwrapGroupParens, - ), - ), - - functionCall: cascadingMatcher( - 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..b357165ce1 100644 --- a/queries/latex.scm +++ b/queries/latex.scm @@ -50,3 +50,153 @@ (begin) @collectionItem.iteration.start.endOf (end) @collectionItem.iteration.end.startOf ) @collectionItem.iteration.domain + +;;!! \section{foo bar} +;;! ^^^^^^^ +( + (_ + text: (_ + (_) @name @argumentOrParameter + ) @_.removal + ) @name.domain + (#type? + @name.domain + subparagraph + paragraph + subsubsection + subsection + section + chapter + part + ) +) + +;;!! \begin{quote} +;; ! ^^^^^ +(begin + name: (_ + text: (_) @name @argumentOrParameter + ) @_.removal +) @name.domain + +;;!! \end{quote} +;; ! ^^^^^ +(end + name: (_ + text: (_) @name @argumentOrParameter + ) @_.removal +) @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 @argumentOrParameter.iteration + +( + (_ + command: _ @functionCall.start @argumentOrParameter.iteration.start + . + (_)? @functionCall.end @argumentOrParameter.iteration.end + ) @_dummy + (#type? + @_dummy + subparagraph + paragraph + subsubsection + subsection + section + chapter + 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 + ) +)