mathworks / MATLAB-extension-for-vscode

This extension provides support for editing MATLAB® code in Visual Studio® Code and includes features such as syntax highlighting, code analysis, navigation support, and more.
https://marketplace.visualstudio.com/items?itemName=MathWorks.language-matlab
MIT License
234 stars 15 forks source link

"Go to definition" incorrectly triggers on tokens which dont have a reference (e.g. strings) #94

Open goldrik opened 7 months ago

goldrik commented 7 months ago

If you right click a token (some function, variable, etc), then select "Go to Definition", VS Code will navigate to where that token was originally defined. For functions, this may mean opening the file where that function was defined. This should not work on other tokens, such as raw strings.

In the video, I created a dummy string. To "Go to Definition", I use ctrl+click (though I have found that it occurs with ctrl+d as well). Near the end of the video, you can see that clicking on the words takes me to some random built-in function (which doesnt even have the same name as the word I selected). The words then end up showing up as links (blue, underlined).

https://github.com/mathworks/MATLAB-extension-for-vscode/assets/8674612/380e9009-ebb5-48a8-b840-79980afd9857

It is somewhat finicky to reproduce. In the video it took me a few clicks (and some waiting) to get it to take me to the "definition". The behavior is also weirdly inconsistent. But I have always been able to reproduce it.

Visual Studio Code 1.87.0 MATLAB r2023b, r2023a MATLAB Extension v1.1.6

dklilley commented 7 months ago

Thanks for reporting this! I agree that this is not ideal behavior.

J-Sorenson commented 6 months ago

There are cases where you want tokens in a string to navigate to functions (such as in evalin(st) calls). We have code where we create handles from the names of scripts (don't look at me like that, I didn't write this God-forsaken code), and it's useful to click on that string. That said: the script name should match the string token. This looks like it is trying to navigate to a class member or private function.