Skip to content

Scope function call differently from function definition #443

Closed

Description

TS and JS Grammar Extension version: 0.0.18 / latest

This issue is likely Sublime Text specific, which relies on scoping to provide simple navigation in all languages:

  • Go to symbol: by listing all symbols with scopes like entity.name.function.ts
  • Go to definition: by finding a matching entity.name.function.ts for a variable.function.ts.

Because the TypeScript grammar labels function calls as entity.name.function.ts, the symbol list is polluted with invocations and Go To Definition does not know which entry to navigate to.

If no regressions are caused in themes / other editors, it would be great if Sublime's guidelines could be used: (from https://www.sublimetext.com/docs/3/scope_naming.html#variable)

Function and method names should be scoped using the following, but only when they are being invoked. When defined, they should use entity.name.function.

  • variable.function

Code

function myFunc() {
}

myFunc();
myFunc();
myFunc();

Results

Go to definition hover:
screen shot 2017-04-07 at 21 37 07
Go to symbol: screen shot 2017-04-07 at 21 37 26

I was able to fix the symptoms by changing to "variable.function.ts" in the function-call matcher at https://github.com/Microsoft/TypeScript-TmLanguage/blob/master/TypeScript.tmLanguage#L3791

The syntax did use variable.function before, but it was changed in 55c8c9e , perhaps in response to #72.

Activity

  1. sheetalkamat commented on Apr 21, 2017

    @sheetalkamat
    Member

    Function calls now have 'meta.function-call' scope by f2cdd8b and that should help with the themes. Unless there is absolute need I don't think we can change the scope to variable.function as that doesn't seem to be common use (eg. look at the grammar at atom/language-javascript )

  2. tomv564 commented on Apr 24, 2017

    @tomv564
    Author

    Thanks for responding - is there a plan to eventually remove entity.name.function.ts where meta.function-call was added?
    As this is not a theming issue, there is no other workaround (short of maintaining a fork of this syntax) for ST3 users.

  3. sheetalkamat commented on Apr 24, 2017

    @sheetalkamat
    Member

    As such there is no plan to replace entity.name.function with variable.function (in function usage scenarios). I am adding Matt Bierner (@mjbvz) and Martin Aeschlimann (@aeschli) to see what they think as they would need to make changes to vscode themes if we decide to change this.

  4. tomv564 commented on Apr 24, 2017

    @tomv564
    Author

    Forgot to add that switching to variable.function is not really important, meta.function-call is fine (also commonly used in the ST3 syntaxes).

    Several other of the VS Code syntaxes (go, python, ruby) only apply entity.name.function to function definitions, but several others (rust, c#) apply to invocations as well.

  5. aeschli commented on Apr 25, 2017

    @aeschli

    I think using entity.name.function only for function declarations is the right thing to do, but none of the grammars in our repo uses variable.function. I know that the Sublime doc lobbies for it but my guess it will result in a lot of functions colored as variables. IMO most common is support.function even I understand that this is not 100% correct. meta.function-call is also used and I wouldn't object to support it.

  6. mikelward commented on Jun 18, 2018

    @mikelward

    Sheetal Nandi (@sheetalkamat) It doesn't help, because of vscode-textmate issue 52, which means you can't style entity.name.function - meta.function-call differently from entity.name.function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions