Vito De Tullio
Vito De Tullio

Reputation: 2121

intelligent vscode "Go to Definition"

--- edit

Let's say that I have the following scenario in vscode:

Example

I have 3 open files, with vscode showing two files at once. on the left I have 2 tabs: a.js, in foreground, with

import { b } from './b';
import { c } from './c';

b();
c();

and b.js, with

export function b() {
    // ...
}

and on the right I have c.js, with

export function c() {
    // ...
}

My goal is:

Is there a way to get it?

--- original

In vscode, according to https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition

You can jump to the definition with Ctrl+Click or open the definition to the side with Ctrl+Alt+Click.

Now, I use the side panel a lot, and sometimes the "target" where the definition is, is in another side, and sometimes is a different tab in the same side on where I am now.

If I do the appropriate choice I can go directly to the already opened buffer. If I choose the "wrong" shortcut a new buffer of the same file is opened.

Is there a way to make the "go to definition" smart? I just want to always go to the already opened file (if is available).

Upvotes: 5

Views: 3842

Answers (1)

akseli
akseli

Reputation: 2818

You should head to VS Code's settings and select the Reveal If Open option.

You'll be able to find it in the Workbench --> Editor Management section.

Reveal If Open Setting

Upvotes: 7

Related Questions