Sublime Forum

Goto Symbol in same language

#1

It would be great if the Goto Symbol command would ignore files that weren’t the same language or file type as the current file.

For example, if I am trying to find a symbol definition in PHP, I don’t care if that same symbol exists in JS and CSS. Just give me matching PHP symbols.

If this exists already in some capacity, I’d love to learn about it. The best I can hope for now is having “.php” at the end of the Goto Symbol palette and hope the fuzzy search just gives me those results…

2 Likes

#2

However, I like it. If I have a symbol on a Pawn language file, I want it to point to the C++ file. So, a setting option to enable this behavior or not, is welcome. But of course, on an PHP/CSS project I would like this feature enabled.

Then instead of just enabled or disable crossed language symbol linking globally, add a setting to select what languages may not have crossed symbols. Example:

    "not_crossed_symbols_languages": 
    [ 
        { ["source.CSS", "source.PHP" ] },
        { ["source.Java", "source.C++" ] },
    ]

On the above example, only the symbols from CSS and PHP, will not be crossed, the same for the second line.
But all other things as symbols not mentioned within the same line as from CSS, Java, C++, etc, are allowed to be crossed.

1 Like

#3

I considered this when we rolled the functionality out in dev build 3116, but decided not to implement it initially.

Reasons for this include:

  1. HTML and CSS/Sass
  2. C and dynamic languages interaction (Python or Ruby calling functions defined in C)
  3. Various languages and SQL

It may be that we come up with some functionality to limit it, I just think we need some discussion of the possible options before we decide on anything. Personally I wouldn’t not have noticed the benefits of items 2 and 3 without leaving it enabled by default.

4 Likes

#4

Thanks for the info, @wbond - I didn’t know about Python/Ruby calling C functions.

In any case, it would seem the bare minimum (something like @addons_zz’s example) could be implemented and leaving the user to decide what restrictions to introduce. That way, as a kind of intro to the feature, users could play with it, get a feel for it, etc…

If it became popular enough, making more intelligence associations and restrictions would be a more worthy investment of resources. I’d love to see at least a super simple, stripped-down version of the feature though.

1 Like

#5

There are some contexts where there is little to no ambiguity.

The one I describe in the issue on the tracker is a good one: https://github.com/SublimeTextIssues/Core/issues/335#issue-35540618. I’ve never wanted to jump from a PHP context to RUBY.

Where | is the cursor when jumping to the definition.

# syntax PHP

# view.phtml
<ht|ml>

# other file.php
function html() {}

The above will jump to the PHP function. I can’t see how I would ever need or want this. However, there are cases, for example maybe in template systems, where identifiers might map to PHP functions or methods. But generally I find these cases are rare and given a choice I’d prefer goto definition to be more clever and make assumptions. There could be two commands: a smart one that makes assumptions and one that doesn’t. I’d default to the smart one.

Vim, allows modifiers to the jump so you can prefix a jump with a number which will pick the nth definition in the list and jump straight to that definition. By default it jumps to the first in the list (it’s quiet clever about the priority of the list). It also allows you to request to show a list if more than one possible definition is available.

g						*g*
					** *CTRL-]*
CTRL-]			Jump to the definition of the keyword under the
			cursor.  Same as ":tag {ident}", where {ident} is the
			keyword under or after cursor.
			When there are several matching tags for {ident}, jump
			to the [count] one.  When no [count] is given the
			first one is jumped to. See |tag-matchlist| for
			jumping to other matching tags.

re: http://vimdoc.sourceforge.net/htmldoc/tagsrch.html

0 Likes

#6

I think Goto Symbol makes sense to be searching any language, but it would be great if Goto Definition would search only within a language, and maybe add a Goto Uses for going the other way that again stays within the language.

I agree with @wbond’s reasons for within an application. However, my use-case for this is that I tend to have multiple applications within a project, often using the same names in different applications for the same data when they are communicating, so this would be really helpful.

0 Likes