Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 0 additions & 19 deletions data/fixtures/scopes/r/functionCall.chain.scope

This file was deleted.

25 changes: 0 additions & 25 deletions data/fixtures/scopes/r/functionCallee.chain.scope

This file was deleted.

6 changes: 4 additions & 2 deletions packages/common/src/scopeSupportFacets/r.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = {

functionCall: supported,
"functionCall.method": supported,
"functionCall.chain": supported,
functionCallee: supported,
"functionCallee.method": supported,
"functionCallee.chain": supported,

"comment.line": supported,
ifStatement: supported,
Expand Down Expand Up @@ -81,6 +79,10 @@ export const rScopeSupport: LanguageScopeSupportFacetMap = {

// Not applicable

// Chained function calls
"functionCall.chain": notApplicable,
"functionCallee.chain": notApplicable,

"interior.cell": notApplicable,
"interior.command": notApplicable,
"interior.element": notApplicable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,59 +263,6 @@ class GrowToNamedSiblings extends QueryPredicateOperator<GrowToNamedSiblings> {
return true;
}
}
/**
* A predicate operator that modifies the range of the match to grow to leading siblings of the same type.
*
* The `leadingSeparator` argument specificies the separator each node except the first sibling will be separated by.
*
* ```
* (#call-chain! @foo ".")
* ```
*/
class CallChain extends QueryPredicateOperator<CallChain> {
name = "call-chain!" as const;
schema = z.union([z.tuple([q.node]), z.tuple([q.node, q.string])]);

run(nodeInfo: MutableQueryCapture, leadingSeparator: string) {
const { node } = nodeInfo;

if (node.parent == null) {
throw Error("Node has no parent");
}

const { children } = node.parent;
const nodeIndex = children.findIndex((n) => n.id === node.id);

if (nodeIndex === -1) {
throw Error("Node not found in parent");
}

let start = children[nodeIndex];

for (let i = nodeIndex; i > -1; --i) {
const child = children[i];

if (child.type !== node.type) {
break;
}

start = child;

if (!child.text.startsWith(leadingSeparator)) {
break;
}
}

if (start.id !== node.id) {
nodeInfo.range = makeRangeFromPositions(
start.startPosition,
children[nodeIndex].endPosition,
);
}

return true;
}
}

/**
* A predicate operator that modifies the range of the match by trimming trailing whitespace,
Expand Down Expand Up @@ -494,7 +441,6 @@ export const queryPredicateOperators = [
new CharacterRange(),
new ShrinkToMatch(),
new GrowToNamedSiblings(),
new CallChain(),
new AllowMultiple(),
new InsertionDelimiter(),
new SingleOrMultilineDelimiter(),
Expand Down
21 changes: 4 additions & 17 deletions queries/r.scm
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@
;;! ^^^^^^^^^^^^^^
(if_statement) @ifStatement

;; ;;!! if (TRUE) { print("hello") } else { print("world") }
;; ;;! ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;; (if_statement
;; "if" @branch.start
;; (_) @condition
;; consequence: (braced_expression) @branch.end
;; alternative: (braced_expression)? @branch.end
;; ) @branch.iteration

;; named function
;;!! abc <- function(x){ }
;;! ^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -136,14 +127,10 @@
;;! ^^^^^
;;! ^^^
;;! -----
(
(call
(identifier) @functionCallee.end
) @functionCall @functionCallee.start.startOf @functionCallee.domain
(#call-chain! @functionCall ".")
(#call-chain! @functionCallee.start.startOf ".")
(#call-chain! @functionCallee.domain ".")
)

(call
(identifier) @functionCallee
) @functionCall @functionCallee.domain

;; Technically lists and arrays are just calls to the function `list` or `c`
;;!! list(1, 2, 3)
Expand Down
Loading