Skip to content

Added text based item scope #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 57 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
2be775a
Added text based item scope
pokey Jun 7, 2022
f1e61fe
Merge branch 'main' into textTheBasedItemScope
pokey Jun 7, 2022
256e92c
Merge branch 'main' into textTheBasedItemScope
AndreasArvidsson Jun 13, 2022
94048ec
Cleaned up imports
AndreasArvidsson Jun 13, 2022
25b8248
Merge branch 'main' into textTheBasedItemScope
AndreasArvidsson Jun 15, 2022
ee74800
Use text based item as a fallback
AndreasArvidsson Jun 15, 2022
3f0a79a
Updated tests
AndreasArvidsson Jun 15, 2022
f9ab73e
Merge branch 'main' into textTheBasedItemScope
AndreasArvidsson Jun 18, 2022
0f0241d
Don't look for items inside strings
AndreasArvidsson Jun 18, 2022
dd837b3
Merge branch 'textTheBasedItemScope' of github.com:pokey/cursorless-v…
AndreasArvidsson Jun 18, 2022
05c253b
More work on item stage
Jun 28, 2022
4c51ff5
updated test
Jun 29, 2022
3f9afa5
Replaced take test with clear test
Jun 29, 2022
742c603
Merge branch 'main' into textTheBasedItemScope
AndreasArvidsson Jun 29, 2022
3499f53
updated item stage
Jun 29, 2022
2c13872
Typescript now uses text based item
Jun 29, 2022
974aeea
Use text based item for more languages
Jun 29, 2022
1e3941c
Use text based item for more languages
Jun 29, 2022
768eef2
Cleanup
Jun 29, 2022
9ab4388
Added more tests
Jun 29, 2022
cb0972f
Added test
Jun 29, 2022
0a5b8a3
Added support for escaped strings
Jun 30, 2022
0e346a7
Added additional test
Jun 30, 2022
e5efc63
Added more tests
Jun 30, 2022
eccb1c9
Light clean up and add test
pokey Jun 30, 2022
05218be
cleanup
Jun 30, 2022
571269d
Include trailing delimiter in arguments
Jun 30, 2022
c67f1e2
Cleanup
Jun 30, 2022
2b318ff
Cleanup
Jun 30, 2022
16a720c
Don't expand for weak item target
Jun 30, 2022
b2ae923
Include pairs inside strings
Jun 30, 2022
96e2dcb
Cleanup
Jun 30, 2022
f72b201
p
Jun 30, 2022
37d1168
Merge branch 'main' into textTheBasedItemScope
AndreasArvidsson Jun 30, 2022
bc03305
Merge branch 'main' into textTheBasedItemScope
AndreasArvidsson Jun 30, 2022
8b441ad
Added item support to python argument list
Jul 1, 2022
dc4ad3e
Merged with main
Jul 4, 2022
2ab20f6
Use new requireStrongContainment
Jul 4, 2022
022efb1
Cleanup
Jul 4, 2022
9db3da3
Cleanup
Jul 4, 2022
cae791e
Merge branch 'main' into textTheBasedItemScope
AndreasArvidsson Jul 4, 2022
95acb52
Added complex surrounding pair scope type
Jul 4, 2022
8ca0f91
Merge branch 'textTheBasedItemScope' of github.com:cursorless-dev/cur…
Jul 4, 2022
6136843
Tweaks to #709 (#823)
pokey Jul 4, 2022
c1d2bfb
Revert "Added complex surrounding pair scope type"
Jul 4, 2022
c3d3495
Merge branch 'textTheBasedItemScope' of github.com:cursorless-dev/cur…
Jul 4, 2022
7c7f3aa
Cleanup
Jul 4, 2022
7969637
Create single union of items
Jul 4, 2022
6d074a6
Excluded separator from domain
Jul 4, 2022
7b14de4
Cleanup
Jul 4, 2022
30d9c11
Updated tests
Jul 4, 2022
9f70175
Update src/processTargets/modifiers/ItemStage/tokenizeRange.ts
AndreasArvidsson Jul 5, 2022
9a65fcf
Update src/processTargets/modifiers/ItemStage/tokenizeRange.ts
AndreasArvidsson Jul 5, 2022
456c905
Update src/languages/python.ts
AndreasArvidsson Jul 5, 2022
1d4ff8d
Cleanup
Jul 5, 2022
27e966b
Merge branch 'main' into textTheBasedItemScope
pokey Jul 5, 2022
0791c3e
Tweaks
pokey Jul 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/languages/cpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ const nodeMatchers: Partial<
],
[":", "=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="]
),
collectionItem: argumentMatcher("initializer_list"),
argumentOrParameter: argumentMatcher("parameter_list", "argument_list"),
attribute: "attribute",
};
Expand Down
80 changes: 0 additions & 80 deletions src/languages/csharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,6 @@ import { nodeFinder, typedNodeFinder } from "../util/nodeFinders";
import { delimitedSelector, childRangeSelector } from "../util/nodeSelectors";
import { patternFinder } from "../util/nodeFinders";

// Generated by the following command:
// > curl https://github.com/raw/tree-sitter/tree-sitter-c-sharp/master/src/node-types.json \
// | jq '.[] | select(.type == "_expression") | [.subtypes[].type]'
const EXPRESSION_TYPES = [
"anonymous_method_expression",
"anonymous_object_creation_expression",
"array_creation_expression",
"as_expression",
"assignment_expression",
"await_expression",
"base_expression",
"binary_expression",
"boolean_literal",
"cast_expression",
"character_literal",
"checked_expression",
"conditional_access_expression",
"conditional_expression",
"default_expression",
"element_access_expression",
"element_binding_expression",
"generic_name",
"global",
"identifier",
"implicit_array_creation_expression",
"implicit_object_creation_expression",
"implicit_stack_alloc_array_creation_expression",
"initializer_expression",
"integer_literal",
"interpolated_string_expression",
"invocation_expression",
"is_expression",
"is_pattern_expression",
"lambda_expression",
"make_ref_expression",
"member_access_expression",
"null_literal",
"object_creation_expression",
"parenthesized_expression",
"postfix_unary_expression",
"prefix_unary_expression",
"query_expression",
"range_expression",
"real_literal",
"ref_expression",
"ref_type_expression",
"ref_value_expression",
"size_of_expression",
"stack_alloc_array_creation_expression",
"string_literal",
"switch_expression",
"this_expression",
"throw_expression",
"tuple_expression",
"type_of_expression",
"verbatim_string_literal",
"with_expression",
];

function isExpression(node: SyntaxNode) {
return EXPRESSION_TYPES.includes(node.type);
}

// Generated by the following command:
// > curl https://github.com/raw/tree-sitter/tree-sitter-c-sharp/master/src/node-types.json \
// | jq '.[] | select(.type == "_statement" or .type == "_declaration") | [.subtypes[].type]'
Expand Down Expand Up @@ -197,23 +134,6 @@ const getMapMatchers = {
(node: SyntaxNode) => node.childForFieldName("initializer"),
])
),
collectionItem: matcher(
nodeFinder(
(node) =>
(node.parent?.type === "initializer_expression" &&
isExpression(node)) ||
node.type === "assignment_expression"
),
delimitedSelector(
(node) =>
node.type === "," ||
node.type === "[" ||
node.type === "]" ||
node.type === "}" ||
node.type === "{",
", "
)
),
string: typeMatcher("string_literal"),
};

Expand Down
1 change: 0 additions & 1 deletion src/languages/go.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const nodeMatchers: Partial<
patternMatcher("parameter_declaration"),
patternMatcher("argument_declaration")
),
collectionItem: ["keyed_element", "element"],
collectionKey: "keyed_element[0]",
value: cascadingMatcher(
patternMatcher("keyed_element[1]"),
Expand Down
1 change: 0 additions & 1 deletion src/languages/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ const nodeMatchers: Partial<
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="]
),
condition: conditionMatcher("*[condition]"),
collectionItem: argumentMatcher("array_initializer"),
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),
};

Expand Down
8 changes: 3 additions & 5 deletions src/languages/json.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { SyntaxNode } from "web-tree-sitter";
import { SimpleScopeTypeType } from "../typings/targetDescriptor.types";
import { NodeMatcherAlternative, SelectionWithEditor } from "../typings/Types";
import {
createPatternMatchers,
argumentMatcher,
leadingMatcher,
trailingMatcher,
} from "../util/nodeMatchers";
import { NodeMatcherAlternative, SelectionWithEditor } from "../typings/Types";
import { SimpleScopeTypeType } from "../typings/targetDescriptor.types";
import { SyntaxNode } from "web-tree-sitter";
import { getNodeRange } from "../util/nodeSelectors";

const nodeMatchers: Partial<
Expand All @@ -17,7 +16,6 @@ const nodeMatchers: Partial<
string: "string",
collectionKey: trailingMatcher(["pair[key]"], [":"]),
value: leadingMatcher(["*[value]"], [":"]),
collectionItem: argumentMatcher("object", "array"),
};

export const patternMatchers = createPatternMatchers(nodeMatchers);
Expand Down
1 change: 0 additions & 1 deletion src/languages/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ const nodeMatchers: Partial<
),

collectionKey: trailingMatcher(["array_element_initializer[0]"], ["=>"]),
collectionItem: argumentMatcher("array_creation_expression"),

argumentOrParameter: argumentMatcher("arguments", "formal_parameters"),
};
Expand Down
36 changes: 27 additions & 9 deletions src/languages/python.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { Selection } from "vscode";
import { SyntaxNode } from "web-tree-sitter";
import { SimpleScopeTypeType } from "../typings/targetDescriptor.types";
import { NodeFinder, NodeMatcherAlternative } from "../typings/Types";
import { argumentNodeFinder, patternFinder } from "../util/nodeFinders";
import {
createPatternMatchers,
argumentMatcher,
leadingMatcher,
trailingMatcher,
cascadingMatcher,
patternMatcher,
conditionMatcher,
createPatternMatchers,
leadingMatcher,
matcher,
patternMatcher,
trailingMatcher,
} from "../util/nodeMatchers";
import { patternFinder } from "../util/nodeFinders";
import { NodeMatcherAlternative } from "../typings/Types";
import { SimpleScopeTypeType } from "../typings/targetDescriptor.types";
import { childRangeSelector } from "../util/nodeSelectors";
import {
argumentSelectionExtractor,
childRangeSelector,
} from "../util/nodeSelectors";

// Generated by the following command:
// > curl https://github.com/raw/tree-sitter/tree-sitter-python/d6210ceab11e8d812d4ab59c07c81458ec6e5184/src/node-types.json \
Expand Down Expand Up @@ -49,13 +53,28 @@ export const getTypeNode = (node: SyntaxNode) =>
const dictionaryTypes = ["dictionary", "dictionary_comprehension"];
const listTypes = ["list", "list_comprehension", "set"];

function importNodeFinder(): NodeFinder {
const finder = argumentNodeFinder("import_from_statement");
return (node: SyntaxNode, selection?: Selection) => {
const childNode = finder(node, selection);
if (
childNode?.type !== "dotted_name" ||
childNode?.id === childNode?.parent?.namedChildren[0].id
) {
return null;
}
return childNode;
};
}

const nodeMatchers: Partial<
Record<SimpleScopeTypeType, NodeMatcherAlternative>
> = {
map: dictionaryTypes,
list: listTypes,
statement: STATEMENT_TYPES,
string: "string",
collectionItem: matcher(importNodeFinder(), argumentSelectionExtractor()),
collectionKey: trailingMatcher(["pair[key]"], [":"]),
ifStatement: "if_statement",
anonymousFunction: "lambda?.lambda",
Expand All @@ -78,7 +97,6 @@ const nodeMatchers: Partial<
"parameters.identifier!",
"*[name]",
],
collectionItem: argumentMatcher(...dictionaryTypes, ...listTypes),
value: cascadingMatcher(
leadingMatcher(
["assignment[right]", "augmented_assignment[right]", "~subscript[value]"],
Expand Down
1 change: 0 additions & 1 deletion src/languages/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ const nodeMatchers: Partial<
],
[":"]
),
collectionItem: argumentMatcher(...mapTypes, ...listTypes),
value: cascadingMatcher(
valueMatcher(),
patternMatcher("return_statement.~return!"),
Expand Down
3 changes: 3 additions & 0 deletions src/processTargets/getModifierStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ExcludeInteriorStage,
InteriorOnlyStage,
} from "./modifiers/InteriorStage";
import ItemStage from "./modifiers/ItemStage";
import { LeadingStage, TrailingStage } from "./modifiers/LeadingTrailingStages";
import ModifyIfWeakStage from "./modifiers/ModifyIfWeakStage";
import OrdinalRangeSubTokenStage, {
Expand Down Expand Up @@ -98,6 +99,8 @@ const getContainingScopeStage = (
);
case "url":
return new UrlStage(modifier as UrlModifier);
case "collectionItem":
return new ItemStage(modifier);
case "surroundingPair":
return new SurroundingPairStage(
modifier as ContainingSurroundingPairModifier
Expand Down
Loading