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

Suggestions for scope additions/changes #649

Open
@savetheclocktower

Description

@savetheclocktower

Summary

I have suggestions for scope additions/changes for the tree-sitter grammar. If any of these are warmly received, I’ll whip up a PR.

Motivation

A bare-bones grammar is less useful. Scope names have value beyond syntax highlighting.

The suggestions

More meta. scopes

I’ve got a custom define-a-function command that behaves differently inside class bodies than it does elsewhere; with the Babel grammar I was able to use the meta.class.body scope to tell the difference.

I’d love for that (and a few other similar scopes) to be added. Without scopes it’s quite hard to get commands to do different things in different contexts.

Punctuation

All opening braces ({) — except in strings, of course — are scoped as punctuation.definition.function.body.begin.bracket.curly. This is inaccurate; lots of opening braces don’t signal the start of a function body. Closing braces are similarly scoped, as are square brackets and parentheses.

If the goal is to give all such punctuation the same scope regardless of context, I’d suggest these scopes be renamed like (e.g.) punctuation.definition.begin.brace so that the scope name doesn’t imply a context that may or may not be true. If these scopes should include information about their context so that {s can be distinguished from one another, then we need to be a bit more thorough in the grammar.

Definition vs. invocation

Both function names and class names are scoped identically between definition and usage.

class Foo extends Bar {}
let foo = new Foo();

function baz(...args) {}
baz(false);

In this code sample, both occurrences of Foo have the scope meta.class. Both occurrences of baz have the scope entity.name.function.

This is intended behavior, as I understand from @maxbrunsfeld’s comments in past issues like these. I’m not trying to change how these identifiers appear in default syntax themes. But I’d like these scopes to be distinguished somehow so that I can make them look different from one another in my own syntax theme if I so choose.

For functions, I’d suggest entity.name.function.definition in the definition case, and entity.name.function.call in the invocation case.

For classes, meta.class is a questionable choice in the first place, in my opinion; I’d suggest entity.name.class.definition and entity.name.class.instantiation. (If meta.class needs to be kept for backward-compatibility, that’s fine; I believe that it’s possible to apply two scope names to the same thing.)

Adding to the scope name shouldn’t affect their appearance in existing syntax themes.

Describe alternatives you've considered

There aren't any, short of continuing to use language-babel. Grammars are the underpinning of most of the customization I already do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions