forked from cursorless-everywhere/cursorless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
45 changed files
with
1,237 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import { Range, Selection, TextEditor } from "vscode"; | ||
import { SyntaxNode } from "web-tree-sitter"; | ||
import { SimpleScopeTypeType } from "../typings/targetDescriptor.types"; | ||
import { NodeMatcherAlternative, SelectionWithContext } from "../typings/Types"; | ||
import { patternFinder } from "../util/nodeFinders"; | ||
import { | ||
ancestorChainNodeMatcher, | ||
cascadingMatcher, | ||
createPatternMatchers, | ||
matcher, | ||
} from "../util/nodeMatchers"; | ||
|
||
const COMMANDS = [ | ||
"command", | ||
"displayed_equation", | ||
"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 ENVIRONMENTS = [ | ||
"generic_environment", | ||
"comment_environment", | ||
"verbatim_environment", | ||
"listing_environment", | ||
"minted_environment", | ||
"pycode_environment", | ||
]; | ||
|
||
const sectioningText = SECTIONING.map((s) => `${s}[text]`); | ||
const sectioningCommand = SECTIONING.map((s) => `${s}[command]`); | ||
|
||
function unwrapGroupParens( | ||
editor: TextEditor, | ||
node: SyntaxNode | ||
): 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: SyntaxNode | ||
): 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: {}, | ||
}; | ||
} | ||
|
||
function extractItemContent( | ||
editor: TextEditor, | ||
node: SyntaxNode | ||
): SelectionWithContext { | ||
let contentStartIndex = node.startIndex; | ||
|
||
const label = node.childForFieldName("label"); | ||
if (label == null) { | ||
const command = node.childForFieldName("command"); | ||
if (command != null) { | ||
contentStartIndex = command.endIndex + 1; | ||
} | ||
} else { | ||
contentStartIndex = label.endIndex + 1; | ||
} | ||
|
||
return { | ||
selection: new Selection( | ||
editor.document.positionAt(contentStartIndex), | ||
editor.document.positionAt(node.endIndex) | ||
), | ||
context: { | ||
leadingDelimiterRange: new Range( | ||
editor.document.positionAt(node.startIndex), | ||
editor.document.positionAt(contentStartIndex - 1) | ||
), | ||
}, | ||
}; | ||
} | ||
|
||
const nodeMatchers: Partial< | ||
Record<SimpleScopeTypeType, NodeMatcherAlternative> | ||
> = { | ||
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: matcher(patternFinder(...sectioningText), unwrapGroupParens), | ||
functionCallee: "command_name", | ||
|
||
collectionItem: matcher(patternFinder("enum_item"), extractItemContent), | ||
|
||
comment: ["block_comment", "line_comment"], | ||
|
||
part: "part", | ||
chapter: "chapter", | ||
section: "section", | ||
subSection: "subsection", | ||
subSubSection: "subsubsection", | ||
namedParagraph: "paragraph", | ||
subParagraph: "subparagraph", | ||
|
||
environment: ENVIRONMENTS, | ||
}; | ||
|
||
export default createPatternMatchers(nodeMatchers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/test/suite/fixtures/recorded/languages/latex/changeArg.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
languageId: latex | ||
command: | ||
version: 1 | ||
spokenForm: change arg | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false} | ||
initialState: | ||
documentContents: | | ||
\begin{itemize} | ||
\end{itemize} | ||
selections: | ||
- anchor: {line: 0, character: 11} | ||
active: {line: 0, character: 11} | ||
marks: {} | ||
finalState: | ||
documentContents: | | ||
\begin{} | ||
\end{itemize} | ||
selections: | ||
- anchor: {line: 0, character: 7} | ||
active: {line: 0, character: 7} | ||
thatMark: | ||
- anchor: {line: 0, character: 7} | ||
active: {line: 0, character: 7} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}] |
25 changes: 25 additions & 0 deletions
25
src/test/suite/fixtures/recorded/languages/latex/changeArg2.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
languageId: latex | ||
command: | ||
version: 1 | ||
spokenForm: change arg | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false} | ||
initialState: | ||
documentContents: | | ||
\section{some section} | ||
selections: | ||
- anchor: {line: 0, character: 16} | ||
active: {line: 0, character: 16} | ||
marks: {} | ||
finalState: | ||
documentContents: | | ||
\section{} | ||
selections: | ||
- anchor: {line: 0, character: 9} | ||
active: {line: 0, character: 9} | ||
thatMark: | ||
- anchor: {line: 0, character: 9} | ||
active: {line: 0, character: 9} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}] |
25 changes: 25 additions & 0 deletions
25
src/test/suite/fixtures/recorded/languages/latex/changeArg3.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
languageId: latex | ||
command: | ||
version: 1 | ||
spokenForm: change arg | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false} | ||
initialState: | ||
documentContents: | | ||
\href{https://some.url}{some text} | ||
selections: | ||
- anchor: {line: 0, character: 14} | ||
active: {line: 0, character: 14} | ||
marks: {} | ||
finalState: | ||
documentContents: | | ||
\href{}{some text} | ||
selections: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} | ||
thatMark: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}] |
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/latex/changeArg4.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: latex | ||
command: | ||
version: 1 | ||
spokenForm: change arg | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false} | ||
initialState: | ||
documentContents: \usepackage[utf8]{inputenc} | ||
selections: | ||
- anchor: {line: 0, character: 14} | ||
active: {line: 0, character: 14} | ||
marks: {} | ||
finalState: | ||
documentContents: \usepackage[]{inputenc} | ||
selections: | ||
- anchor: {line: 0, character: 12} | ||
active: {line: 0, character: 12} | ||
thatMark: | ||
- anchor: {line: 0, character: 12} | ||
active: {line: 0, character: 12} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: argumentOrParameter, includeSiblings: false}, isImplicit: false}] |
Oops, something went wrong.