Skip to content
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

Tree-sitter rolling fixes (February) #906

Merged

Conversation

savetheclocktower
Copy link
Sponsor Contributor

Fresh off the merging of #859! This one will also land before the 1.114 release.

@DeeDeeG
Copy link
Member

DeeDeeG commented Feb 1, 2024

Just popping in to suggest we might shoot for two of these PRs per month? May mess with your PR titles if we do that, maybe Feb part 1, Feb Part 2? I dunno. In any case, I am thankful for this continued work.

@savetheclocktower
Copy link
Sponsor Contributor Author

savetheclocktower commented Feb 1, 2024

Yeah, I'll just have to start naming them differently. (I created this branch on January 31, so I'm already cheating.)

DeeDeeG

This comment was marked as outdated.

…and add some `punctuation` scopes for the generic type delimiters.
This code snippet sets up logging so that a worker process can call `console.log` and its siblings and have them show up in the renderer process’s console… but it’s trying to destructure the antiquated magical `arguments` collection (which is like an array, but isn’t an array!) and the engine doesn’t seem to like it.

Logging didn’t work for me until I changed this.

This is such a tiny fix, and I don’t have the energy to shelve everything on this branch just to make a separate PR.
@DeeDeeG DeeDeeG dismissed their stale review February 3, 2024 16:35

New changes since then

Changes: 

* `#define FOO 1` and `#define FOO` will _always_ scope `FOO` as `constant.other.c`, even when `FOO` is mixed-case or lower-case.
* `#define FOO()` will _always_ scope `FOO` as `entity.name.function.preprocessor.c`, even when `FOO` is mixed-case or lower-case.
* Usages of bare identifiers in other contexts in preprocessor directives should always scope them as `constant.other.c` — unless I’m made aware of any counterexamples where that shouldn’t happen. For example: in `#if TABLE_SIZE > 200`, `TABLE_SIZE` should always be `constant.other.c`, no matter its casing.
* All-caps variable declarations and assignments (`int FOO = 0`, etc.) should scope `FOO` as `variable` rather than `constant`. We should only scope an arbitrary identifier as `constant` if we think it’s been used in the context of a macro definition.

However:

* When deciding whether something outside of a directive refers to a macro constant, we have no choice but to use the `ALL_CAPS` heuristic. Ideally we’d be able to determine that from some sort of analysis of the source code files — but even if we could keep track of that sort of thing in a single buffer, it’d fall down when macro constants _defined in other files_ are used. All we can do here is make a best guess.
…such as in multi-line self-closing tags and multi-line opening tags.

Also fix an issue in fold handling that made it impossible to use `@_IGNORE_` captures in `folds.scm`.
@savetheclocktower savetheclocktower marked this pull request as ready for review February 9, 2024 22:23
@savetheclocktower
Copy link
Sponsor Contributor Author

This one's ready for review — or will be after the inevitable spurious CI failures.

Copy link
Member

@DeeDeeG DeeDeeG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through/commenting on the off-topic stuff first.

Comment on lines +45 to +46
@syntax-color-string: #97C378;
@syntax-color-comment: #888;
Copy link
Member

@DeeDeeG DeeDeeG Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure: These are fallback variables, so this shouldn't really impact any existing themes, right? Existing themes either already provided these values themselves and were using them internally to the specific theme, or else any usages of these variable names would have resulted in LESS errors, I suppose.

So this should only add to the list of valid LESS variable names theme authors can reference in their themes? (And for users to reference in their user theme.) Doesn't seem like it would have a chance to cause any conflicts or issues.

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. There's still the matter of adding these variables to the built-in themes, and if I'd had the time for that then this change would've gone into a PR along with those changes. Failing that, I wanted to get this change in as soon as possible, which is why it's in this PR where it doesn't belong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to reference the specific commit adding them here, and this PR as well, if doing a follow-up to add it to the default themes, then, IMO.

src/task.js Outdated
Copy link
Member

@DeeDeeG DeeDeeG Feb 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am slightly tempted to ask for this to be reverted here and I could volunteer to cherry-pick it and post it as its own PR. But I would struggle to provide much of a description in such a PR body other than copy-pasting your commit message.

So, I think I'll just call this out here and acknowledge that it's included, even if it's not strictly/narrowly related to the rest of the PR changes.

For anyone out there trawling the git blame view and finding this PR: Yes, we know this is unrelated! I hope the commit message is helpful enough if this in fact caused any issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some docs, if this ends up puzzling anyone in the future looking back on this:

* A new predicate called `fold.invalidateOnChange` that can be used when a change should automatically invalidate the fold cache for each row in a node's range.
* The ability to use custom predicates in `folds.scm` files. (Previously, captures from `folds.scm` did not consult an instance of `ScopeResolver` in the processing phase.)
@savetheclocktower
Copy link
Sponsor Contributor Author

savetheclocktower commented Feb 14, 2024

Rolled back an attempted bump of tree-sitter-bash because it caused a “memory access out of bounds” exception. But only on the CI build! Not locally. I hate it.

Copy link
Member

@DeeDeeG DeeDeeG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once again, I wish I understood more deeply, but this all seems good to the extent I can understand it, and I have read up on some of the issues these changes are fixing.

(I've also read the commit messages and diff, including code comments.)

To the best of my ability, since it's better to have an underqualified but sincere attempt at a review than a pure rubber-stamp, here's my Approve. 👍 Thanks as always.

.eslintignore Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I'm personally still fine with tweaking these files until linters are okay with our current code. (Mentioning again so folks don't have to go through older PRs to find the discussion/justification for updating these.)

(For the vendor/ dir, I definitely agree with linters just ignoring that code. Because that code's from elsewhere, and we more or less don't want to be tweaking it just because a linter told us we might want to.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like the amount of comments in this, I sort of almost can follow along with this. (One of these days I need to read what I believe I heard you've written about how to write .scm files, so I know what's specifically going on in these. But I can sense the comments will come very much in handy then.)

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably because of how not-at-home I feel inside C/C++ as opposed to most of the other languages for which I've written highlights.scm files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was gonna say, at risk of being mildly off-topic or tangenty: C seems really tricky based on reading through this (plus some stuff I'm dealing with outside of Pulsar lately that's in C...)

Comment on lines -136 to +173
declarator: (identifier) @variable.declaration.c)
declarator: (identifier) @variable.other.declaration.c)
Copy link
Member

@DeeDeeG DeeDeeG Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we marking so many of these as .other, in addition to the various other CSS classes being added?

I can guess it helps make sure rules in stylesheets actually apply, by adding this class on to the rule's selector to increase its specificity as needed, without resorting to !important... Is this basically the reason, or anything else I'm missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knowing the issue this is addressing, these comments are great and very readable, IMO.

Even though I can't read .scm files that well right now, I know what purpose this is accomplishing. 👍. Thanks.

it('understands custom predicates', async () => {
const grammar = new WASMTreeSitterGrammar(atom.grammars, htmlGrammarPath, htmlConfig);

await grammar.setQueryForTest('foldsQuery', scm`
Copy link
Member

@DeeDeeG DeeDeeG Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this scm`templateStringHere` stuff call the scm() function with the template string as an argument? This syntax is a tad confusing to read, IMO. If it can use parentheses, maybe that'd be better? Just a style nitpick, I suppose. Hmm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding specs for this fold.invalidateOnChange feature!

Comment on lines -2159 to 2193
} else {
} else if (capture.name.startsWith('fold.')) {
let key = this.keyForDividedFold(capture);
boundaries = boundaries.insert(key, capture);
}
Copy link
Member

@DeeDeeG DeeDeeG Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any downside to making this basic else "fallback" block become specific/conditional? Could anything be missed if ! capture.name.startsWith('fold.') here?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No — and, in fact, the old code was breaking things. I had thought I'd made it so that you could safely use @_IGNORE_ as a capture name in any .scm file, but when I tried it in folds.scm, I discovered that I'd written this in such a way (almost a year ago) that only three different kinds of capture names were envisioned in a folds.scm. So the @_IGNORE_ was being treated like a divided fold (@fold.start or @fold.end) when it clearly isn't.

In general, if a query file doesn't assign a special meaning to a certain capture name, it should be silently ignored.

Comment on lines +3832 to +3837
for (let range of foldRangeList) {
// The fold cache is automatically cleared for any range that needs
// re-highlighting. But sometimes we need to go further and invalidate
// rows that don't even need highlighting changes.
this.languageMode.emitFoldUpdate(range);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any insights on this? I'm curious about why this is needed, but I'm not sure I have context to get it, to be honest. Optional but appreciated if you can give a go at explaining this further.

Copy link
Sponsor Contributor Author

@savetheclocktower savetheclocktower Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, whenever syntax highlighting changes, that's a good indicator that we should re-investigate whether the affected lines have changed from foldable to not-foldable (or vice versa). That's why emitRangeUpdate (the method that signals the display layer for re-highlighting) actually calls emitFoldUpdate on the same ranges.

But sometimes (rarely!) a row's foldability might be affected by a change that would not (should not) result in re-highlighting. The case I added a test for was the one very specific place that I needed this.

(There's a similar feature — the highlight.invalidateOnChange predicate — that scratches this same itch on the highlighting side. And I've only ever needed it once: when a /* comment chanes into a JavaDoc-style /** comment and several lines need to be re-highlighted at once.)

Comment on lines +3872 to 3875
// Checks whether a given {Point} lies within one of this layer's content
// ranges — not just its extent. The optional `exclusive` flag will return
// `false` if the point lies on a boundary of a content range.
containsPoint(point, exclusive = false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay more code comments 👍 !

@savetheclocktower
Copy link
Sponsor Contributor Author

I'm a big fan of your willingness to wade into these PRs and ask questions about them. I should be at least as gracious for your devops-related PRs, so that'll be a resolution of mine for the coming month. Thanks!

@savetheclocktower savetheclocktower merged commit ec12b2f into pulsar-edit:master Feb 15, 2024
104 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants