[vscode] navigate to class definition when clicking class name in comment section is possible?

Hi, all.
First of all, sorry for taking your precious time on reading this dumb question…

Assuming one file named domain_models.py


# All domain models in one file
# ====== Authentication =======
# `User`
# ...
# ===== Investing: Stock ======
# `Stock`
# ...
# ===== Investing: Community =====
# `Post`

class User:

# after 1_000 lines
class Stock: # line 2_001

# after another 3_000 lines
class Post: # line 4_001

I want to move to class definition when I click class name in comment section. For example, when I click Stock in comment, mouse cursor moves to line 2001. Is that functionality possible in VSCode?

I think spliting one file into many subfiles into meanigful way (such as domain boundary, functionality, team organizations etc…) is better for this case. However, I just want to know that kind of functionality is possible in Visual Studio Code… (Actually I practice python using creating mini project, I don’t have good knowledge to split files and manage import etc… just wanna to keep one file if possible.)

Thanks for reading this question.

Hey SoonShin am not so sure about that functionality… but in the meantime why don’t you just ctrl + F to perform a quick search of all the matching names lol

If I put vscode python go to class definition into a search engine, I get some useful references right off the top, including something from the official documentation. Reading the links further, I think you may actually want the “go to implementation” feature, which should be Ctrl-F12. I think that covers the problem, or did I misunderstand the requirement?

1 Like

Yeah… you’re right. However, I am not good at typing english and typo expert… and there are a few same name out there such as class definition, type alias, comments, docstring etc. I think I am too lazy… Luckily Karl Knechtel’s comments about various utility shortcuts make me happy dealing with the issues I have althought it doesn’t fit 100%. (that means my approach is not good maybe).

Thanks for a kind and helpful comment. It saves me… No misunderstanding. I don’t know vscode has many different good shortcuts as you said. (go to definition, go to implementation etc.). Although names in comment are not effective in triggering shortcuts, it’s better to take another way given your comment. Just using Go to Symbol.. (ctrl + shift + o by default) and Go to Definition (F12 by default) will saves me time and efforts a lot. You make my tiny toolkit better. Thank you!