Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Conversation

@savetheclocktower
Copy link
Contributor

@savetheclocktower savetheclocktower commented Jul 18, 2019

Description of the Change

Adds appropriate punctuation scopes to the following characters:

  • angle-brackets around HTML tags, as distinct from the tag name itself (e.g., <p>)
  • attribute value delimiters (single and double quotes)
  • the = between an attribute’s name and value

Alternate Designs

None that I can see. This is how tree-sitter grammars are meant to work.

I intentionally left off the .html at the ends of each scope name. This shouldn’t be necessary in order to target HTML-specific punctuation in a syntax theme, even when dealing with HTML injected into another source file.

Benefits

The tree-sitter-html grammar was not adding punctuation scopes to HTML documents. This means that it was impossible (or highly impractical) to style these punctuation marks in any way that distinguished them from ordinary, unscoped text. See #224.

Possible Drawbacks

Opening Pandora’s box, perhaps? But this is just about inching the tree-sitter grammar toward feature parity with its TM-style sibling.

Applicable Issues

Fixes #224.

@savetheclocktower savetheclocktower changed the title Add scopes for punctuation (fixes #22). Add scopes for punctuation. Jul 18, 2019
@savetheclocktower
Copy link
Contributor Author

The failing CI doesn't appear to be related to any changes introduced in this PR.

Also, I neglected to add unit tests because the existing spec tests only the TM-style grammar. If there's a way to unit-test the tree-sitter grammar, I'm all for starting.

@rsese
Copy link

rsese commented Jul 19, 2019

Thanks @savetheclocktower 🙇

Fixes #22.

Just to double check, did you mean #224?

@savetheclocktower
Copy link
Contributor Author

I did indeed. Updated the PR description.

@jasonrudolph
Copy link
Contributor

The failing CI doesn't appear to be related to any changes introduced in this PR.

I re-ran the build and it's passing now. 😅

Also, I neglected to add unit tests because the existing spec tests only the TM-style grammar. If there's a way to unit-test the tree-sitter grammar, I'm all for starting.

We recently added some specs for the Tree-sitter grammar in atom/language-ruby (atom/language-ruby@c616809). Those specs might offer a starting point for you if you're up for adding some specs for the changes in this pull request.

@savetheclocktower
Copy link
Contributor Author

Done! That was easier than I envisioned.

@jasonrudolph
Copy link
Contributor

Thanks for adding these specs, @savetheclocktower. ⚡🙇

And thanks for verifying these edge cases.

// Ensure an attribute value delimited by single-quotes won't mark a
// double-quote in the value as punctuation.
expect(editor.scopeDescriptorForBufferPosition([3, 15]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.begin'
)
expect(editor.scopeDescriptorForBufferPosition([3, 16]).toString()).toBe(
'.text.html.basic .source.html .string.html'
)
expect(editor.scopeDescriptorForBufferPosition([3, 17]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.end'
)
// Ensure an attribute value delimited by double-quotes won't mark a
// single-quote in the value as punctuation.
expect(editor.scopeDescriptorForBufferPosition([3, 27]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.begin'
)
expect(editor.scopeDescriptorForBufferPosition([3, 32]).toString()).toBe(
'.text.html.basic .source.html .string.html'
)
expect(editor.scopeDescriptorForBufferPosition([3, 66]).toString()).toBe(
'.text.html.basic .source.html .punctuation.definition.string.end'
)

😍

@jasonrudolph jasonrudolph merged commit c41dd49 into atom:master Aug 9, 2019
jasonrudolph added a commit that referenced this pull request Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tag and string punctuation is not targetable in the tree-sitter grammar

3 participants