Sublime Forum

Scope-restricted symbol definitions

#1

Right now, as far as I understand me (and please correct me if my understanding is incorrect), symbol navigation go roughly like this: you define a set of secopes, and any string in files with those scopes are registered as symbols in a single list. Then, when sublime encounter any string that matches an item in the list, it allows us to navigate to the place where the strig was captured.

So, for example, say I have a class name such as “point” and I define the medatada files such that class names are registered as symbols. Then, any occurence of “point” in my project will be considered as an usage of the symbol (even if it is e.g. in a comment). This might however be an undesired behaviour.

What I’d like would be for Sublime to allow us to define custom lists of symbols (say, function names, class names, variable names, etc.) just like now we can define the single symbol list. And associate to each list a set of scopes where items in the list can be found. That way, using a Go to definition on e.g. a function call would only search for definitions in function scope and not in class scope, etc.

1 Like

[Syntax] Entities' definition/reference not found
#2

I wouldn’t create multiple lists, but rather than just extend the goto definition api to allow the user to pass a selector.

Here is an example how goto_definition could look like.

    { "caption": "Goto: Symbol…", "command": "show_overlay", "args": {"overlay": "goto", "text": "@", "selector": "source.python entity.name.function"} },

    { "caption": "Goto: Definition…", "command": "goto_definition", "selector": "source.python entity.name.function" },

The same would be useful for python API functions.

    view.indexed_symbols(selector="source.python entity.name.function")  # returns a list of all indexed python functions

   view.lookup_symbol_in_index(sym="my_func", selector="source.python entity.name.function")

Such things would be needed for references respectively.

0 Likes

#3

this sounds very sensible, and reminds me of some behavior I found and modified in my copy of symbol.py yesterday - the show_definitions hover popup was triggering while I hovered over keywords! I can’t imagine any language whereby one would want to a keyword to be shown as a reference, so it’d be great to have a better way to configure that

1 Like