From dfe9fcdf2b98e6135f7d64da2f62a11f3e82183c Mon Sep 17 00:00:00 2001 From: bluedrink9 Date: Sat, 28 Dec 2024 20:31:37 +1300 Subject: [PATCH 1/4] Enable initial r support --- .../common/src/scopeSupportFacets/languageScopeSupport.ts | 2 ++ packages/common/src/scopeSupportFacets/r.ts | 8 ++++++++ queries/r.scm | 1 + 3 files changed, 11 insertions(+) create mode 100644 packages/common/src/scopeSupportFacets/r.ts create mode 100644 queries/r.scm diff --git a/packages/common/src/scopeSupportFacets/languageScopeSupport.ts b/packages/common/src/scopeSupportFacets/languageScopeSupport.ts index 8a2c0124a6..ea98a324c7 100644 --- a/packages/common/src/scopeSupportFacets/languageScopeSupport.ts +++ b/packages/common/src/scopeSupportFacets/languageScopeSupport.ts @@ -18,6 +18,7 @@ import { luaScopeSupport } from "./lua"; import { markdownScopeSupport } from "./markdown"; import { phpScopeSupport } from "./php"; import { pythonScopeSupport } from "./python"; +import { rScopeSupport } from "./r"; import { rubyScopeSupport } from "./ruby"; import { rustScopeSupport } from "./rust"; import { scalaScopeSupport } from "./scala"; @@ -51,6 +52,7 @@ export const languageScopeSupport: StringRecord = markdown: markdownScopeSupport, php: phpScopeSupport, python: pythonScopeSupport, + r: rScopeSupport, ruby: rubyScopeSupport, rust: rustScopeSupport, scala: scalaScopeSupport, diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts new file mode 100644 index 0000000000..4311d8b21e --- /dev/null +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -0,0 +1,8 @@ +import type { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; +import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; + +export const rScopeSupport: LanguageScopeSupportFacetMap = { +}; diff --git a/queries/r.scm b/queries/r.scm new file mode 100644 index 0000000000..26a62fe87e --- /dev/null +++ b/queries/r.scm @@ -0,0 +1 @@ +;; https://github.com/r-lib/tree-sitter-r/blob/main/src/grammar.json From 35f3646d601bb2fe5d6e73d476759f6a69e1a718 Mon Sep 17 00:00:00 2001 From: bluedrink9 Date: Sun, 23 Feb 2025 20:01:36 +1300 Subject: [PATCH 2/4] intial supported queries --- packages/common/src/scopeSupportFacets/r.ts | 3 +++ queries/r.scm | 25 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index 4311d8b21e..cf67f59af1 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -5,4 +5,7 @@ import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const rScopeSupport: LanguageScopeSupportFacetMap = { + "comment.line": supported, + ifStatement: supported, + "argument.actual": supported, }; diff --git a/queries/r.scm b/queries/r.scm index 26a62fe87e..8d62246200 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -1 +1,26 @@ ;; https://github.com/r-lib/tree-sitter-r/blob/main/src/grammar.json +;; https://github.com/r-lib/tree-sitter-r/blob/main/src/node-types.json + +[ + (for_statement) + (if_statement) + (repeat_statement) + (function_definition) +] @statement + +(comment) @comment +(if_statement) @ifStatement +(argument) @argumentOrParameter +(call) @functionCall +(identifier) @identifier + +;; ;; https://github.com/r-lib/tree-sitter-r/blob/main/queries/highlights.scm +;; ;; Plus magrittr operators +;; [ "?" ":=" "=" "<-" "<<-" "->" "->>" +;; "~" "|>" "||" "|" "&&" "&" +;; "<" "<=" ">" ">=" "==" "!=" +;; "+" "-" "*" "/" "::" ":::" +;; "**" "^" "$" "@" ":" "%in%" +;; "%>%" "%<>%" "%T>%" "%$%" +;; "special" +;; ] @operator From 2642bf6fb4d021a3c47a954c24f4f89fa275a736 Mon Sep 17 00:00:00 2001 From: bluedrink9 Date: Fri, 16 May 2025 08:49:05 +1200 Subject: [PATCH 3/4] add initial bunch of r scopes --- .../fixtures/scopes/r/anonymousFunction.scope | 17 ++ data/fixtures/scopes/r/argument.actual.scope | 30 +++ .../scopes/r/argumentList.formal.scope | 13 ++ data/fixtures/scopes/r/comment.line.scope | 10 + data/fixtures/scopes/r/functionCall.scope | 10 + data/fixtures/scopes/r/functionCallee.scope | 10 + data/fixtures/scopes/r/functionName.scope | 19 ++ data/fixtures/scopes/r/ifStatement.scope | 63 ++++++ data/fixtures/scopes/r/name.assignment.scope | 34 ++++ data/fixtures/scopes/r/name.variable.scope | 34 ++++ data/fixtures/scopes/r/namedFunction.scope | 44 +++++ data/fixtures/scopes/r/value.assignment.scope | 34 ++++ data/fixtures/scopes/r/value.variable.scope | 34 ++++ packages/common/src/scopeSupportFacets/r.ts | 180 +++++++++++++++++- queries/r.scm | 119 +++++++++++- 15 files changed, 646 insertions(+), 5 deletions(-) create mode 100644 data/fixtures/scopes/r/anonymousFunction.scope create mode 100644 data/fixtures/scopes/r/argument.actual.scope create mode 100644 data/fixtures/scopes/r/argumentList.formal.scope create mode 100644 data/fixtures/scopes/r/comment.line.scope create mode 100644 data/fixtures/scopes/r/functionCall.scope create mode 100644 data/fixtures/scopes/r/functionCallee.scope create mode 100644 data/fixtures/scopes/r/functionName.scope create mode 100644 data/fixtures/scopes/r/ifStatement.scope create mode 100644 data/fixtures/scopes/r/name.assignment.scope create mode 100644 data/fixtures/scopes/r/name.variable.scope create mode 100644 data/fixtures/scopes/r/namedFunction.scope create mode 100644 data/fixtures/scopes/r/value.assignment.scope create mode 100644 data/fixtures/scopes/r/value.variable.scope diff --git a/data/fixtures/scopes/r/anonymousFunction.scope b/data/fixtures/scopes/r/anonymousFunction.scope new file mode 100644 index 0000000000..1f2d152fd1 --- /dev/null +++ b/data/fixtures/scopes/r/anonymousFunction.scope @@ -0,0 +1,17 @@ +lapply(1:10, function(x) x^2) +--- + +[Content] = +[Domain] = 0:13-0:28 + >---------------< +0| lapply(1:10, function(x) x^2) + +[Removal] = 0:12-0:28 + >----------------< +0| lapply(1:10, function(x) x^2) + +[Leading delimiter] = 0:12-0:13 + >-< +0| lapply(1:10, function(x) x^2) + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/argument.actual.scope b/data/fixtures/scopes/r/argument.actual.scope new file mode 100644 index 0000000000..7e093e98be --- /dev/null +++ b/data/fixtures/scopes/r/argument.actual.scope @@ -0,0 +1,30 @@ +func(1) +func(...) +func(x=1) +--- + +[#1 Content] = +[#1 Removal] = +[#1 Domain] = 0:5-0:6 + >-< +0| func(1) + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Removal] = +[#2 Domain] = 1:5-1:8 + >---< +1| func(...) + +[#2 Insertion delimiter] = " " + + +[#3 Content] = +[#3 Removal] = +[#3 Domain] = 2:5-2:8 + >---< +2| func(x=1) + +[#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/argumentList.formal.scope b/data/fixtures/scopes/r/argumentList.formal.scope new file mode 100644 index 0000000000..1f9c3abe95 --- /dev/null +++ b/data/fixtures/scopes/r/argumentList.formal.scope @@ -0,0 +1,13 @@ +abc <- function(x, y){ } +--- + +[Content] = +[Removal] = 0:16-0:20 + >----< +0| abc <- function(x, y){ } + +[Domain] = 0:7-0:24 + >-----------------< +0| abc <- function(x, y){ } + +[Insertion delimiter] = ", " diff --git a/data/fixtures/scopes/r/comment.line.scope b/data/fixtures/scopes/r/comment.line.scope new file mode 100644 index 0000000000..42719cdbb8 --- /dev/null +++ b/data/fixtures/scopes/r/comment.line.scope @@ -0,0 +1,10 @@ +# Hello world +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:13 + >-------------< +0| # Hello world + +[Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/functionCall.scope b/data/fixtures/scopes/r/functionCall.scope new file mode 100644 index 0000000000..9d9be652fd --- /dev/null +++ b/data/fixtures/scopes/r/functionCall.scope @@ -0,0 +1,10 @@ +lapply(1:10, function(x) x^2) +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:29 + >-----------------------------< +0| lapply(1:10, function(x) x^2) + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/functionCallee.scope b/data/fixtures/scopes/r/functionCallee.scope new file mode 100644 index 0000000000..b9f1e38504 --- /dev/null +++ b/data/fixtures/scopes/r/functionCallee.scope @@ -0,0 +1,10 @@ +lapply(1:10, function(x) x^2) +--- + +[Content] = +[Removal] = +[Domain] = 0:0-0:6 + >------< +0| lapply(1:10, function(x) x^2) + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/functionName.scope b/data/fixtures/scopes/r/functionName.scope new file mode 100644 index 0000000000..672a84af03 --- /dev/null +++ b/data/fixtures/scopes/r/functionName.scope @@ -0,0 +1,19 @@ +abc <- function(arg){ + TRUE +} +--- + +[Content] = +[Domain] = 0:0-0:3 + >---< +0| abc <- function(arg){ + +[Removal] = 0:0-0:4 + >----< +0| abc <- function(arg){ + +[Trailing delimiter] = 0:3-0:4 + >-< +0| abc <- function(arg){ + +[Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/ifStatement.scope b/data/fixtures/scopes/r/ifStatement.scope new file mode 100644 index 0000000000..6ebcfc8733 --- /dev/null +++ b/data/fixtures/scopes/r/ifStatement.scope @@ -0,0 +1,63 @@ +if(FALSE) 0 + +if(TRUE){ 1 } + +if(TRUE){ + 1 +} else { + 0 +} +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:11 + >-----------< +0| if(FALSE) 0 + +[#1 Removal] = 0:0-2:0 + >----------- +0| if(FALSE) 0 +1| +2| if(TRUE){ 1 } + < + +[#1 Insertion delimiter] = "\n" + + +[#2 Content] = +[#2 Domain] = 2:0-2:13 + >-------------< +2| if(TRUE){ 1 } + +[#2 Removal] = 2:0-4:0 + >------------- +2| if(TRUE){ 1 } +3| +4| if(TRUE){ + < + +[#2 Insertion delimiter] = "\n" + + +[#3 Content] = +[#3 Domain] = 4:0-8:1 + >--------- +4| if(TRUE){ +5| 1 +6| } else { +7| 0 +8| } + -< + +[#3 Removal] = 2:13-8:1 + > +2| if(TRUE){ 1 } +3| +4| if(TRUE){ +5| 1 +6| } else { +7| 0 +8| } + -< + +[#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/r/name.assignment.scope b/data/fixtures/scopes/r/name.assignment.scope new file mode 100644 index 0000000000..cf7bf36ade --- /dev/null +++ b/data/fixtures/scopes/r/name.assignment.scope @@ -0,0 +1,34 @@ +hello <- "world" +hello = "world" +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:5 + >-----< +0| hello <- "world" + +[#1 Removal] = 0:0-0:6 + >------< +0| hello <- "world" + +[#1 Trailing delimiter] = 0:5-0:6 + >-< +0| hello <- "world" + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 1:0-1:5 + >-----< +1| hello = "world" + +[#2 Removal] = 1:0-1:6 + >------< +1| hello = "world" + +[#2 Trailing delimiter] = 1:5-1:6 + >-< +1| hello = "world" + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/name.variable.scope b/data/fixtures/scopes/r/name.variable.scope new file mode 100644 index 0000000000..cf7bf36ade --- /dev/null +++ b/data/fixtures/scopes/r/name.variable.scope @@ -0,0 +1,34 @@ +hello <- "world" +hello = "world" +--- + +[#1 Content] = +[#1 Domain] = 0:0-0:5 + >-----< +0| hello <- "world" + +[#1 Removal] = 0:0-0:6 + >------< +0| hello <- "world" + +[#1 Trailing delimiter] = 0:5-0:6 + >-< +0| hello <- "world" + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 1:0-1:5 + >-----< +1| hello = "world" + +[#2 Removal] = 1:0-1:6 + >------< +1| hello = "world" + +[#2 Trailing delimiter] = 1:5-1:6 + >-< +1| hello = "world" + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/namedFunction.scope b/data/fixtures/scopes/r/namedFunction.scope new file mode 100644 index 0000000000..44b7e09057 --- /dev/null +++ b/data/fixtures/scopes/r/namedFunction.scope @@ -0,0 +1,44 @@ +abc <- function(arg){ + TRUE +} +abc = function(arg){ + TRUE +} +--- + +[#1 Content] = +[#1 Domain] = 0:0-2:1 + >--------------------- +0| abc <- function(arg){ +1| TRUE +2| } + -< + +[#1 Removal] = 0:0-3:0 + >--------------------- +0| abc <- function(arg){ +1| TRUE +2| } +3| abc = function(arg){ + < + +[#1 Insertion delimiter] = "\n\n" + + +[#2 Content] = +[#2 Domain] = 3:0-5:1 + >-------------------- +3| abc = function(arg){ +4| TRUE +5| } + -< + +[#2 Removal] = 2:1-5:1 + > +2| } +3| abc = function(arg){ +4| TRUE +5| } + -< + +[#2 Insertion delimiter] = "\n\n" diff --git a/data/fixtures/scopes/r/value.assignment.scope b/data/fixtures/scopes/r/value.assignment.scope new file mode 100644 index 0000000000..20b110b271 --- /dev/null +++ b/data/fixtures/scopes/r/value.assignment.scope @@ -0,0 +1,34 @@ +hello <- "world" +hello = "world" +--- + +[#1 Content] = +[#1 Domain] = 0:9-0:16 + >-------< +0| hello <- "world" + +[#1 Removal] = 0:8-0:16 + >--------< +0| hello <- "world" + +[#1 Leading delimiter] = 0:8-0:9 + >-< +0| hello <- "world" + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 1:8-1:15 + >-------< +1| hello = "world" + +[#2 Removal] = 1:7-1:15 + >--------< +1| hello = "world" + +[#2 Leading delimiter] = 1:7-1:8 + >-< +1| hello = "world" + +[#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/r/value.variable.scope b/data/fixtures/scopes/r/value.variable.scope new file mode 100644 index 0000000000..20b110b271 --- /dev/null +++ b/data/fixtures/scopes/r/value.variable.scope @@ -0,0 +1,34 @@ +hello <- "world" +hello = "world" +--- + +[#1 Content] = +[#1 Domain] = 0:9-0:16 + >-------< +0| hello <- "world" + +[#1 Removal] = 0:8-0:16 + >--------< +0| hello <- "world" + +[#1 Leading delimiter] = 0:8-0:9 + >-< +0| hello <- "world" + +[#1 Insertion delimiter] = " " + + +[#2 Content] = +[#2 Domain] = 1:8-1:15 + >-------< +1| hello = "world" + +[#2 Removal] = 1:7-1:15 + >--------< +1| hello = "world" + +[#2 Leading delimiter] = 1:7-1:8 + >-< +1| hello = "world" + +[#2 Insertion delimiter] = " " diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index cf67f59af1..5851e12915 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -6,6 +6,184 @@ const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const rScopeSupport: LanguageScopeSupportFacetMap = { "comment.line": supported, - ifStatement: supported, + "ifStatement": supported, "argument.actual": supported, + "argumentList.formal": supported, + "condition.if": supported, + "condition.while": unsupported, + + "namedFunction": supported, + "anonymousFunction": supported, + "functionName": supported, + "functionCall": supported, + "functionCallee": supported, + + "name.assignment": supported, + "name.assignment.pattern": notApplicable, + "name.variable": supported, + "value.assignment": supported, + "value.variable": supported, + "value.variable.pattern": notApplicable, + + // "interior.function": unsupported, + // "interior.lambda": unsupported, + // "interior.if": unsupported, + // "interior.try": unsupported, + + command: notApplicable, + element: notApplicable, + startTag: notApplicable, + endTag: notApplicable, + tags: notApplicable, + attribute: unsupported, + environment: unsupported, + // Not applicable for base language but might be useful for markdown or quarto + section: notApplicable, + "section.iteration.document": notApplicable, + "section.iteration.parent": notApplicable, + notebookCell: notApplicable, + + map: unsupported, + regularExpression: unsupported, + switchStatementSubject: unsupported, + fieldAccess: unsupported, + "string.singleLine": unsupported, + "string.multiLine": unsupported, + + // "statement.class" + // "statement.iteration.document" + // "statement.iteration.block" + class: unsupported, + // "class.iteration.document" + // "class.iteration.block" + className: unsupported, + // "className.iteration.document" + // "className.iteration.block" + // "namedFunction.method" + // "namedFunction.method.iteration.class" + // "namedFunction.constructor" + // "namedFunction.iteration.block" + // "namedFunction.iteration.document" + // "functionName.method" + // "functionName.method.iteration.class" + // "functionName.constructor" + // "functionName.iteration.block" + // "functionName.iteration.document" + // "functionCall.constructor" + // "functionCallee.constructor" + // "argument.actual" + // "argument.actual.iteration" + // "argument.actual.method" + // "argument.actual.method.iteration" + // "argument.actual.constructor" + // "argument.actual.constructor.iteration" + // "argument.formal" + // "argument.formal.iteration" + // "argument.formal.method" + // "argument.formal.method.iteration" + // "argument.formal.constructor" + // "argument.formal.constructor.iteration" + // "argument.formal.lambda" + // "argument.formal.lambda.iteration" + // "argumentList.formal.method" + // "argumentList.formal.constructor" + // "argumentList.formal.lambda" + // "textFragment.comment.line" + // "textFragment.comment.block" + // "textFragment.string.singleLine" + // "textFragment.string.multiLine" + // "textFragment.element" + // disqualifyDelimiter + // pairDelimiter + "branch.if": unsupported, + // "branch.loop" + // "branch.if.iteration" + // "branch.try" + // "branch.try.iteration" + // "branch.switchCase" + // "branch.switchCase.iteration" + // "branch.ternary" + // "collectionItem.unenclosed" + // "collectionItem.unenclosed.iteration" + // "condition.if" + // "condition.while" + // "condition.doWhile" + // "condition.for" + // "condition.ternary" + // "condition.switchCase" + // "condition.switchCase.iteration" + // "name.assignment" + // "name.assignment.pattern" + // "name.variable" + // "name.variable.pattern" + // "name.foreach" + // "name.function" + // "name.method" + // "name.constructor" + // "name.class" + // "name.field" + // "name.resource" + // "name.resource.iteration" + // "name.argument.actual" + // "name.argument.actual.iteration" + // "name.argument.formal" + // "name.argument.formal.iteration" + // "name.argument.formal.method" + // "name.argument.formal.method.iteration" + // "name.argument.formal.constructor" + // "name.argument.formal.constructor.iteration" + // "name.iteration.block" + // "name.iteration.document" + // "key.attribute" + // "key.mapPair" + // "key.mapPair.iteration" + // "value.mapPair" + // "value.mapPair.iteration" + // "value.foreach" + // "value.attribute" + "value.return": unsupported, + // "value.return.lambda" + // "value.field" + // "value.yield" + // "value.resource" + // "value.resource.iteration" + // "value.argument.formal" + // "value.argument.formal.iteration" + // "value.argument.actual" + // "value.argument.actual.iteration" + // "value.argument.formal.method" + // "value.argument.formal.method.iteration" + // "value.argument.formal.constructor" + // "value.argument.formal.constructor.iteration" + // "value.typeAlias": notApplicable, + "type.variable": notApplicable, + "type.argument.formal": notApplicable, + "type.argument.formal.iteration": notApplicable, + "type.argument.formal.method": notApplicable, + "type.argument.formal.method.iteration": notApplicable, + "type.argument.formal.constructor": notApplicable, + "type.argument.formal.constructor.iteration": notApplicable, + "type.return": notApplicable, + "type.field": notApplicable, + "type.field.iteration": notApplicable, + "type.foreach": notApplicable, + "type.interface": notApplicable, + "type.enum": notApplicable, + "type.class": notApplicable, + "type.alias": notApplicable, + "type.cast": notApplicable, + "type.typeArgument": notApplicable, + "type.typeArgument.iteration": notApplicable, + "type.resource": notApplicable, + "type.resource.iteration": notApplicable, + "interior.element": notApplicable, + "interior.command": notApplicable, + "interior.cell": notApplicable, + "interior.class": unsupported, + // "interior.switchCase" + // "interior.ternary" + // "interior.loop" + // "interior.resource" + + "name.foreach": unsupported, }; diff --git a/queries/r.scm b/queries/r.scm index 8d62246200..e3f0595b20 100644 --- a/queries/r.scm +++ b/queries/r.scm @@ -6,21 +6,132 @@ (if_statement) (repeat_statement) (function_definition) + (while_statement) + (function_definition) ] @statement +;;!! # hello +;;! ^^^^^^^ (comment) @comment + +;;!! if (x > 0) { } +;;! ^^^^^^^^^^^^^^ (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 + +;;!! foo(x) +;;! ^ (argument) @argumentOrParameter +;;!! foo(x) +;;! ^^^^^^ +(call) @functionCall + +;;!! function(x){ } +;;! ^^^^^^^^^^^^^^ +(function_definition) @anonymousFunction + +;;!! function("bar") +;;! ^^^^^ +( + (parameters + (_)? @_.leading.endOf + . + (_) @argumentOrParameter + . + (_)? @_.trailing.startOf + ) @_dummy + (#single-or-multi-line-delimiter! @argumentOrParameter @_dummy ", " ",\n") +) +(_ + parameters: (_ + "(" @argumentList.start.endOf @argumentOrParameter.iteration.start.endOf + ")" @argumentList.end.startOf @argumentOrParameter.iteration.end.startOf + ) @_dummy + (#empty-single-multi-delimiter! @argumentList.start.endOf @_dummy "" ", " ",\n") +) @argumentList.domain @argumentOrParameter.iteration.domain + +(parameters + "(" @argumentOrParameter.iteration.start.endOf + ")" @argumentOrParameter.iteration.end.startOf +) @argumentOrParameter.iteration.domain + +;;!! abc <- function(x){ } +;;! ^^^^^^^^^^^^^^^^^^^^^ +(binary_operator + ;;!! abc <- function(x){ } + ;;! ^^^ + lhs: (identifier) @functionName + rhs: (function_definition + name: "function" + parameters: (parameters) + body: (braced_expression) @interior + ) +) @namedFunction + +;;!! foo() +;;! ^^^^^ +;;! ----- (call) @functionCall -(identifier) @identifier -;; ;; https://github.com/r-lib/tree-sitter-r/blob/main/queries/highlights.scm +;;!! foo() +;;! ^^^ +;;! ----- +(call + (identifier) @functionCallee +) + +;; Technically lists and arrays are just calls to the function `list` or `c` +;; TODO: should this include the function name/brackets? +;;!! list(1, 2, 3) +;;! ^^^^^^^^^^^^^ +(call + function: (identifier) @functionName + (#match? @functionName "^(c|list)$") +) @list + +(binary_operator + ;;!! hello <- "world" + ;;! ^^^^^ + ;;! ----- + lhs: (identifier) @name + operator: "<-" + ;;!! hello <- "world" + ;;! ^^^^^^^ + ;;! ----- + rhs: (_) @value +) +(binary_operator + ;;!! hello <- "world" + ;;! ^^^^^ + ;;! ----- + lhs: (identifier) @name + operator: "=" + ;;!! hello <- "world" + ;;! ^^^^^^^ + ;;! ----- + rhs: (_) @value +) + +;;!! foo(hello) +;;! ^^^^^ +;;! ----- +;; (identifier) @value + +;; ;; from https://github.com/r-lib/tree-sitter-r/blob/main/queries/highlights.scm ;; ;; Plus magrittr operators -;; [ "?" ":=" "=" "<-" "<<-" "->" "->>" +;; operator: [ "?" ":=" "=" "<-" "<<-" "->" "->>" ;; "~" "|>" "||" "|" "&&" "&" ;; "<" "<=" ">" ">=" "==" "!=" ;; "+" "-" "*" "/" "::" ":::" ;; "**" "^" "$" "@" ":" "%in%" ;; "%>%" "%<>%" "%T>%" "%$%" ;; "special" -;; ] @operator +;; ] @disqualifyDelimiter From 84600fff7f40bb44a71916114d83e8acc6fe4922 Mon Sep 17 00:00:00 2001 From: bluedrink9 Date: Sat, 17 May 2025 15:18:08 +1200 Subject: [PATCH 4/4] (r) clean up facet list --- packages/common/src/scopeSupportFacets/r.ts | 217 ++++++-------------- 1 file changed, 62 insertions(+), 155 deletions(-) diff --git a/packages/common/src/scopeSupportFacets/r.ts b/packages/common/src/scopeSupportFacets/r.ts index 5851e12915..f85284599a 100644 --- a/packages/common/src/scopeSupportFacets/r.ts +++ b/packages/common/src/scopeSupportFacets/r.ts @@ -5,185 +5,92 @@ import { ScopeSupportFacetLevel } from "./scopeSupportFacets.types"; const { supported, unsupported, notApplicable } = ScopeSupportFacetLevel; export const rScopeSupport: LanguageScopeSupportFacetMap = { - "comment.line": supported, - "ifStatement": supported, + "anonymousFunction": supported, "argument.actual": supported, "argumentList.formal": supported, + "comment.line": supported, "condition.if": supported, - "condition.while": unsupported, - - "namedFunction": supported, - "anonymousFunction": supported, - "functionName": supported, "functionCall": supported, "functionCallee": supported, - + "functionName": supported, + "ifStatement": supported, "name.assignment": supported, - "name.assignment.pattern": notApplicable, "name.variable": supported, + "namedFunction": supported, "value.assignment": supported, "value.variable": supported, - "value.variable.pattern": notApplicable, - - // "interior.function": unsupported, - // "interior.lambda": unsupported, - // "interior.if": unsupported, - // "interior.try": unsupported, - command: notApplicable, - element: notApplicable, - startTag: notApplicable, - endTag: notApplicable, - tags: notApplicable, + "branch.if": unsupported, + "branch.if.iteration": unsupported, + "branch.loop": unsupported, + "branch.switchCase": unsupported, + "branch.switchCase.iteration": unsupported, + "branch.ternary": unsupported, + "branch.try": unsupported, + "branch.try.iteration": unsupported, + "condition.for": unsupported, + "condition.ternary": unsupported, + "condition.while": unsupported, + "interior.class": unsupported, + "interior.function": unsupported, + "interior.if": unsupported, + "interior.lambda": unsupported, + "interior.try": unsupported, + "key.attribute": unsupported, + "name.class": unsupported, + "name.field": unsupported, + "name.foreach": unsupported, + "name.function": unsupported, + "name.method": unsupported, + "statement.class": unsupported, + "string.multiLine": unsupported, + "string.singleLine": unsupported, + "value.attribute": unsupported, + "value.foreach": unsupported, + "value.return": unsupported, attribute: unsupported, + class: unsupported, + className: unsupported, environment: unsupported, - // Not applicable for base language but might be useful for markdown or quarto - section: notApplicable, - "section.iteration.document": notApplicable, - "section.iteration.parent": notApplicable, - notebookCell: notApplicable, - + fieldAccess: unsupported, map: unsupported, regularExpression: unsupported, switchStatementSubject: unsupported, - fieldAccess: unsupported, - "string.singleLine": unsupported, - "string.multiLine": unsupported, - // "statement.class" - // "statement.iteration.document" - // "statement.iteration.block" - class: unsupported, - // "class.iteration.document" - // "class.iteration.block" - className: unsupported, - // "className.iteration.document" - // "className.iteration.block" - // "namedFunction.method" - // "namedFunction.method.iteration.class" - // "namedFunction.constructor" - // "namedFunction.iteration.block" - // "namedFunction.iteration.document" - // "functionName.method" - // "functionName.method.iteration.class" - // "functionName.constructor" - // "functionName.iteration.block" - // "functionName.iteration.document" - // "functionCall.constructor" - // "functionCallee.constructor" - // "argument.actual" - // "argument.actual.iteration" - // "argument.actual.method" - // "argument.actual.method.iteration" - // "argument.actual.constructor" - // "argument.actual.constructor.iteration" - // "argument.formal" - // "argument.formal.iteration" - // "argument.formal.method" - // "argument.formal.method.iteration" - // "argument.formal.constructor" - // "argument.formal.constructor.iteration" - // "argument.formal.lambda" - // "argument.formal.lambda.iteration" - // "argumentList.formal.method" - // "argumentList.formal.constructor" - // "argumentList.formal.lambda" - // "textFragment.comment.line" - // "textFragment.comment.block" - // "textFragment.string.singleLine" - // "textFragment.string.multiLine" - // "textFragment.element" - // disqualifyDelimiter - // pairDelimiter - "branch.if": unsupported, - // "branch.loop" - // "branch.if.iteration" - // "branch.try" - // "branch.try.iteration" - // "branch.switchCase" - // "branch.switchCase.iteration" - // "branch.ternary" - // "collectionItem.unenclosed" - // "collectionItem.unenclosed.iteration" - // "condition.if" - // "condition.while" - // "condition.doWhile" - // "condition.for" - // "condition.ternary" - // "condition.switchCase" - // "condition.switchCase.iteration" - // "name.assignment" - // "name.assignment.pattern" - // "name.variable" - // "name.variable.pattern" - // "name.foreach" - // "name.function" - // "name.method" - // "name.constructor" - // "name.class" - // "name.field" - // "name.resource" - // "name.resource.iteration" - // "name.argument.actual" - // "name.argument.actual.iteration" - // "name.argument.formal" - // "name.argument.formal.iteration" - // "name.argument.formal.method" - // "name.argument.formal.method.iteration" - // "name.argument.formal.constructor" - // "name.argument.formal.constructor.iteration" - // "name.iteration.block" - // "name.iteration.document" - // "key.attribute" - // "key.mapPair" - // "key.mapPair.iteration" - // "value.mapPair" - // "value.mapPair.iteration" - // "value.foreach" - // "value.attribute" - "value.return": unsupported, - // "value.return.lambda" - // "value.field" - // "value.yield" - // "value.resource" - // "value.resource.iteration" - // "value.argument.formal" - // "value.argument.formal.iteration" - // "value.argument.actual" - // "value.argument.actual.iteration" - // "value.argument.formal.method" - // "value.argument.formal.method.iteration" - // "value.argument.formal.constructor" - // "value.argument.formal.constructor.iteration" - // "value.typeAlias": notApplicable, - "type.variable": notApplicable, + "interior.cell": notApplicable, + "interior.command": notApplicable, + "interior.element": notApplicable, + "name.assignment.pattern": notApplicable, + // Not applicable for base language but might be useful for markdown or quarto + "section.iteration.document": notApplicable, + "section.iteration.parent": notApplicable, + "type.alias": notApplicable, "type.argument.formal": notApplicable, + "type.argument.formal.constructor": notApplicable, + "type.argument.formal.constructor.iteration": notApplicable, "type.argument.formal.iteration": notApplicable, "type.argument.formal.method": notApplicable, "type.argument.formal.method.iteration": notApplicable, - "type.argument.formal.constructor": notApplicable, - "type.argument.formal.constructor.iteration": notApplicable, - "type.return": notApplicable, + "type.cast": notApplicable, + "type.class": notApplicable, + "type.enum": notApplicable, "type.field": notApplicable, "type.field.iteration": notApplicable, "type.foreach": notApplicable, "type.interface": notApplicable, - "type.enum": notApplicable, - "type.class": notApplicable, - "type.alias": notApplicable, - "type.cast": notApplicable, - "type.typeArgument": notApplicable, - "type.typeArgument.iteration": notApplicable, "type.resource": notApplicable, "type.resource.iteration": notApplicable, - "interior.element": notApplicable, - "interior.command": notApplicable, - "interior.cell": notApplicable, - "interior.class": unsupported, - // "interior.switchCase" - // "interior.ternary" - // "interior.loop" - // "interior.resource" - - "name.foreach": unsupported, + "type.return": notApplicable, + "type.typeArgument": notApplicable, + "type.typeArgument.iteration": notApplicable, + "type.variable": notApplicable, + "value.typeAlias": notApplicable, + "value.variable.pattern": notApplicable, + command: notApplicable, + element: notApplicable, + endTag: notApplicable, + notebookCell: notApplicable, + section: notApplicable, + startTag: notApplicable, + tags: notApplicable, };