Commit Graph

69 Commits

Author SHA1 Message Date
Andrew Dupont
b5f66353f4 [language-c] Highlight “and”/“or”/“not” in C++ 2024-07-07 11:34:35 -05:00
Andrew Dupont
0070e88d83 [language-c] Highlight auto 2024-07-06 19:31:27 -05:00
Andrew Dupont
b9ee65f6a3 Add extensive comment delimiter metadata to most built-in grammars 2024-04-06 13:00:55 -07:00
Andrew Dupont
a294c88a47 [language-c] C/C++ highlighting fixes…
* GOTO labels
* Members like `foo.bar`
* Marking of constants in C++
2024-03-17 20:49:17 -07:00
Andrew Dupont
78deb79146 [language-c] Fix issue where the wrong node gets injected into…
…in a macro definition.
2024-03-09 10:14:39 -08:00
Andrew Dupont
e332953260 [language-c] Add missing anchor to constant pattern 2024-02-04 13:36:17 -08:00
Andrew Dupont
cb7d4aad6c [language-c] C/C++ highlighting fixes…
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.
2024-02-03 23:39:12 -08:00
Andrew Dupont
995196a138 [language-c] Support declarations of pointers-of-pointers 2024-01-22 17:43:25 -08:00
Andrew Dupont
aeeb03a824 Adopt the support.storage compromise found in legacy Tree-sitter…
…in which all _value types_ are scoped under `support.storage`. The goal is to avoid drawing an arbitrary distinction between, say, `int` and `SomeCustomCType` — those things are different, but not _so_ different that they belong in separate root scope namespaces.

`storage.type` can be used for core language constructs — `var`, `class`, `function`, `struct`, `enum`, `namespace`, and so on. `support.storage.type` should be used for any _recognized_ value type — certainly core language types like `int`, but also other things if they make sense. `support.other.storage.type` can be used for user-defined types, or any other types that we don't recognize. (Using the `support.other` ordering here adheres to our new convention of reserving all of `support.other` for user-defined things.)

The point of this compromise is that both the `syntax--storage` and `syntax--support` class names are present so that many themes will still highlight these tokens as though they were in the root `storage` namespace.

This commit changes the C/C++ and TypeScript `highlights.scm` files. The results appear to be satisfactory to my eye after testing on two of the builtin themes.

I’ve updated the taxonomy document to reflect this new proposal:
https://gist.github.com/savetheclocktower/c9607b97477d4817911e4f2f8db89679#file-scope-taxonomy-md
2024-01-21 10:33:01 -08:00
Andrew Dupont
4d8a7219c3 [language-c] Highlight struct designated initializers 2024-01-20 12:07:22 -08:00
Andrew Dupont
e874d51362 [language-c] Update the tree-sitter-c and tree-sitter-cpp parsers 2024-01-19 20:02:22 -08:00
Andrew Dupont
937cb15953 [language-c] Apply some fixes to C/C++ highlighting
Choosing the other side of some dilemmas I had to resolve six months ago. Highlighting between modern and legacy Tree-sitters now appears to be identical to me (with rare exception) on the One Dark theme.
2024-01-18 18:33:00 -08:00
Andrew Dupont
93ab0f7bf0 Convert all modern Tree-sitter TODO/hyperlink injections into services 2024-01-18 13:53:22 -08:00
Andrew Dupont
bbf4cb4417 Add TODO and hyperlink injections to C/C++ 2024-01-11 15:07:08 -08:00
Andrew Dupont
fdc70fc4a5 [tree-sitter] Highlight an obscure inheritance construct properly in C++ 2024-01-11 15:07:07 -08:00
Andrew Dupont
3ab0c39f24 [tree-sitter] Add firstLineRegex to C grammars 2023-12-07 11:12:15 -08:00
Andrew Dupont
193a3dc3e7 [tree-sitter] Tweak C++ highlighting of class function declarations 2023-11-03 22:01:56 -07:00
Andrew Dupont
e2acf70e43 [tree-sitter] Add highlights for C++ destructors…
…and for the `class` keyword, whose omission is a strange oversight.
2023-10-31 13:27:43 -07:00
Andrew Dupont
80126cdbc8 [tree-sitter] More C++ fixes
Built a new `tree-sitter-cpp` parser from latest master to fix a parsing error with variable assignment. Also added/tweaked scopes for some specific scenarios.
2023-10-30 14:46:51 -07:00
Andrew Dupont
f9232482d0 [tree-sitter] Add some scopes to the C++ highlights.scm 2023-10-28 10:17:40 -07:00
Andrew Dupont
0b86be410c [language-c] Change scope names on C/C++ types
On some default themes, scoping types as `storage.type` rather than `support.type` makes them the same color as lots of other things. Both the TM grammar and the legacy TS grammar scope them as `support.storage.type` — which isn't a thing — but `support.type` is a fine compromise.
2023-09-25 18:04:13 -07:00
Andrew Dupont
ebf5333022 [language-c] Scope identifiers as types when they are unambiguously so
Anything that is one of the reserved type words in C must be a type in all contexts. And any identifier that ends in `_t` is, by strong convention, a type.
2023-08-21 00:46:29 -07:00
Andrew Dupont
cd392dfbd6 Tweak some C/C++ queries 2023-08-16 11:40:51 -07:00
Andrew Dupont
d629e2c3a8 Add tags queries for lots of builtin grammars
These can probably be improved in most cases, but they should be present so that
`symbol-provider-tree-sitter` is more likely to be useful.
2023-07-29 16:23:02 -07:00
Andrew Dupont
099d5b8671
Merge pull request #652 from savetheclocktower/tree-sitter-query-refactor
[modern-tree-sitter] Overhaul Tree-sitter scope tests
2023-07-22 19:40:36 -07:00
confused_techie
3fdf991693
Merge pull request #632 from pulsar-edit/language--/manual-decaf
[language-*]: Manual Spec Decaf (Part 1)
2023-07-20 18:25:06 -07:00
Andrew Dupont
c8cbd82518 Overhaul Tree-sitter scope tests
I realized a few days ago that the `#is?` and `#is-not?` predicates — which
puzzled me upon first investigation back in February, and which I'd ignored ever
since — are exactly what I should've been using all along for scope tests.

They are counterparts to `#set!` in that they are two additional buckets in
which to store arbitrary data. And they remove the need to have both
`test.onlyIfFoo` and `test.onlyIfNotFoo`, since the presence of `test.onlyIfFoo`
in the `refutedProperties` bucket can behave opposite to the its presence in the
`assertedProperties` bucket.

This further means that a test called `test.onlyIfFoo` can be renamed
`test.foo`. The `onlyIf` was my way of making it clear through context that this
`#set!` predicate actually enforced a criterion — but that's implicit now that
it'll be using an `#is?` or `#is-not?` predicate.

I also took the opportunity to move `test.final` and `test.shy` to their own
namespace. `final` is an oddball in the sense that it sets criteria for _other_
captures as well as its own, and they're both oddballs in the sense that they
consider the effects of other captures on the same range. And I don't want to
introduce the idea that a predicate like `#is?` can have side effects.

So they stay on `#set!` and live at `capture.final` and `capture.shy`,
respectively.

To summarize, here's a before and after:

  ((string "\"" @punctuation.start)
    (#set! test.onlyIfFirst true)
    (#set! test.final true)

  ((bar) @baz
    (#set! test.onlyIfNotDescendantOfType thud))

becomes

  ((string "\"" @punctuation.start)
    (#is? test.first true)
    (#set! capture.final true)

  ((bar) @baz
    (#is-not? test.descendantOfType thud))

This PR changes all the built-in grammars. I don't know if there are any
third-party modern-Tree-sitter grammars out there except for mine, but I've
added a simple compatibility layer so that all of the old predicates should
still work for now. But I'm going to remove that code before we ship this stuff
for real.
2023-07-20 15:17:01 -07:00
Andrew Dupont
8d3b254482 Two quick fixes 2023-07-13 22:05:09 -07:00
confused-Techie
77199b4726 Apply lost tabs to c specs 2023-07-09 23:29:32 -07:00
confused-Techie
096a14517f Revert "Revert "language-c remove decaf suggestions""
This reverts commit d132564341.
2023-07-09 23:23:57 -07:00
confused-Techie
0d97bc67f0 Revert "Revert "Manual decaf language-c; Remove CoffeeScript""
This reverts commit 050f0c96c5.
2023-07-09 23:23:52 -07:00
confused-Techie
050f0c96c5 Revert "Manual decaf language-c; Remove CoffeeScript"
This reverts commit 39e59555e6.
2023-07-09 21:43:15 -07:00
confused-Techie
d132564341 Revert "language-c remove decaf suggestions"
This reverts commit b40c1e3f5e.
2023-07-09 21:43:05 -07:00
confused-Techie
b40c1e3f5e language-c remove decaf suggestions 2023-07-08 17:59:45 -07:00
confused-Techie
39e59555e6 Manual decaf language-c; Remove CoffeeScript 2023-07-08 17:58:56 -07:00
confused-Techie
a7d07ab72c Add some languages
* language-c
* language-clojure
* language-coffee-script
* language-csharp
* language-css
* language-gfm
* language-git
* language-go
2023-07-08 17:50:50 -07:00
Andrew Dupont
8dc6ec0a19 Add namespaces to all folds.scm files 2023-04-29 15:01:25 -07:00
Andrew Dupont
1c90032276 Add namespaces to custom #set! predicates
Predicates were getting pretty chaotic. With the namespace, it's now clearer
where a predicate may be defined and what its purpose is. It also helps resolve
ambiguity — e.g., both folds and highlights can have an `endAt` predicate, so
now they're disambiguated as `fold.endAt` and `adjust.endAt`, respectively.

Namespaces:

* `highlight` for highlight-specific settings (of which there is presently only
   one)
* `test` for scope tests (currently used by highlights and indents)
* `adjust` for scope adjustments (highlights)
* `indent` for indent settings
* `fold` for fold settings

Right now, only the `test` namespace will be used by more than one kind of query
file, but I could imagine that changing in the future.

For now, tests and adjustments still work without the prepended namespace, but
I imagine I'll take that out even before we ship this feature experimentally.
Much easier to make big changes like this before anyone depends on them.

This also draws a much clearer line between `#set!` predicates with special
meaning in Pulsar… and those which are being used to set arbitrary data for
later use. For instance, if you see `(#set! isOnLeftSideOfAssignment true)`, you
know it must just be arbitrary data.
2023-04-29 14:58:42 -07:00
Andrew Dupont
71d4ad1d07 Restore core.useTreeSitterParsers setting…
…along with a temporary `core.useExperimentalModernTreeSitter` setting.

If we truly planned to keep three different language modes around indefinitely,
changing `core.useTreeSitterParsers` to an enum would make sense. But we don't,
so it'd actually just be a gigantic pain in the ass to migrate one setting to
another of a different type.

When we ship modern-tree-sitter experimentally, we'll make it opt-in via the
temporary setting. When we make it the official tree-sitter implementation and
remove the legacy node-tree-sitter version, we'll remove the temporary setting
and just change the semantics around `core.useTreeSitterParsers`.

Reverting the addition of the `core.languageParser` setting is a chore, but it
prevents a _gigantic_ future headache.
2023-04-26 17:46:02 -07:00
Andrew Dupont
8671d9cbee Update highlights.scm in language-cpp 2023-04-25 17:41:41 -07:00
Andrew Dupont
2cd20067b5 Rename syntaxQuery to highlightsQuery
The `syntaxQuery` key in a grammar definition file is the only query whose name
differs from its canonical filename, and there's no reason why that should be
the case. Might as well change it now before we ship instead of going through
the pain of changing it later.
2023-04-25 11:38:53 -07:00
Andrew Dupont
5870276a6c Scope only the left side of assignments as vars…
…in C/C++.
2023-04-12 12:08:52 -07:00
Andrew Dupont
365561069f Rename all tree-sitter-2 values to modern-tree-sitter
Any file paths with `tree-sitter-2` in them can be renamed later.
2023-04-07 15:21:33 -07:00
Andrew Dupont
d9347d6c57 Clean up/harmonize scopes…
…to conform better to the documentation I just wrote at

https://gist.github.com/savetheclocktower/c9607b97477d4817911e4f2f8db89679#file-scope-taxonomy-md.
2023-03-31 00:02:30 -07:00
Andrew Dupont
e13793034a Add C and C++ grammars 2023-03-28 17:03:42 -07:00
Maurício Szabo
ebb54aaed5 Merge remote-tracking branch 'origin/master' into feature/modernize-tree-sitter 2023-02-16 17:57:01 -03:00
Steven Nguyen
c2963a383e
c++ fixes
incorporates:

https://github.com/atom/language-c/pull/252
Note that this particular change was modified. `class public virtual : public virtual Example` is invalid I think, but I don't see a good way to prevent that because the detection must be moved into `patterns > include` because textmate is not multiline regex.
See also https://github.com/jeff-hykin/better-cpp-syntax/issues/14
(In fact that whole repostory probably has some improvements)
I changed it to include the angle brackets because types can have those

https://github.com/atom/language-c/pull/263
https://github.com/atom/language-c/pull/311
https://github.com/atom/language-c/pull/368

For tree-sitter, kinda fix the Discord reported issue
(In #support M1 Mac C++ Syntax highlighting)

Note that I syntax color only the last function name and not the namespace or colon. But that could easily be changed.

For future me, the relevant tree-sitter namespace identifier scopes are:
`call_expression > qualified_identifier > identifier` and
`function_declarator > qualified_identifier > identifier`

I don't know anything about template functions so I left that untouched. So this is probably an incomplete fix.

Finally, add the `static_assert` operator. It's technically a directive so it'll appear purple, not blue. Again this could easily be changed so don't hesitate about feedback, idk anything about c++
2023-02-02 15:56:31 -06:00
Maurício Szabo
beb1701753 Changed config for tree-sitter to be grammar-based 2023-01-14 17:53:41 -03:00
confused_techie
2eab519e23
Merge pull request #209 from Sertonix/add-or-update-packages-package-lock.js
add or update `packages/*/package-lock.json`
2022-12-13 18:21:25 -08:00
confused_techie
8dac21178f
Merge pull request #190 from Daeraxa/pkg-brand-licence
Re-brand and re-licence core packages
2022-12-10 18:36:17 -08:00