Sublime Forum

Goto Definition (F12) Opens New Tab Despite Preopened Instance

#1

This is an old topic
Secondly sorry for un-punchy title, might not be that descriptive either:

My problem has been bugging me for two years, so finally thought I’d tackle it…
I’ve tried the solution posted here but to no avail.

The behaviour I’m looking for is that if a have a file open (in a tab) that contains a definition (of a function or whatever) that if I then use F12 to goto that definition, ST3 doesn’t open a new tab (another open instance of that file).

I tired pasting:


def open_location(window, l):
    fname, display_fname, rowcol = l
    row, col = rowcol

    view = window.find_open_file(fname)
    if view:
        if view.is_primary():
            window.focus_view(view)
        else:
            view.close() # Preview related to the QuickPanel

    window.open_file(
        fname + ":" + str(row) + ":" + str(col),
        sublime.ENCODED_POSITION)

into Default/etc but no joy.

In other news, I’m finally getting to grips with ST3, and beginning to realise it’s power. Am thinking about writing a “stuff I’d wish I’d known at the beginning of my ST3 journey” post. I guess it would go under general discussion…?

ATB

1 Like

#2

In ST4 ctrl+f12 opens a new tab regardless of whether that file is already open.

0 Likes

#3

Ah ha. Is it possible, not to have a new tab open ? I.e. if one is already open. Fine if there are No tabs open, that’s what I’d expect !
(I only have a 32 bit machine so ST4 is out of reach atm)

Ta

0 Likes

#4

In ST4, just F12 does that; you use Ctrl+F12 when you want the extra tab (which is put into a split view so you can see both at once).

The fix you outlined above works fine for me in ST3; how did you implement it?

0 Likes

#5

Hi
Firstly, here’s few screen shots,and hopefully I can clarify:
In the first screen shot hopefully you can see the F12 dialog box (it’s been partially de-rendered by the screen saving process) where my white arrow cursor is hovering over:-

 graphicsWindow.Display(mandelbrot_resourcer.CompleteTexture, position,

(in white) Definitions:
(in blue) Final Project/SDLE{nvironment.cpp:55}
Final Project/SDLE{nvironment.hpp:31}

(text in { } is the text missing from F12 dialog box)

graphicsWindow is an instance of SDLEnviroment and so when I click on Final Project/SDLEnvironment.hpp:31 I expect to go the tab that’s already open in the top pane.
(I should have organised the screen grab so that you could see the method Display() there, d’oh)

However it opens a new tab:- (where you can see the Display method !)


As you can see there’s now two instances of SDLEnvironment.hpp open, instead of one.

In answer to your question; The following link is a detailed version of what I did if you scroll down a bit.
I’ve tried the solution posted here but to no avail. I.e. I posted the replacement code into Default/symbol.py. I think it’s around line 100 in this version of ST 3211

0 Likes

#6

Does it do the same thing if you use the key instead of the hover popup?

0 Likes

#7

Hi
I get an unable to find error. I’ve tried ‘re-installing’ the old code (I only commented it out) and quitting and restarting ST3, but it doesn’t make any difference.

With either old or new code I still have the uneccessary new tab opening.
Weirdly I’m sure using just the key used to work, maybe I need a machine restart…

Thanks for getting back to me !

0 Likes

#8

Also noticed ST4 to open files in new views when invoking a “Goto Definition” every here and than, rather than just re-using the existing one. I am not very confident about circumstances but the file being open in another group/pane than the one goto definition is invoked in seems involved.

1 Like

#9

Surely ST3 keeps a list of open files somewhere, and then it’s just a question of querying that, and not opening if one is open, and opening one if one isn’t ?
Here’s something for ST2

Final thought, knowing that everything in ST is modular, is there anywhere where the goto definition code is ?

0 Likes

#10

Final thought, knowing that everything in ST is modular, is there anywhere where the goto definition code is?

Command Palette > View Package File > Default/symbol.py

Edit: Sry, just saw that according to your posts above you already tried to edit this file. But I think everything relevant to the “goto definition” feature is implemented in the symbol.py file, in particular the F12 keybinding is set to the goto_definition command, which is implemented via the Python code in class GotoDefinition(sublime_plugin.WindowCommand).

0 Likes

#11

Indeed, and the plugin enhancement mentioned previously should be all that’s needed; it looks to see if the file is open already, and focuses it to make sure that a new copy isn’t opened. In my testing here it works the way I would expect.

0 Likes

#12

Even though the patch might work, the point probably is window.open_file() to be expected to find already open views into a file as well. That’s what bugs me every here and than, when opening a file from within Sublime Merge. ST always opens a new view into the same already open file.

1 Like

#13

Thanks everyone so far, still have two instances opening tho. I’ve lived with it for 2 years, but it’s about work flow. The more time I don’t have to spend doing uneccessary things, the more time I can spend infront of youtube!
(That was an attempt at a joke btw)

My career as a comedian, done before start…

1 Like

Open reference in active column
#14

For those still looking how to do this (including myself after a new ST4 install), see my comment here.

0 Likes

#15

Hey, I’ve been suffering this for a long while, but thanks to LSP plugin and your threads guys (i.e. the knowledge that it’s sublime.FORCE_GROUP that’s causing the undesirable behavior), turns out LSP already has an option to neutralize it:

{ "keys": ["super+b"], "command": "lsp_symbol_definition", "args": {"side_by_side": false, "force_group": false} },
{ "keys": ["super+shift+b"], "command": "lsp_symbol_type_definition", "args": {"side_by_side": false, "force_group": false} },

Pure. Happiness.

Sharing in case you also prefer to switch to LSP and forget this disaster.

0 Likes