-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Scope tests #2053
Changes from 74 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,15 @@ | ||
import { htmlScopeSupport } from "./html"; | ||
import { javascriptScopeSupport } from "./javascript"; | ||
import { LanguageScopeSupportFacetMap } from "./scopeSupportFacets.types"; | ||
|
||
export function getLanguageScopeSupport( | ||
languageId: string, | ||
): LanguageScopeSupportFacetMap { | ||
switch (languageId) { | ||
case "javascript": | ||
return javascriptScopeSupport; | ||
case "html": | ||
return htmlScopeSupport; | ||
} | ||
throw Error(`Unsupported language: '${languageId}'`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
LanguageScopeSupportFacetMap, | ||
ScopeSupportFacetLevel, | ||
} from "./scopeSupportFacets.types"; | ||
|
||
const { supported, notApplicable } = ScopeSupportFacetLevel; | ||
|
||
export const htmlScopeSupport: LanguageScopeSupportFacetMap = { | ||
["key.attribute"]: supported, | ||
["tags"]: supported, | ||
|
||
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 "./scopeSupportFacets.types"; | ||
|
||
const { supported, notApplicable } = ScopeSupportFacetLevel; | ||
|
||
export const javascriptScopeSupport: 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"]: notApplicable, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
ScopeSupportFacet, | ||
ScopeSupportFacetInfo, | ||
} from "./scopeSupportFacets.types"; | ||
|
||
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"'], | ||
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. As in other examples, this would be more helpful if there were a way to put it in context, but a flat string is not a particularly comfortable way to do that 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. Absolutely. |
||
}, | ||
["key.mapPair"]: { | ||
label: "Map key", | ||
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. These labels feel kinda useless / arbitrary and a bit redundant with the description. I wonder if we just autogenerate these from the id like we do for human-readable scope types. Ie 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. Sounds good to me |
||
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 }"], | ||
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. This shouldn't include the curly brackets, but then it becomes pretty unclear what's going on here. I guess we could use multiple? 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. The examples are not the content range. It's just example of the type of code that would have this facet |
||
}, | ||
["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"]: { | ||
label: "Tags", | ||
description: "Both tags in an xml element", | ||
scopeType: "xmlBothTags", | ||
examples: ["<div></div>"], | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { SimpleScopeTypeType } from "../types/command/PartialTargetDescriptor.types"; | ||
|
||
const scopeSupportFacets = [ | ||
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 do feel like all of these could be their own fine-grained scope. I wonder if we think about moving in that direction sooner rather than later 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 don't quite follow what you're suggesting? What exactly do you want to make more fine grained? I definitely prefer them fine grained 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. Eg 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. Totally agree |
||
// "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", | ||
] as const; | ||
|
||
const textualScopeSupportFacets = [ | ||
"character", | ||
"word", | ||
"token", | ||
"line", | ||
"paragraph", | ||
"document", | ||
] as const; | ||
|
||
export interface ScopeSupportFacetInfo { | ||
readonly label: string; | ||
readonly description: string; | ||
readonly scopeType: SimpleScopeTypeType; | ||
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. What's going to happen when we want to test "round"? That's not a simple scope type 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 just copied the interface from your issue. We can make it a scope type instead? 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. Maybe ok for the time being. I wonder if we create a utility function to make it more ergonomic once we need to support complex scopes. |
||
readonly isIteration?: boolean; | ||
readonly examples: readonly string[]; | ||
} | ||
|
||
export enum ScopeSupportFacetLevel { | ||
supported, | ||
unsupported, | ||
notApplicable, | ||
} | ||
|
||
export type ScopeSupportFacet = (typeof scopeSupportFacets)[number]; | ||
|
||
export type TextualScopeSupportFacet = | ||
(typeof textualScopeSupportFacets)[number]; | ||
|
||
export type LanguageScopeSupportFacetMap = Partial< | ||
Record<ScopeSupportFacet, ScopeSupportFacetLevel> | ||
>; | ||
|
||
export type TextualLanguageScopeSupportFacetMap = Record< | ||
TextualScopeSupportFacet, | ||
ScopeSupportFacetLevel | ||
>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { | ||
ScopeSupportFacetInfo, | ||
TextualScopeSupportFacet, | ||
} from "./scopeSupportFacets.types"; | ||
|
||
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"], | ||
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. These examples are pretty misleading. If we're going to take the example thing seriously, we need to figure out a way to demarcate substrings. I do question how useful / ergonomic it is to just drop these examples into strings. The examples from test casees are already there and likely to be far more useful 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 was thinking examples as a very general guide. If you want details you she'd look at the actual fixtures |
||
}, | ||
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"], | ||
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. this is unhelpful in the other direction. Really questioning the utility of these examples 🤔 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. If you don't like them we can't ditch them |
||
}, | ||
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"], | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div id="root"></div> | ||
--- | ||
|
||
[Content] = 0:5-0:7 | ||
0| <div id="root"></div> | ||
>--< | ||
|
||
[Removal] = 0:5-0:8 | ||
0| <div id="root"></div> | ||
>---< | ||
|
||
[Trailing delimiter] = 0:7-0:8 | ||
0| <div id="root"></div> | ||
>-< | ||
|
||
[Domain] = 0:5-0:14 | ||
0| <div id="root"></div> | ||
>---------< | ||
|
||
[Insertion delimiter] = " " |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div>hello</div> | ||
--- | ||
|
||
[.1 Content] = | ||
[.1 Removal] = 0:0-0:5 | ||
0| <div>hello</div> | ||
>-----< | ||
|
||
[.1 Insertion delimiter] = " " | ||
|
||
[.2 Content] = | ||
[.2 Removal] = 0:10-0:16 | ||
0| <div>hello</div> | ||
>------< | ||
|
||
[.2 Insertion delimiter] = " " | ||
|
||
[Domain] = 0:0-0:16 | ||
0| <div>hello</div> | ||
>----------------< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't true. JSX is valid in JS. Shall we just mark it unsupported / leave it undefined for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that we should test all jsx under javascriptreact and not javascript. I would leave it undefined if anything. Saying that it's unsupported is not true either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Probably fine for now. At some point we should prob figure out how to automatically run tests for all langs where they're applicable, eg run our js tests in ts, etc. We could maybe make subsets of languages and then define a way to import tests from one language to another. But we can do that in a follow-up