Skip to content

Commit

Permalink
Added more scope support facets (#2102)
Browse files Browse the repository at this point in the history
This pull request has these goals:
1. To flesh out the available facets and their definitions
2. To provide one example scope fixture of each facet
3. Update the domain of for each loops name/value/type
4. Update domain of iteration scope for formal arguments

Once the above is done I'm going to do the bulk fixture recorder we
talked about to fill in the other languages.

## Checklist

- [x] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [-] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [-] I have not broken the cheatsheet

---------

Co-authored-by: Pokey Rule <[email protected]>
  • Loading branch information
AndreasArvidsson and pokey authored Dec 14, 2023
1 parent 730349d commit 15bfde5
Show file tree
Hide file tree
Showing 95 changed files with 2,571 additions and 94 deletions.
12 changes: 12 additions & 0 deletions packages/common/src/scopeSupportFacets/getLanguageScopeSupport.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { htmlScopeSupport } from "./html";
import { javaScopeSupport } from "./java";
import { javascriptScopeSupport } from "./javascript";
import { pythonScopeSupport } from "./python";
import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types";
import { talonScopeSupport } from "./talon";
import { typescriptScopeSupport } from "./typescript";

export function getLanguageScopeSupport(
languageId: string,
): LanguageScopeSupportFacetMap {
switch (languageId) {
case "javascript":
return javascriptScopeSupport;
case "typescript":
return typescriptScopeSupport;
case "java":
return javaScopeSupport;
case "python":
return pythonScopeSupport;
case "html":
return htmlScopeSupport;
case "talon":
return talonScopeSupport;
}
throw Error(`Unsupported language: '${languageId}'`);
}
71 changes: 63 additions & 8 deletions packages/common/src/scopeSupportFacets/html.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */

import {
LanguageScopeSupportFacetMap,
ScopeSupportFacetLevel,
Expand All @@ -6,14 +8,67 @@ import {
const { supported, notApplicable } = ScopeSupportFacetLevel;

export const htmlScopeSupport: LanguageScopeSupportFacetMap = {
["key.attribute"]: supported,
["tags"]: supported,
element: supported,
tags: supported,
startTag: supported,
endTag: supported,
attribute: supported,
"key.attribute": supported,
"value.attribute": supported,
"comment.block": supported,

"argument.actual": notApplicable,
"argument.actual.iteration": notApplicable,
"argument.formal": notApplicable,
"argument.formal.iteration": notApplicable,
"branch.if": notApplicable,
"branch.switchCase": notApplicable,
"branch.try": notApplicable,
"comment.line": notApplicable,
"condition.doWhile": notApplicable,
"condition.for": notApplicable,
"condition.if": notApplicable,
"condition.switchCase": notApplicable,
"condition.ternary": notApplicable,
"condition.while": notApplicable,
"functionCall.constructor": notApplicable,
"functionCallee.constructor": notApplicable,
"key.mapPair.iteration": notApplicable,
"key.mapPair": notApplicable,
"name.assignment": notApplicable,
"name.class": notApplicable,
"name.field": notApplicable,
"name.foreach": notApplicable,
"name.function": notApplicable,
"namedFunction.method": notApplicable,
"string.multiLine": notApplicable,
"string.singleLine": notApplicable,
"type.assignment": notApplicable,
"type.field": notApplicable,
"type.foreach": notApplicable,
"type.formalParameter": notApplicable,
"type.interface": notApplicable,
"type.return": notApplicable,
"value.assignment": notApplicable,
"value.field": notApplicable,
"value.foreach": notApplicable,
"value.mapPair.iteration": notApplicable,
"value.mapPair": notApplicable,
"value.return.lambda": notApplicable,
"value.return": notApplicable,
anonymousFunction: notApplicable,
class: notApplicable,
className: notApplicable,
command: notApplicable,
fieldAccess: notApplicable,
functionCall: notApplicable,
functionCallee: notApplicable,
functionName: notApplicable,
ifStatement: notApplicable,
list: notApplicable,
map: notApplicable,
namedFunction: notApplicable,
["name.assignment"]: notApplicable,
["key.mapPair"]: notApplicable,
["key.mapPair.iteration"]: notApplicable,
["value.mapPair"]: notApplicable,
["value.mapPair.iteration"]: notApplicable,
["value.assignment"]: notApplicable,
regularExpression: notApplicable,
statement: notApplicable,
switchStatementSubject: notApplicable,
};
20 changes: 20 additions & 0 deletions packages/common/src/scopeSupportFacets/java.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable @typescript-eslint/naming-convention */

import {
LanguageScopeSupportFacetMap,
ScopeSupportFacetLevel,
} from "./scopeSupportFacets.types";

const { supported, notApplicable } = ScopeSupportFacetLevel;

export const javaScopeSupport: LanguageScopeSupportFacetMap = {
"name.foreach": supported,
"value.foreach": supported,
"type.foreach": supported,

element: notApplicable,
tags: notApplicable,
attribute: notApplicable,
"key.attribute": notApplicable,
"value.attribute": notApplicable,
};
89 changes: 80 additions & 9 deletions packages/common/src/scopeSupportFacets/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */

import {
LanguageScopeSupportFacetMap,
ScopeSupportFacetLevel,
Expand All @@ -6,14 +8,83 @@ import {
const { supported, notApplicable } = ScopeSupportFacetLevel;

export const javascriptScopeSupport: LanguageScopeSupportFacetMap = {
list: supported,
map: supported,
statement: supported,
ifStatement: supported,
regularExpression: supported,
switchStatementSubject: supported,
fieldAccess: supported,

class: supported,
className: supported,

namedFunction: supported,
["name.assignment"]: supported,
["key.mapPair"]: supported,
["key.mapPair.iteration"]: supported,
["value.mapPair"]: supported,
["value.mapPair.iteration"]: supported,
["value.assignment"]: supported,

["key.attribute"]: notApplicable,
["tags"]: notApplicable,
"namedFunction.method": supported,
anonymousFunction: supported,
functionName: supported,

functionCall: supported,
"functionCall.constructor": supported,
functionCallee: supported,
"functionCallee.constructor": supported,

"argument.actual": supported,
"argument.actual.iteration": supported,
"argument.formal": supported,
"argument.formal.iteration": supported,

"comment.line": supported,
"comment.block": supported,

"string.singleLine": supported,
"string.multiLine": supported,

"branch.if": supported,
"branch.if.iteration": supported,
"branch.try": supported,
"branch.switchCase": supported,
"branch.switchCase.iteration": supported,
"branch.ternary": supported,

"condition.if": supported,
"condition.while": supported,
"condition.doWhile": supported,
"condition.for": supported,
"condition.ternary": supported,
"condition.switchCase": supported,

"name.foreach": supported,
"name.assignment": supported,
"name.assignment.pattern": supported,
"name.function": supported,
"name.class": supported,
"name.field": supported,

"key.mapPair": supported,
"key.mapPair.iteration": supported,

"value.mapPair": supported,
"value.mapPair.iteration": supported,
"value.assignment": supported,
"value.foreach": supported,
"value.return": supported,
"value.return.lambda": supported,
"value.field": supported,

element: supported,
tags: supported,
startTag: supported,
endTag: supported,
attribute: supported,
"key.attribute": supported,
"value.attribute": supported,

"type.assignment": notApplicable,
"type.formalParameter": notApplicable,
"type.return": notApplicable,
"type.field": notApplicable,
"type.foreach": notApplicable,
"type.interface": notApplicable,
command: notApplicable,
};
24 changes: 24 additions & 0 deletions packages/common/src/scopeSupportFacets/python.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-disable @typescript-eslint/naming-convention */

import {
LanguageScopeSupportFacetMap,
ScopeSupportFacetLevel,
} from "./scopeSupportFacets.types";

const { supported, supportedLegacy, notApplicable } = ScopeSupportFacetLevel;

export const pythonScopeSupport: LanguageScopeSupportFacetMap = {
"name.foreach": supported,
"value.foreach": supported,

"argument.actual": supportedLegacy,
"argument.actual.iteration": supportedLegacy,
"argument.formal": supportedLegacy,
"argument.formal.iteration": supportedLegacy,

element: notApplicable,
tags: notApplicable,
attribute: notApplicable,
"key.attribute": notApplicable,
"value.attribute": notApplicable,
};
Loading

0 comments on commit 15bfde5

Please sign in to comment.