-
-
Notifications
You must be signed in to change notification settings - Fork 89
Scope tests #2053
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
Scope tests #2053
Changes from 69 commits
6ac7ea6
9bc6d8a
8326276
5feb0cf
6cd7cc0
eac4b30
fcef5ec
0348ae4
dde8a77
9f79367
33263bb
91a5fc2
9123d4b
ec2004c
a1e62ea
fcefb46
191454f
5814cd5
e3753b3
7dcde95
c5d8fdb
071e815
c6b8aaf
b756723
9965927
5e76ff0
1995cde
b93893e
f45a753
d5d4c28
473a084
ee9fa80
2f8dfa2
bf70406
bf5e187
f2b63d8
9f9de74
fc63d43
cbd156f
653354e
fee4588
1a96826
0e70883
ed21c4d
f783cb1
4c39f55
963675e
c5da832
ef8d452
66669f2
6c38cc3
eb348ba
2f51f65
459761c
c096e8a
ac90914
da04e03
637d8ea
aa05a65
4f703a4
35718a3
12e7588
b0f4fef
cca1d21
06d00b4
b8c2ade
5f1d178
93d36d0
b8a80a8
7adcef6
cfebfd9
72ef3f5
d427431
616988e
2d8c499
008f4ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { htmlSupport } from "./html"; | ||
import { javascriptSupport } from "./javascript"; | ||
import { plaintextSupport } from "./plaintext"; | ||
import { | ||
LanguageScopeSupportFacetMap, | ||
TextualLanguageScopeSupportFacetMap, | ||
} from "./scopeSupportFacets"; | ||
|
||
export function getLanguageScopeSupport( | ||
languageId: string, | ||
): TextualLanguageScopeSupportFacetMap | LanguageScopeSupportFacetMap { | ||
switch (languageId) { | ||
case "plaintext": | ||
return plaintextSupport; | ||
case "javascript": | ||
return javascriptSupport; | ||
case "html": | ||
return htmlSupport; | ||
} | ||
throw Error(`Unsupported language: '${languageId}'`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
LanguageScopeSupportFacetMap, | ||
ScopeSupportFacetLevel, | ||
} from "@cursorless/common"; | ||
|
||
const { supported, notApplicable } = ScopeSupportFacetLevel; | ||
|
||
export const htmlSupport: LanguageScopeSupportFacetMap = { | ||
["key.attribute"]: supported, | ||
["tags.element"]: supported, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might have tags in another context in the future. I'm just trying to be thorough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. I guess it's a bit more future proof, tho feels like following this convention to the letter might result in some awkward names. Idk cc/ @josharian There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idk either how immutable do we need these facets to be? can we lower the cost of mistakes sufficiently that it doesn't matter much? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Were gonna have a lot of files with these facets as their name so it's not gonna be that easy to change them, but also definitely not impossible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess a simple rename should handle all the typescript refs, and then we could easily write a script that moves the test fixtures There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit annoying having to do a script, but definitely doable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update from meet-up: let's go with just |
||
|
||
namedFunction: notApplicable, | ||
["name.assignment"]: notApplicable, | ||
["key.mapPair"]: notApplicable, | ||
["key.mapPair.iteration"]: notApplicable, | ||
["value.mapPair"]: notApplicable, | ||
["value.mapPair.iteration"]: notApplicable, | ||
["value.assignment"]: notApplicable, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
LanguageScopeSupportFacetMap, | ||
ScopeSupportFacetLevel, | ||
} from "@cursorless/common"; | ||
|
||
const { supported, notApplicable } = ScopeSupportFacetLevel; | ||
|
||
export const javascriptSupport: LanguageScopeSupportFacetMap = { | ||
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.element"]: notApplicable, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
ScopeSupportFacetLevel, | ||
TextualLanguageScopeSupportFacetMap, | ||
} from "@cursorless/common"; | ||
|
||
const { supported } = ScopeSupportFacetLevel; | ||
|
||
export const plaintextSupport: TextualLanguageScopeSupportFacetMap = { | ||
character: supported, | ||
word: supported, | ||
token: supported, | ||
line: supported, | ||
paragraph: supported, | ||
document: supported, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
import { SimpleScopeTypeType } from ".."; | ||
|
||
const scopeSupportFacets = [ | ||
// "list", | ||
// "list.interior", | ||
// "map", | ||
// "map.interior", | ||
// "collectionKey", | ||
"namedFunction", | ||
// "namedFunction.interior", | ||
// "functionName", | ||
// "anonymousFunction", | ||
// "anonymousFunction.interior", | ||
"name.assignment", | ||
"key.attribute", | ||
"key.mapPair", | ||
"key.mapPair.iteration", | ||
"value.assignment", | ||
"value.mapPair", | ||
"value.mapPair.iteration", | ||
// "value.assignment.removal", | ||
// "value.return", | ||
// "value.return.removal", | ||
// "value.collectionItem", | ||
// "value.collectionItem.removal", | ||
// "statement", | ||
// "ifStatement", | ||
// "condition.if", | ||
// "condition.while", | ||
// "condition.doWhile", | ||
// "condition.for", | ||
// "condition.ternary", | ||
// "branch", | ||
// "comment.line", | ||
// "comment.block", | ||
// "string.singleLine", | ||
// "string.multiLine", | ||
// "textFragment", | ||
// "functionCall", | ||
// "functionCallee", | ||
// "argumentOrParameter.argument", | ||
// "argumentOrParameter.argument.removal", | ||
// "argumentOrParameter.parameter", | ||
// "argumentOrParameter.parameter.removal", | ||
// "class", | ||
// "class.interior", | ||
// "className", | ||
// "type", | ||
"tags.element", | ||
] as const; | ||
|
||
const textualScopeSupportFacets = [ | ||
"character", | ||
"word", | ||
"token", | ||
"line", | ||
"paragraph", | ||
"document", | ||
] as const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it confusing to treat textual scope support facets like the other facets. They are not something that we want to ensure languages support, so I don't think they should be lumped in. Maybe we should discuss?
to discuss
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are not. They will only be added to the language plaintext. Other languages are not supposed to implement them. |
||
|
||
export type ScopeSupportFacet = (typeof scopeSupportFacets)[number]; | ||
export type TextualScopeSupportFacet = | ||
(typeof textualScopeSupportFacets)[number]; | ||
|
||
export interface ScopeSupportFacetInfo { | ||
label: string; | ||
description: string; | ||
scopeType: SimpleScopeTypeType; | ||
isIteration?: boolean; | ||
examples: string[]; | ||
} | ||
|
||
export const scopeSupportFacetInfos: Record< | ||
ScopeSupportFacet, | ||
ScopeSupportFacetInfo | ||
> = { | ||
namedFunction: { | ||
label: "Named function", | ||
description: "A named function", | ||
scopeType: "namedFunction", | ||
examples: ["function foo() {}", "const foo = () => {}"], | ||
}, | ||
["name.assignment"]: { | ||
label: "Assignment name", | ||
description: "Name(LHS) of an assignment", | ||
scopeType: "name", | ||
examples: ["const foo = 1"], | ||
}, | ||
["key.attribute"]: { | ||
label: "Attributes key", | ||
description: "Key(LHS) of an attribute", | ||
scopeType: "collectionKey", | ||
examples: ['id="root"'], | ||
}, | ||
["key.mapPair"]: { | ||
label: "Map key", | ||
description: "Key(LHS) of a map pair", | ||
scopeType: "collectionKey", | ||
examples: ["value: 0"], | ||
}, | ||
["key.mapPair.iteration"]: { | ||
label: "Map pair key iteration", | ||
description: "Iteration of map pair keys", | ||
scopeType: "collectionKey", | ||
isIteration: true, | ||
examples: ["{ value: 0 }"], | ||
}, | ||
["value.assignment"]: { | ||
label: "Assignment value", | ||
description: "Value(RHS) of an assignment", | ||
scopeType: "value", | ||
examples: ["const foo = 1"], | ||
}, | ||
["value.mapPair"]: { | ||
label: "Map pair value", | ||
description: "Key(RHS) of a map pair", | ||
scopeType: "value", | ||
examples: ["value: 0"], | ||
}, | ||
["value.mapPair.iteration"]: { | ||
label: "Map pair value iteration", | ||
description: "Iteration of map pair values", | ||
scopeType: "value", | ||
isIteration: true, | ||
examples: ["{ value: 0 }"], | ||
}, | ||
["tags.element"]: { | ||
label: "Tags", | ||
description: "Both tags in an xml element", | ||
scopeType: "xmlBothTags", | ||
examples: ["<div></div>"], | ||
}, | ||
// list: { | ||
// label: "List", | ||
// description: "A list of items", | ||
// scopeType: "list", | ||
// }, | ||
// "list.interior": { | ||
// label: "List interior", | ||
// description: "Excludes the opening and closing delimiters of the list", | ||
// scopeType: "list", | ||
// }, | ||
// map: { | ||
// label: "Map", | ||
// description: "A map of key-value pairs", | ||
// scopeType: "map", | ||
// }, | ||
// "map.interior": { | ||
// label: "Map interior", | ||
// description: "Excludes the opening and closing delimiters of the map", | ||
// scopeType: "map", | ||
// }, | ||
}; | ||
|
||
export const textualScopeSupportFacetInfos: Record< | ||
TextualScopeSupportFacet, | ||
ScopeSupportFacetInfo | ||
> = { | ||
character: { | ||
label: "Character", | ||
description: "A single character in the document", | ||
scopeType: "character", | ||
examples: ["a", "."], | ||
}, | ||
word: { | ||
label: "Word", | ||
description: "A single word in a token", | ||
scopeType: "word", | ||
examples: ["foo_bar", "fooBar"], | ||
}, | ||
token: { | ||
label: "Token", | ||
description: "A single token in the document", | ||
scopeType: "token", | ||
examples: ["foo", "("], | ||
}, | ||
line: { | ||
label: "Line", | ||
description: "A single line in the document", | ||
scopeType: "line", | ||
examples: ["foo"], | ||
}, | ||
paragraph: { | ||
label: "Paragraph", | ||
description: | ||
"A single paragraph(contiguous block of lines) in the document", | ||
scopeType: "paragraph", | ||
examples: ["foo\nbar"], | ||
}, | ||
document: { | ||
label: "Documents", | ||
description: "The entire document", | ||
scopeType: "document", | ||
examples: ["foo\n\nbar"], | ||
}, | ||
}; | ||
|
||
export enum ScopeSupportFacetLevel { | ||
supported, | ||
unsupported, | ||
notApplicable, | ||
} | ||
|
||
export type LanguageScopeSupportFacetMap = Partial< | ||
Record<ScopeSupportFacet, ScopeSupportFacetLevel> | ||
>; | ||
|
||
export type TextualLanguageScopeSupportFacetMap = Record< | ||
TextualScopeSupportFacet, | ||
ScopeSupportFacetLevel | ||
>; |
Uh oh!
There was an error while loading. Please reload this page.