Skip to content

Commit

Permalink
Added iteration scope for js statements (#2144)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson authored Dec 18, 2023
1 parent 86266ce commit fff171f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 10 deletions.
5 changes: 4 additions & 1 deletion packages/common/src/scopeSupportFacets/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ const { supported, notApplicable } = ScopeSupportFacetLevel;
export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
list: supported,
map: supported,
statement: supported,
ifStatement: supported,
regularExpression: supported,
switchStatementSubject: supported,
fieldAccess: supported,

statement: supported,
"statement.iteration.document": supported,
"statement.iteration.block": supported,

class: supported,
className: supported,

Expand Down
20 changes: 16 additions & 4 deletions packages/common/src/scopeSupportFacets/scopeSupportFacetInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ export const scopeSupportFacetInfos: Record<
description: "A map/dictionary",
scopeType: "map",
},
statement: {
description: "A statement, eg assignment, for loop, etc",
scopeType: "statement",
},
ifStatement: {
description: "An if statement",
scopeType: "ifStatement",
Expand All @@ -64,6 +60,22 @@ export const scopeSupportFacetInfos: Record<
scopeType: "private.fieldAccess",
},

statement: {
description: "A statement, eg assignment, for loop, etc",
scopeType: "statement",
},
"statement.iteration.document": {
description: "Iteration scope for statements. The entire document.",
scopeType: "statement",
isIteration: true,
},
"statement.iteration.block": {
description:
"Iteration scope for statements. Statement blocks(body of functions/if statements/for loops/etc).",
scopeType: "statement",
isIteration: true,
},

class: {
description: "A class in an object-oriented language",
scopeType: "class",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ const scopeSupportFacets = [

"list",
"map",
"statement",
"ifStatement",
"regularExpression",
"switchStatementSubject",
"fieldAccess",

"statement",
"statement.iteration.document",
"statement.iteration.block",

"class",
"className",
"namedFunction",
Expand Down
12 changes: 8 additions & 4 deletions packages/common/src/testUtil/getFixturePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ export function getRecordedTestPaths() {
return walkFilesSync(directory)
.filter((p) => p.endsWith(".yml") || p.endsWith(".yaml"))
.map((p) => ({
name: path
.relative(relativeDir, p.substring(0, p.lastIndexOf(".")))
.replaceAll("\\", "/"),
path: p,
name: pathToName(relativeDir, p),
}));
}

Expand All @@ -47,8 +45,14 @@ export function getScopeTestPaths() {
.filter((p) => p.endsWith(".scope"))
.map((p) => ({
path: p,
name: path.relative(relativeDir, p.substring(0, p.lastIndexOf("."))),
name: pathToName(relativeDir, p),
languageId: path.dirname(path.relative(directory, p)).split(path.sep)[0],
facet: path.basename(p).match(/([a-zA-Z.]+)\d*\.scope/)![1],
}));
}

function pathToName(relativeDir: string, filePath: string) {
return path
.relative(relativeDir, filePath.substring(0, filePath.lastIndexOf(".")))
.replaceAll("\\", "/");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function foo() {

}
---

[#1 Range] =
[#1 Domain] = 0:0-2:1
0| function foo() {
>----------------
1|

2| }
-<


[#2 Range] =
[#2 Domain] = 0:16-2:0
0| function foo() {
>
1|

2| }
<
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Start

function foo() {

}
---

[#1 Range] =
[#1 Domain] = 0:0-4:1
0| // Start
>--------
1|

2| function foo() {
----------------
3|

4| }
-<


[#2 Range] =
[#2 Domain] = 2:16-4:0
0| // Start

1|

2| function foo() {
>
3|

4| }
<
7 changes: 7 additions & 0 deletions queries/javascript.core.scm
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,13 @@
(#not-parent-type? @statement export_statement)
)

(program) @statement.iteration

(statement_block
"{" @statement.iteration.start.endOf
"}" @statement.iteration.end.startOf
)

;;!! foo(name: string) {}
;;! ^^^^^^^^^^^^
(
Expand Down

0 comments on commit fff171f

Please sign in to comment.