-
Notifications
You must be signed in to change notification settings - Fork 589
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] Definitions and References #1861
Comments
I missed this when it was added. I have three concerns. The first is that in (say) JavaScript, not all functions (scoped with The second is that we can't rely on the scope at time of reference. For example: function f() {}
// ^ entity.name.function
console.log(f);
// ^ variable.other The third is that I'm not sure how we would use this to implement GOTO features. If the appropriate meta scopes were all present, then we could implement a fairly reliable GOTO system in Python, but it's not trivial. I've done this for JavaScript, and it requires a fair bit of language-specific code. We could define a new kind of JSON-based specification format and write an engine that consumes it, but I'm not sure that this is within the scope of the proposal. |
This issue was not raised with the goal to force everybody to scope the most obvious impossible declaration-reference pairs as illustrated in the previous post. It was rather created with the question in mind: "If a syntax allows us to scope definitions and references, how to name those in order to make use of the goto feature?" It is obvious that this question can't be answered for all syntaxes the same way we know ST's syntax engine can't handle all syntaxes on earth with 100% accuracy. |
This is probably not the right place to ask, but I'll do it anyway. What about variable declarations and variable references? I would like to have goto references know when a function has been used as a variable. i.e. specifying a callback. So adding I'm thinking of the following example: char buffer[1024];
// ^ entity.name.variable
void my_callback(void *data) { ... }
// ^ meta.function entity.name.function
struct driver my_driver = {
.data = buffer,
// ^ variable.other
.callback = &my_callback
// ^ variable.other
}; |
This is the correct place to ask and this is basically the scope of the issue. Your question is partly discussed in #1842. Was not able to follow any detail though. Explicit variable declarations as in C/C++ might be matched as |
Motivation
The primary motivation of this RFC is to define a common guideline of how syntax definitions should scope entities in order to work well with Sublime Text's Goto Definition and Goto Reference features using a minimal set of rules and to provide a starting point to extend the feature syntax specifically.
Sublime Text's Goto Definition and Goto Reference requires scoping tokens of definitions or declarations and pairing them with those looking like a reference of the entity.
Pairing works by adding those tokens to Sublime Text's index database.
The following code blocks show the most basic pair, which is defined by Sublime Text out of the box.
Definitions
References
Note: The disussion was initiated at #1841 (comment)
Issues
The function identifier can be one of the following atomic or complex expresions:
variable.function
support.function
constant.other.macro
support.constant.macro
...
Examples with macros
C
Erlang
The
FUNC_NAME
is defined in line 1. Its reference is used as identifier in the function definition.The
FUNC_NAME
in line 5 is now both - a reference of a previously defined macro and the identifier of the function definition.The
FUNC_NAME
is also used as identifier in the function call in the last line.Note: Macros and ordinary identifiers may not be distinguished in syntaxes like C/C++ for sure, while they can in others like Erlang.
Questions
FUNC_NAME
in the function definition?constant.other.macro
entity.name.function
entity.name.function.macro
entity.name.function constant.other.macro
FUNC_NAME
in the function call?constant.other.macro
variable.function
variable.function.macro
variable.function constant.other.macro
Answer
[entity|variable].function.macro
from the list of candidates.constant.other.macro
only is not a proper candidate as it might be used in the function body with different meaning.Proposal
This PFC proposes to use (existing) meta scopes to solve the issue and introduce detailed subscopes for the different parts of a complex definition/reference statement based on #884
Note: Even though this proposal uses the function definition and function call as an example, it may be applied to any kind of definition/reference expression.
Simple definitions and references
Simple definitions and references, which are uniquely identified by one word, don't need extra meta scoping.
entity.name.<definition-type>
variable.other.<definition-type>
entity.name.<definition-type>
constant.other.<definition-type>
Example
A custom object definition could use
entity.name.object
while its references are scopedvariable.other.object
.Complex definitions and references
If a syntax supports sophisticated names or expressions to be used as identifier in a (function-) definition the whole definition statement should ...
meta.<definition-type>
scope,entity.name.<definition-type>
for the identifier,meta.<definition-type>.name
to wrap complex identifier expressions.If a syntax supports sophisticated names or expressions to be used as identifier in a (function-) reference the whole reference statement should ...
meta.<definition-type>-call
scope,variable.other.<definition-type>
orconstant.other.<definition-type>
for the identifier,meta.<definition-type>-call.name
to wrap complex identifier expressions.Notes:
An
entity.
which is used as identifier in a definition should not be used to scope the reference of the same object. In short:entity
is dedicated to definitions.Scopes being directly used for highlighting should not be stacked together in order to create specialized tokens. Don't use
variable.function constant.other
or something like that.Example
Benefit
All sorts of definitions or references - even if they use macros as identifier - can be added to the index or be addressed by color schemes.
function definition:
meta.function.name & (entity.name.function | constant.other.macro)
function call:
meta.function-call.name & (variable.function | support.function | support.constant.macro | constant.other.macro)
The text was updated successfully, but these errors were encountered: