Sublime Forum

Syntax Scopes Q: `meta.path` and `meta.generic`

#1

I have a couple of question about Syntax scoping, where I couldn’t understand clearly the documentation.

meta.path

The documentation says:

Complete identifiers, including namespace names, should use the following scope. Such identifiers are the fully-qualified forms of variable, function and class names. For example, in C++ a path may look like myns::myclass, whereas in PHP it would appears such as \MyNS\MyClass.

It’s not clear to me if that “including namespace names” means:

  • identifiers which might have namespace name, or
  • only applies to identifiers which have namespace name.

meta.generic

Documentation:

Generic data type constructs should use the following scope. […]

  • meta.generic

Looking at the shipped syntaxes source and test files, I’ve only come across meta.generic-name. Has this scope changed or are they two different scopes?

Could anyone provide an illustrative example of this scope, please?

0 Likes

#2

I take it to mean this one

different, I believe, see

0 Likes

#3

Hm, I thought of meta.path to mean this:

0 Likes

#4

What I fail to understand is how these scopes are going to affect indexing and autocompletions.

In a syntax I’m working on, I’ve followed all the scoping rules as close as I could — i.e. scope classes, instances, etc., following the guidelines of the Documentation — but then I didn’t see any gain in terms of autocompletions.
Although I’ve added to the indexing all type of identifiers, it doesn’t seem like ST provides autocompletions as I would expects.

For example, in instances I would declaration I’d expect ST to autocomplete the class part using the indexed class-tokens, but this is not happening.

The documentation doesn’t really explain the purpose of these scopes beyond being able to control syntax highlighting via custom themes. While syntax coloring is a nice feature, being able to control autocompletions is more important.

In the Documentation we find all these (rather vague and abstact) guidelines on how every syntax element should be semantically scoped, but reveals nothing on how these are used beside syntax coloring. Also, these guidelines are not easy to apply to many languages outside the mainstream (yet, non mainstream syntaxes are more likely to need a new syntax definition in the first place).

I wish these docs would provide some hints on how to deal with unusual syntaxes which might require adopting different scopes. Which of these scopes are really important to make the most of ST? Which are, on the other hand, only important for syntax highlighting themes?

As I started to work on my own custom ST syntaxes, to be able to use ST to edit other languages which come with old school IDEs, my original enthusiasm for ST has diminished. It’s been some years now that I have purchased my ST license, and have been using it every day for work, but in these years its documentation hasn’t grown much — it’s still a few pages in total.

In the last six monthes I’ve began to seriously look into other editors similar to ST, like Atom and VSCode. Although I’m quite aware that no Electron/JS based editor is ever going to be as perfomant as ST (which I can tell is a very well code-optimized product), I nevertheless started to consider that lack of documentation constitutes a huge barrier in terms of being able to customize the editor.

Ultimately, I might be willing to trade off performance in exchange of good documentaion and accessibility to the source.

At least with an open source editor you can always peek at the source to understand how it handles scopes in terms of indexing and autocompletions, and you are never really faced with a Black-Box design. With ST, on the other hand, you can only hope that the documentation will be updated (indeed, written) one day; but I’m starting to doubt that this will ever happen as the documentation has been rather stale for a while.

The documentation page even links to the unofficial documentation as a reference (which is great project, although for ST2, not 3). The fact that the only true source of knowledge is an unofficial documentation makes me think that documentation hasn’t been a top priority and, most likely, it will never be.

The natively shipped syntaxes aren’t really much of an inspiration either, as they barely contain any useful comments.

At the end of the day, I was hoping that ST would empower me to create my own packages to work with any exotic syntax I needed. What really annoys me is being put in a position of having to continually ask on the forums for hints on how to procede, while if I were provided some decent documentation and examples I’d be able to take my time and learn what is needed — which, by the way, tends to lessen the sensation of being a total idiot, for you can prove that provided some decent documentation you’re able to make your way through it.

@kingkeith and @FichteFoll, have you any advise to give me in this regard? I’ve seen that you are quite prolific in developing packages and, if I’m not mistaken, at least one of you is actively enganged with the ST team.

I’m a missing out something? All the resources I could find for developing packages are mostly fragmented over the forums or some Issues in one of ST repos, which makes it rather difficult to sift through what is old-dated and what is up to date with the current version.

I see that I’m not alone in this kind of frustration, as basic questions on syntaxes how-tos are daily on the fourm (which makes me think that if more time was invested in the documentation, on the long run it would turn out a time-saver in terms of replying to similar posts). And I’ve seen quite a few of my collaborators move on to VSCode for these very same reasons.

0 Likes

#5

ST core doesn’t do anything special with meta.path scopes etc. The built in autocompletions are just suggestions from the buffer, there are no scope checks taking place. There have been requests to be able to prevent some text from being extracted from the buffer as completions for certain scopes etc., but afaik, if you want special completions in certain scopes, it currently has to be provided by a plugin on_query_completions handler or in .sublime-completions files etc.

To have such a thing in core could be annoying because it may suggest the wrong types of symbol in situations where they are not relevant etc.

But, a few other people have asked for a way to get symbols to be suggested as completions, so it’s a fairly common request:




3 Likes

#6

Thanks @kingkeith, your explanation and the links you provided are helping me better understand this issue.

I’ve managed to create successfully autocompletion settings files, for the suggestion of native keywords according to scope.

Maybe, since this feature has been asked for by others too, the syntax definition could introduce a new special scope which tells ST that the captured text in that scope should end up in autocompletions.

Something like:

- match: '\w+'                    # Some regex
  scope: entity.name.class.mylang # The usual semantic scope
         autocompletion.class     # The autocompletion scope for the matched token

… a very rough example, but the idea is that an new root scope like autocompletion could be introduced to tell ST that the matched token should end up for autocompletion in the scope that follows.

I’m not sure how this could integrate with the current way ST handles the index and the buffer, but surely it would allow fine grain control on autocompletion directly in the syntax definition. At least, this is how I would imagine the feature to fulfill my current needs, by controllling it directly in the syntax definition, instead of external settings files (which are fine when it comes to the language’s built-in functions, keywords, etc.)

0 Likes