Commit Graph

9210 Commits

Author SHA1 Message Date
confused_techie
cf7040e297
Merge pull request #959 from pulsar-edit/refactor-style-manager
[core] Simplify/Cleanup `StyleManager`
2024-04-15 16:46:56 -07:00
Andrew Dupont
8145f06c5b Make TreeSitterLanguageMode::commentStringsForPosition
…_minimally_ support the new contract.

Some of the edge cases here aren't fixed, but this is good enough for a type of grammar whose days are numbered anyway.
2024-04-07 21:41:48 -07:00
Andrew Dupont
769b86ed38 Rename method to getCommentDelimitersForBufferPosition
…as much as it pains me to do so.
2024-04-06 16:38:03 -07:00
Andrew Dupont
035595d1c2 Add TextEditor specs for new getCommentDelimitersForPosition 2024-04-06 16:36:13 -07:00
Andrew Dupont
0e41a3de8a Add specs for comment delimiters 2024-04-06 16:11:39 -07:00
confused-Techie
8dd3ca738f Ensure we can call upgradeStyleSheet without access to StyleManager local functions 2024-03-18 16:20:50 -07:00
Andrew Dupont
df6349af83 Update workspace spec…
…to reflect new behavior of `GrammarRegistry#getGrammars`.
2024-03-02 21:23:44 -08:00
Andrew Dupont
6c54813c21 Add spec for scope-specific core.useLegacyTreeSitter setting 2024-03-02 17:37:04 -08:00
Andrew Dupont
89d410baef Small fixes 2024-03-02 17:13:57 -08:00
Andrew Dupont
8b0f62b7a0 Prefer synchronous indentation by default in modern Tree-sitter…
…but only while we can afford to spend time on re-parsing.

Synchronous indentation hinting is clearly the best choice, but it can theoretically be very costly. So we'll set a time budget per transaction — currently 10ms, but could be adjusted up or down. We'll start out doing synchronous indentation, but flip to async indentation if we run out of time in a given transaction. At the end of a transaction, the time budget resets.

This allows us to balance indentation accuracy with editor responsiveness, and would even allow us to expose this tradeoff as a setting in the future. The current threshold, 10ms, would probably result in one dropped frame if exceeded, but not two.

Right now, any one parse can exceed the budget — because we don't set a timeout on the parse the way we do with an async parse. But this could be changed in the future. The main goal here is to prevent a catastrophic scenario where a complex transaction locks up the editor.
2024-03-02 16:27:29 -08:00
Andrew Dupont
afe6e1e7bf Be more aggressive in determining suggested indent positions…
…at ends of transactions — instead of falling back to a transaction-wide auto-indent quite so easily.
2024-03-02 13:45:57 -08:00
Andrew Dupont
0df4e7528a Simplify the test case and add an explanation 2024-02-16 09:01:35 -08:00
Andrew Dupont
9b1e8e5513 Add features to folds:
* 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.)
2024-02-10 14:36:32 -08:00
Andrew Dupont
11ebeeab61 Prefer a more graceful solution 2024-01-29 22:00:58 -08:00
Andrew Dupont
14e3562330 Fix failing spec 2024-01-29 21:55:04 -08:00
DeeDeeG
4f3bc686e1
Merge branch 'master' into tree-sitter-january 2024-01-29 22:44:18 -05:00
Andrew Dupont
5855241698 Fix issue with looking up objects in atom.config
…when a project-specific config is present.

Most people don't use a project-specific config, which is why this bug has been present for ages. Read the new spec for an explanation.
2024-01-28 00:47:32 -08:00
Andrew Dupont
f691cfce28 Allow for any number of @_IGNORE_ capture names in a query…
…by namespacing them as `@_IGNORE_.foo`, `@_IGNORE_.bar`, etc.

It's sometimes necessary to define a capture in a query not because you want to apply a scope name, but because you need to use it as the argument to a predicate. `@_IGNORE_` was intended for that purpose, but it was the _only_ capture name with that special effect.

Now, you can specify any number of captures that don't apply scope names. As long as it equals `@_IGNORE_` or _starts with_ `@_IGNORE_.`, it'll have the same effect. This lets you target two or more nodes and use them all in predicates in the same query without any of them applying a scope name.
2024-01-27 23:11:41 -08:00
Andrew Dupont
46877b05ff [language-php] Add meta.embedded.block/meta.embedded.line
…to each PHP section in order to match the functionality of the TextMate grammar.

This was a gigantic endeavor and involved doing several things that were on my “ugh, I’ll get around to it” list:

* To make some of this stuff work, we were using two different PHP parser layers. The root one did the syntax highlighting and separated the HTML from the rest, and the deeper injection was there just so we could scope some ranges as `source.php`.

  That doesn’t work because of rules we have about shallower layers acting before deeper layers when iterating through syntax highlighting boundaries. I was trying to be too clever. Now the _root_ layer is the one that does no highlighting, and the _deeper_ layer is the one that exists to apply `source.php` _and then_ perform highlighting and indentation hinting and folding and whatnot.

  If we need to, we can move some of the queries to the root layer for whatever reason; maybe we come across a bug six months from now that could be fixed if we made the root layer in charge of folding. We have options.

* All boundaries for `HighlightIterator`s now _either_ open one or more scopes _or_ close one or more scopes. If one boundary can close some scopes and open others, then boundaries on different layers that share a buffer position cannot possibly close/open in the correct order because they can't intermingle. This needed to happen and this was as good of an excuse as any to do it.
* We needed to present sane PHP opening/closing ranges to the injection. Ironically, `tree-sitter-php` itself makes this nearly impossible because of how the tree is structured; it tries to hide the `<?php` and `?>` tags from the PHP layer and treat them as text, despite the fact that PHP is the thing that knows how to parse that.

  The best way to do this — at least until I encounter a reason why it can’t work — is to find all the `<?php`s and `?>`s, sort them, group them, and build fake node ranges. This is fine! I mean, it’s ridiculous, but it’s fine! The ranges that we hand off to another parser are allowed to be completely arbitrary!

  This lets us do what we were only approximating before: have _one_ PHP injection layer with _any number of_ content ranges, each of which begins with `<?php` and ends with `?>` without trying to claim any surrounding whitespace. This would be worth it even if we didn’t have to do any of this other stuff.

* Each content range of the injection needs _either_ `meta.embedded.line.php` _or_ `meta.embedded.block.php` depending on whether the range begins and ends on the same line. This is not something I was willing to regress on because it's _hard_ to distinguish between PHP and non-PHP unless your editor helps you out, and because I wasn't going to go into a bunch of themes and tell them to treat `source.php` like `meta.embedded`.

  This also meant that we needed to be able to add _multiple_ “root” scope names per content range. But we already had a mode in which the `languageScope` injection option could be a callback, so it wasn't hard to make it a callback that could take extra parameters for the buffer and range.

  This isn't a feature that I'm eager for other grammars to use, or even necessarily know about, but it was what we needed to deliver feature parity here. And none of it would have been necessary if `tree-sitter-php` made more sensible choices. (Whatever. Maybe what I want isn't possible for some strange reason.)

All existing tests pass. Tests have been written for the new `languageScope` features. Tests need to be written for PHP just like for all other language grammars, but that was on the to-do list anyway. If any of this turns out to be catastrophic, it’s easy to roll back, but tests are passing on my machine and I expect them to pass in CI.
2024-01-20 20:49:17 -08:00
Andrew Dupont
2a0ebacf62 An injection with no highlights query should still apply its root scope 2024-01-20 13:50:31 -08:00
Andrew Dupont
c01099323f (forgot to change this spec) 2024-01-19 20:45:48 -08:00
Andrew Dupont
1ed84b8180 Adjust fold in response to tree-sitter-javascript change 2024-01-18 13:53:23 -08:00
Andrew Dupont
4a8df88ca5 Fix other grammar paths 2024-01-18 13:53:23 -08:00
Andrew Dupont
13c5c07412 Change references to JS grammar path in specs 2024-01-18 13:53:23 -08:00
Clayton Carter
ae03e1e9ba fix(tree-sitter): pass node text to grammar
This fixes a subtle breaking change in the WASM tree-sitter modes that
affected the semanticolor package. (And probably only that package.)

Although the node text is unused in `idForScope` in the core editor, the
legacy tree-sitter mode was specifically modified to pass the node text
into `idForScope` so that the semanticolor package could make use of it
to give custom scopes (and thus colors) to different symbols. (On
activation, semanticolor monkey patches that method in relevant
grammars.)

This alone is not enough to get sematicolor working with Pulsar's new
WASM tree-sitter modes, but it's one piece of the puzzle.

Ref: 97b905a2b0
Ref: https://github.com/atom/atom/pull/20212
Ref: 1bf7fc4025/src/tree-sitter-language-mode.js (L1321-L1324)
Ref: d219ef9a1f/lib/semanticolor-grammar.js (L44-L65)
2024-01-16 07:42:16 -05:00
Andrew Dupont
254440e6bc Oops 2024-01-11 15:07:11 -08:00
Andrew Dupont
4c6b0ba7d0 Ensure indentation decisions consult the correct layers…
…when straddling injection boundaries.
2024-01-11 15:07:11 -08:00
Andrew Dupont
a40bae4b88 Allow (#set! capture.final) as shorthand…
…instead of making grammars specify `(#set! capture.final true)`.
2024-01-11 15:07:08 -08:00
Andrew Dupont
58f76a8378 Address feedback 2024-01-10 20:47:51 -08:00
Andrew Dupont
413eeeaa5b Fix memory access error on autocomplete-html specs 2024-01-07 15:35:08 -08:00
Andrew Dupont
206a15a7b1 Get more TextEditor specs passing 2024-01-07 15:35:08 -08:00
Andrew Dupont
c7cde85856 Get Workspace specs passing 2024-01-07 15:35:08 -08:00
Andrew Dupont
11e5a6176f Get TextEditorRegistry specs passing 2024-01-07 15:35:07 -08:00
Andrew Dupont
3c4493b895 Get PackageManager specs passing 2024-01-07 15:35:07 -08:00
Andrew Dupont
98c80eb245 Get GrammarRegistry specs passing 2024-01-07 15:35:07 -08:00
Andrew Dupont
9884445241 Get WASMTreeSitterLanguageMode specs passing 2024-01-07 15:35:07 -08:00
Andrew Dupont
1bf7fc4025 Get TextEditor specs passing 2024-01-07 15:35:07 -08:00
Andrew Dupont
76ac2cf81c Make useExperimentalModernTreeSitter the default…
…and create `useLegacyTreeSitter` for those who want to opt into the previous default behavior.

(Legacy Tree-sitter grammars will soon be removed, but this is a step toward that future!)
2024-01-07 15:35:07 -08:00
Andrew Dupont
09db9e060b Fix behavior of new ScopeResolver config caching in specs 2023-12-15 21:20:04 -08:00
Andrew Dupont
7bc3ff7280 [tree-sitter] Share config caches between ScopeResolvers 2023-12-15 17:08:52 -08:00
confused-Techie
d7f7fede7a Add missing path delimiter 2023-11-08 19:55:11 -08:00
confused-Techie
339f228dd8 Match path translations 2023-11-06 22:23:10 -08:00
confused-Techie
46c0b3a6c0 Add newlines to expected specs 2023-11-06 21:50:19 -08:00
confused-Techie
3378746454 Move Atom link transformations out, fix tests 2023-11-06 21:28:48 -08:00
confused_techie
fb006f65c1 Add some minor specs 2023-11-06 10:50:28 -08:00
confused-Techie
4c590f07e7 Remove accidentally included test file 2023-10-18 12:01:40 -07:00
confused-Techie
e7c14be227 Migrate notifications to new API 2023-10-18 12:00:23 -07:00
Andrew Dupont
69038a1c4c
Merge pull request #677 from savetheclocktower/tree-sitter-more-fixes
Tree-sitter running fixes (August edition)
2023-09-13 15:14:27 -07:00
Andrew Dupont
e9903ad9d6 Change behavior of “adjustment exceeds bounds” error
Previously, we threw an error when a scope adjustment violated its bounds constraints, but that's a bit disruptive for everyday use. Instead, we throw an error in dev mode (so that the grammar's author doesn't fail to notice the problem), but downgrade it to a warning outside of dev mode so that it's recoverable.

There's a chance that the warning will be _too_ subtle, but we'll give it a shot.

We also include more diagnostic information so that it's clearer exactly _where_ the violation is happening.
2023-09-11 15:14:19 -07:00
confused_techie
24ab36323c
Merge pull request #668 from pulsar-edit/mothball-current-auto-update-logic
Remove AutoUpdate functionality from Core
2023-08-24 16:45:20 -07:00