nishtahir / language-kotlin

Textmate language grammar for the Kotlin programming language
Apache License 2.0
12 stars 6 forks source link

Annotations with qualifier and braces are not handled. #42

Open Animeshz opened 3 years ago

Animeshz commented 3 years ago

Looking at the sources,

https://github.com/nishtahir/language-kotlin/blob/e968288236401d322c8d16a96540bc0dc141f920/src/annotations.YAML-tmLanguage#L6

https://github.com/nishtahir/language-kotlin/blob/e968288236401d322c8d16a96540bc0dc141f920/src/annotations.YAML-tmLanguage#L9

https://github.com/nishtahir/language-kotlin/blob/e968288236401d322c8d16a96540bc0dc141f920/src/annotations.YAML-tmLanguage#L25

Neither of them seem to handle annotations used such as:

@set:Option(option = "verbose", description = "Sets verbosity of output.")

i.e. ones which are prefixed with the qualifier (@qualifier:).

Animeshz commented 3 years ago

Also I guess its better to use the storage.type.annotation.kotlin according to the docs, and also used for the Java.

It also has predefined highlighting available from the github's primer defined scopes.

nishtahir commented 3 years ago

I'm not sure I agree that storage.type is the right scope for this. According to the docs that you linked they describe storage type as

type — the type of something, class, function, int, var, etc.

The Kotlin docs describe annotations as

Annotations are means of attaching metadata to code. To declare an annotation, put the annotation modifier in front of a class:

Which seems to fit the description of the meta scope in my view

meta — the meta scope is generally used to markup larger parts of the document. For example the entire line which declares a function would be meta.function and the subsets would be storage.type, entity.name.function, variable.parameter etc. and only the latter would be styled. Sometimes the meta part of the scope will be used only to limit the more general element that is styled, most of the time meta scopes are however used in scope selectors for activation of bundle items. For example in Objective-C there is a meta scope for the interface declaration of a class and the implementation, allowing the same tab-triggers to expand differently, depending on context.

In my opinion the keyword annotation is a storage type whereas annotations themselves should be meta

Animeshz commented 3 years ago

O.O The VSCode java uses something like this and that.

It gives the whole annotation scope of meta: "name": "meta.declaration.annotation.java", whereas the @ symbol and the name of annotation, punctuation and storage respectively:

"beginCaptures": {
    "2": {
        "name": "punctuation.definition.annotation.java"
        },
        "3": {
            "name": "storage.type.annotation.java"
        },

Similar one for scss @media queries or @mixins 👀.

Animeshz commented 3 years ago

Also dart-grammar applies storage scope it for whole the annotation 🤔.