-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] More specific subscopes (e.g. meta.function.name) #884
Comments
I would welcome those parts as standards and already define I also define a |
That could be useful. I'd lean toward keeping attributes and access separate, because several common languages have both and use different syntax for them. Python is an exception, because many features that most languages implement as special syntax are instead implemented instead as decorators. Another concern is that in many languages that use function decorators it may not be generally possible to know ahead of time that they are part of a function declaration, because the decorators are conventionally followed by newlines. For example, in both Python and JavaScript (proposed), a decorator could precede either a function or a class, and there's no way to know which. C# attributes are even more permissive. Are there common languages that do not suffer this difficulty? I saw your mention of G-code, but I'm not familiar with it. |
Decorators and things like that are already discussed in #737. The results are already used by recently updated syntax files like Scala. So normal function scopes don't need to take this into account anymore. The meta sub-scopes you propose are very fine, but I just missed that general Yes I thought about
where They just don't match any of your proposed scopes and thus the idea raised to use Take a look on the
with Following this rule, we would need to define a minimum required
|
Are there other languages that would use the |
Not sure, maybe most other languages most commonly use the |
We've standardized that decorators, attributes and annotations will use the scopes in #709. |
@wbond: The point is, that #709 is all about Consider the void private func()
^^^ meta.function.return-type
^^^^^^^ meta.annotation.variable
^^^^ meta.function.name
^^ meta.function.parameters I think everything within the function definition line should start with |
@deathaxe Well, In terms of annotations the If you check out the existing C# syntax and tests, you'll see we have annotation before methods and in the middle of parameters. There is no harm in having Does that make sense? |
Yes this makes sense, if annotations aren't handled as part of functions at all. I maybe was misled, but have a look on python's implementation of def start_timer(delay: int) -> None:
# ^^^ meta.function.parameters.annotation
# ^^^^^ meta.function.annotation.return.python A look into the latest C# syntax makes the usage of annotations completely clear to me, but I found something I dislike with the Current situation: class YourMainClass
{
public void Run([Usage("help text")] int x, int y);
// ^^^ meta.method
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.method.parameters
} At least class YourMainClass
{
public void Run([Usage("help text")] int x, int y);
//^^^^^^^^^^^^^^^ meta.method
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.method.parameters
} When following post 1 with class YourMainClass
{
public void Run([Usage("help text")] int x, int y);
//^^^^^^^ meta.method.modifier.access
// ^^^^ meta.method.return-type
// ^^^^ meta.method.name
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.method.parameters
} The usage of Can it be considered standardized to use |
The reason it doesn't start at the beginning of the line is because the language is ambiguous until an identifier followed by a When it comes down to it, properly lexing C-like languages is a real pain, and will never be 100% because of:
|
In terms of Python, yes we may want to revisit that. I believe that was written before we standardized on scopes. I haven't looked into it enough to see if the annotations scopes are applicable there, or if they should be scoped as something else. |
Thanks for clarification.
This is the drawback of the possibility of context sensitive lexing. The rules basically need to imitate the behavior of the compiler/interpreter to correctly handle all the grammar required especially for meta scopes. The meta scoping shouldn't waste too much efforts as meta's are not primarily seen by user but "only" may support package devs to provide proper auto-completions and such things. Means it's not a big deal not to start meta.function at the first keyword. :-) |
I think that if |
I second @Thom1729's concern. Java, for example and as far as I'm aware, doesn't even have "functions" at all, since it only allows "function" definitions inside classes and these are then called "static methods". Alas, methods are just functions that operate on a specific object that is passed to the function in one way ore another, so imo the notion of a "method" does not provide any meaningful information over "function" (for scope names). In Pascal, you also have "procedures" that are just functions without a return value (which makes sense semantically, but in the real world the term "function" has just established itself as the standard name). Regarding Python function annotation scopes: Those most likely still need to be revised. I've only looked into decorators. |
As the goal is to find common scope names which can be reused by all syntaxes I vote for using So everything like |
I agree 100% with this. The line between functions and methods is blurry anyway. |
From the scope naming guidelines:
This is an excellent system, and I think that it can be extended gracefully to cover other parts of a function. The goal would be to provide standard subscope names so that syntaxes that exceed the minimum specificity requirements are compatible with each other.
An important point raised by wbond is that "the more specific it gets, the more difficult to standardize due to language semantics and differences." Any additions should be conservative; there's little point in standardizing a construct that only appears in a single common language. However, universality is not required; for instance, many languages will never use
meta.function.return-type
, but enough do that it is well worth having a standard for it.The following sorts of constructs seem like good candidates for a standardized subscope:
meta.function.name
. In many languages, this may always be marked withentity.name.function
, which would seem to make this scope redundant. But this is not always true. Take JavaScript:Or SQL:
meta.function.body
. In some languages, such as C, this is delimited by punctuation like braces. In other languages, such as Python, it is not delimited by punctuation at all. In yet other languages, such as JavaScript, it varies:meta.function.access
. In many languages, this may be more than one word, such as C#:meta.function.type-parameters
. Many languages explicitly list type or template parameters, such as Java:Other subscopes are conceivable, but I think that these four (along with
meta.function.parameters
andmeta.function.return-type
) cover the pertinent parts of function declarations and expressions while still being general enough to be used in a wide variety of common languages. In particular,meta.function.name
andmeta.function.body
could pertain to every language that has functions.Standardizing these scopes would not (and should not) force all syntax authors to use them, but it would help authors who want to provide a full-featured syntax (or who rely on more specific scopes for features like autocompletion) to create syntaxes that are consistent and interoperable. If these scopes did see wide adoption, then they would be useful hooks for color scheme authors and even (perhaps) for simplistic code-analysis tools.
For the above reasons, I would like to discuss adding additional subscopes such as the ones suggested here to the official scope naming guidelines. I'd be interested in feedback both for the idea of subscopes in general and for the scopes suggested above.
The text was updated successfully, but these errors were encountered: