-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Migrate html scopes #2044
Merged
Merged
Migrate html scopes #2044
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4312131
Migrate html scopes
AndreasArvidsson e1be629
Leading value
AndreasArvidsson 298dc6d
Key trailing
AndreasArvidsson 759e609
Merge branch 'main' into html_scopes
AndreasArvidsson c349b26
cleanup
AndreasArvidsson 076c641
Fix indentation
pokey 0af2ce0
Iterations scope for start and end tag
AndreasArvidsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,11 @@ | ||
import type { SyntaxNode } from "web-tree-sitter"; | ||
import { SimpleScopeTypeType } from "@cursorless/common"; | ||
import { NodeMatcherAlternative, SelectionWithEditor } from "../typings/Types"; | ||
import { typedNodeFinder } from "../util/nodeFinders"; | ||
import { | ||
createPatternMatchers, | ||
leadingMatcher, | ||
matcher, | ||
patternMatcher, | ||
} from "../util/nodeMatchers"; | ||
import { xmlElementExtractor, getNodeRange } from "../util/nodeSelectors"; | ||
|
||
const attribute = "*?.attribute!"; | ||
|
||
const getStartTag = patternMatcher(`*?.start_tag!`); | ||
const getEndTag = patternMatcher(`*?.end_tag!`); | ||
|
||
const getTags = (selection: SelectionWithEditor, node: SyntaxNode) => { | ||
const startTag = getStartTag(selection, node); | ||
const endTag = getEndTag(selection, node); | ||
return startTag != null && endTag != null ? startTag.concat(endTag) : null; | ||
}; | ||
import { NodeMatcherAlternative } from "../typings/Types"; | ||
import { createPatternMatchers } from "../util/nodeMatchers"; | ||
|
||
const nodeMatchers: Partial< | ||
Record<SimpleScopeTypeType, NodeMatcherAlternative> | ||
> = { | ||
xmlElement: matcher( | ||
typedNodeFinder("element", "script_element", "style_element"), | ||
xmlElementExtractor, | ||
), | ||
xmlBothTags: getTags, | ||
xmlStartTag: getStartTag, | ||
xmlEndTag: getEndTag, | ||
attribute: attribute, | ||
collectionItem: attribute, | ||
name: "*?.tag_name!", | ||
collectionKey: ["*?.attribute_name!"], | ||
value: leadingMatcher( | ||
["*?.quoted_attribute_value!.attribute_value", "*?.attribute_value!"], | ||
["="], | ||
), | ||
string: "quoted_attribute_value", | ||
comment: "comment", | ||
collectionItem: "*?.attribute!", | ||
}; | ||
|
||
export const patternMatchers = createPatternMatchers(nodeMatchers); | ||
|
||
const textFragmentTypes = ["attribute_value", "raw_text", "text"]; | ||
|
||
export function stringTextFragmentExtractor( | ||
node: SyntaxNode, | ||
_selection: SelectionWithEditor, | ||
) { | ||
if (textFragmentTypes.includes(node.type)) { | ||
return getNodeRange(node); | ||
} | ||
|
||
return null; | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/html/chuckValue.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
languageId: html | ||
command: | ||
version: 6 | ||
spokenForm: chuck value | ||
action: | ||
name: remove | ||
target: | ||
type: primitive | ||
modifiers: | ||
- type: containingScope | ||
scopeType: {type: value} | ||
usePrePhraseSnapshot: true | ||
initialState: | ||
documentContents: <html value=2></html> | ||
selections: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} | ||
marks: {} | ||
finalState: | ||
documentContents: <html value></html> | ||
selections: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
;;!! <aaa> | ||
;;! ^^^ | ||
;;! ----- | ||
(start_tag | ||
(tag_name) @name | ||
) @_.domain | ||
|
||
;;!! </aaa> | ||
;;! ^^^ | ||
;;! ------ | ||
(end_tag | ||
(tag_name) @name | ||
) @_.domain | ||
|
||
;;!! <aaa id="me"> | ||
;;! ^^^^^^^ | ||
(attribute) @attribute | ||
|
||
;;!! <aaa id="me"> | ||
;;! ^^ | ||
(attribute | ||
(attribute_name) @collectionKey @collectionKey.trailing.start.endOf | ||
[ | ||
(quoted_attribute_value) | ||
(attribute_value) | ||
] ? @collectionKey.trailing.end.startOf | ||
) @_.domain | ||
|
||
;;!! <aaa value=2> | ||
;;! ^ | ||
;;!! <aaa id="me"> | ||
;;! ^^^^ | ||
(attribute | ||
(attribute_name) @value.leading.start.endOf | ||
[ | ||
(quoted_attribute_value) | ||
(attribute_value) | ||
] @value @value.leading.end.startOf | ||
) @value.domain | ||
|
||
;;!! <aaa id="me"> | ||
;;! ^^ | ||
(quoted_attribute_value | ||
(attribute_value) @textFragment | ||
) @string | ||
|
||
;;!! <aaa> | ||
;;! ^^^^^ | ||
(start_tag) @attribute.iteration @collectionKey.iteration @value.iteration | ||
|
||
;;!! <!-- comment --> | ||
;;! ^^^^^^^^^^^^^^^^ | ||
(comment) @comment @textFragment | ||
|
||
;;!! <aaa>text</aaa> | ||
;;! ^^^^ | ||
(text) @textFragment | ||
|
||
;;!! <script>hello</script> | ||
;;! ^^^^^ | ||
(raw_text) @textFragment | ||
|
||
;; Use parent wildcard to get all three kinds of elements: element, script_element, style_element | ||
|
||
;;!! <aaa>text</aaa> | ||
;;! ^^^^^^^^^^^^^^^ | ||
;;! ^^^^ | ||
(_ | ||
(start_tag) @xmlElement.interior.start.endOf | ||
(end_tag) @xmlElement.interior.end.startOf | ||
) @xmlElement | ||
|
||
;;!! <aaa>text</aaa> | ||
;;! ^^^^^ ^^^^^^ | ||
;;! --------------- | ||
(_ | ||
(start_tag) @xmlStartTag | ||
(end_tag) @xmlEndTag | ||
) @_.domain | ||
|
||
(_ | ||
[ | ||
(start_tag) | ||
(end_tag) | ||
] @xmlBothTags | ||
(#allow-multiple! @xmlBothTags) | ||
) @_.domain | ||
|
||
(_ | ||
(start_tag) @xmlElement.iteration.start.endOf @xmlBothTags.iteration.start.endOf | ||
(element) | ||
pokey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(end_tag) @xmlElement.iteration.end.startOf @xmlBothTags.iteration.end.startOf | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
;; import html.scm |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you're missing startTag and endTag
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.
added