-
-
Notifications
You must be signed in to change notification settings - Fork 91
Added html language implementation #385
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1913db
Added html language implementation
AndreasArvidsson 8951929
Added additional angle bound
AndreasArvidsson 703a7e1
Added tests
AndreasArvidsson cb7be72
Updated tests
AndreasArvidsson 7d550b0
Changed order of delimiters
AndreasArvidsson 575246d
Merge branch 'main' into html
AndreasArvidsson 8886829
A de test inside comment
AndreasArvidsson f9f98d2
Merge branch 'main' into html
AndreasArvidsson f7ad3c9
Added htmlStringTextFragmentExtractor
AndreasArvidsson 38b3ee8
Merged with main
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 hidden or 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,9 +1,25 @@ | ||
<html> | ||
|
||
<head> | ||
<link rel="stylesheet" href="./index.css"> | ||
<style> | ||
p { | ||
color: red; | ||
font-size: 20px; | ||
} | ||
</style> | ||
<title> | ||
Hello | ||
</title> | ||
</head> | ||
<body> | ||
<script> | ||
<h1>Title</h1> | ||
</script> | ||
<h1>Title</h1> | ||
<div id="this-is-my-2id" data-a=5> | ||
Hello world | ||
<!-- Comment --> | ||
</div> | ||
<br/> | ||
</body> | ||
|
||
</html> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
import { | ||
createPatternMatchers, | ||
leadingMatcher, | ||
patternMatcher, | ||
} from "../util/nodeMatchers"; | ||
import { | ||
ScopeType, | ||
NodeMatcherAlternative, | ||
SelectionWithEditor, | ||
} from "../typings/Types"; | ||
import { SyntaxNode } from "web-tree-sitter"; | ||
import { 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; | ||
}; | ||
const nodeMatchers: Partial<Record<ScopeType, NodeMatcherAlternative>> = { | ||
xmlElement: ["element", "script_element", "style_element"], | ||
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", | ||
}; | ||
|
||
export const patternMatchers = createPatternMatchers(nodeMatchers); | ||
|
||
export function stringTextFragmentExtractor( | ||
node: SyntaxNode, | ||
selection: SelectionWithEditor | ||
) { | ||
if (node.type === "attribute_value") { | ||
return getNodeRange(node); | ||
} | ||
|
||
return null; | ||
} |
This file contains hidden or 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
33 changes: 33 additions & 0 deletions
33
src/test/suite/fixtures/recorded/languages/html/chuckValueInk.yml
This file contains hidden or 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,33 @@ | ||
languageId: html | ||
command: | ||
version: 1 | ||
spokenForm: chuck value ink | ||
action: remove | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: value, includeSiblings: false} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: i} | ||
initialState: | ||
documentContents: |- | ||
<html id="value"> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 1, character: 4} | ||
active: {line: 1, character: 4} | ||
marks: | ||
default.i: | ||
start: {line: 0, character: 6} | ||
end: {line: 0, character: 8} | ||
finalState: | ||
documentContents: |- | ||
<html id> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 1, character: 4} | ||
active: {line: 1, character: 4} | ||
thatMark: | ||
- anchor: {line: 0, character: 8} | ||
active: {line: 0, character: 8} | ||
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: i}, selectionType: token, position: contents, insideOutsideType: outside, modifier: {type: containingScope, scopeType: value, includeSiblings: false}}] |
33 changes: 33 additions & 0 deletions
33
src/test/suite/fixtures/recorded/languages/html/clearAttributeVest.yml
This file contains hidden or 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,33 @@ | ||
languageId: html | ||
command: | ||
version: 1 | ||
spokenForm: clear attribute vest | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: attribute, includeSiblings: false} | ||
mark: {type: decoratedSymbol, symbolColor: default, character: v} | ||
initialState: | ||
documentContents: |- | ||
<html id="value"> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 1, character: 4} | ||
active: {line: 1, character: 4} | ||
marks: | ||
default.v: | ||
start: {line: 0, character: 10} | ||
end: {line: 0, character: 15} | ||
finalState: | ||
documentContents: |- | ||
<html > | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} | ||
thatMark: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} | ||
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: v}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: attribute, includeSiblings: false}}] |
23 changes: 23 additions & 0 deletions
23
src/test/suite/fixtures/recorded/languages/html/clearComment.yml
This file contains hidden or 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: 1 | ||
spokenForm: clear comment | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: comment, includeSiblings: false} | ||
initialState: | ||
documentContents: <!-- Comment --> | ||
selections: | ||
- anchor: {line: 0, character: 8} | ||
active: {line: 0, character: 8} | ||
marks: {} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: comment, includeSiblings: false}}] |
26 changes: 26 additions & 0 deletions
26
src/test/suite/fixtures/recorded/languages/html/clearElement.yml
This file contains hidden or 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,26 @@ | ||
languageId: html | ||
command: | ||
version: 1 | ||
spokenForm: clear element | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: xmlElement, includeSiblings: false} | ||
initialState: | ||
documentContents: |- | ||
<html> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 1, character: 4} | ||
active: {line: 1, character: 4} | ||
marks: {} | ||
finalState: | ||
documentContents: "" | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: xmlElement, includeSiblings: false}}] |
28 changes: 28 additions & 0 deletions
28
src/test/suite/fixtures/recorded/languages/html/clearEndTag.yml
This file contains hidden or 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,28 @@ | ||
languageId: html | ||
command: | ||
version: 1 | ||
spokenForm: clear end tag | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: xmlEndTag, includeSiblings: false} | ||
initialState: | ||
documentContents: |- | ||
<html> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 1, character: 4} | ||
active: {line: 1, character: 4} | ||
marks: {} | ||
finalState: | ||
documentContents: | | ||
<html> | ||
|
||
selections: | ||
- anchor: {line: 2, character: 0} | ||
active: {line: 2, character: 0} | ||
thatMark: | ||
- anchor: {line: 2, character: 0} | ||
active: {line: 2, character: 0} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: xmlEndTag, includeSiblings: false}}] |
29 changes: 29 additions & 0 deletions
29
src/test/suite/fixtures/recorded/languages/html/clearKey.yml
This file contains hidden or 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,29 @@ | ||
languageId: html | ||
command: | ||
version: 1 | ||
spokenForm: clear key | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: collectionKey, includeSiblings: false} | ||
initialState: | ||
documentContents: |- | ||
<html id="value"> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 0, character: 9} | ||
active: {line: 0, character: 9} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
<html ="value"> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} | ||
thatMark: | ||
- anchor: {line: 0, character: 6} | ||
active: {line: 0, character: 6} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: collectionKey, includeSiblings: false}}] |
29 changes: 29 additions & 0 deletions
29
src/test/suite/fixtures/recorded/languages/html/clearName.yml
This file contains hidden or 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,29 @@ | ||
languageId: html | ||
command: | ||
version: 1 | ||
spokenForm: clear name | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: name, includeSiblings: false} | ||
initialState: | ||
documentContents: |- | ||
<html id="value"> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 0, character: 9} | ||
active: {line: 0, character: 9} | ||
marks: {} | ||
finalState: | ||
documentContents: |- | ||
< id="value"> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
thatMark: | ||
- anchor: {line: 0, character: 1} | ||
active: {line: 0, character: 1} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: name, includeSiblings: false}}] |
29 changes: 29 additions & 0 deletions
29
src/test/suite/fixtures/recorded/languages/html/clearStartTag.yml
This file contains hidden or 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,29 @@ | ||
languageId: html | ||
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 wonder if "clear" should leave the angles. Can't decide 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. Take and clear always have the same range so far. I don't want to change that |
||
command: | ||
version: 1 | ||
spokenForm: clear start tag | ||
action: clearAndSetSelection | ||
targets: | ||
- type: primitive | ||
modifier: {type: containingScope, scopeType: xmlStartTag, includeSiblings: false} | ||
initialState: | ||
documentContents: |- | ||
<html> | ||
|
||
</html> | ||
selections: | ||
- anchor: {line: 1, character: 4} | ||
active: {line: 1, character: 4} | ||
marks: {} | ||
finalState: | ||
documentContents: |2- | ||
|
||
|
||
</html> | ||
selections: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
thatMark: | ||
- anchor: {line: 0, character: 0} | ||
active: {line: 0, character: 0} | ||
fullTargets: [{type: primitive, mark: {type: cursor}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: containingScope, scopeType: xmlStartTag, includeSiblings: false}}] |
Oops, something went wrong.
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.
Will an attribute value always be a string?
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.
No. But it's the only type that can contain other matching pairs
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.
Ok so this is a hack, then, right? Because there might be things that are children that are not strings? It's ok if it's a hack, we should just document that in a comment
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 could also just check node parent type as well maybe?
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.
Or check that it has first and last child of type
"
?Uh oh!
There was an error while loading. Please reload this page.
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 wouldn't say it's a hack. It is a type that can contain text based matching pairs. But I can't contain any children in the tree sitter as far as I know. I tried with few different values and it all behaved as expected.