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
237 stars 15 forks source link

Feature request: Specify custom MATLAB startup function within VS Code #21

Open rick3rt opened 1 year ago

rick3rt commented 1 year ago

Very nice to see a vscode extension by mathworks!

When using MATLAB, I have multiple addpath statements in my startup.m for libraries or projects that I use daily. Could you add the possibility to add the .m files located in these paths to the indexed files? This will allow code navigation for files that are not in my current workspace, but that my code is dependent on.

Ideally by running/parsing the startup.m, but otherwise having a configuration with paths to add to the index would work as well.

Thanks!

dklilley commented 1 year ago

I believe this should work - code navigation should pick up on files which are not in the VS Code workspace but are on the MATLAB path.

I was able to navigate to a file by adding its directory in the startup.m script.

Are you seeing otherwise? Can you provide more information about your setup to help reproduce this?

rick3rt commented 1 year ago

ah indeed, the paths in the default startup.m work, my mistake.

Then my feature request would actually be to set the path to a custom startup file in the vscode configuration, since I work on a system with multiple users and I always start my session with running the command startup_myname. This would not pollute the matlab session of other users with my paths.

dklilley commented 1 year ago

Thanks for the suggestion! I'll update the issue name to better reflect this. Feel free to modify it if it does not capture quite what you are requesting.

eric-dishman-ctct commented 7 months ago

@dklilley I'm not sure if I should create a new issue or not. I am trying to get the vscode extension to find some package folder on a different path.

ProjectRoot below is a Git repo and I am working on a file inside ToolDir. I would like vscode to find packfile.m when using go to definition in myfile.m

For Example image

I have tried using vscode workspaces and adding both Packages and ToolDir in the code.workspace file. This however doesn't work. The only way I can vscode to recognize the Package folder is to add it to startup.m

For me this could be problematic if I wanted to work in a duplicate repo as I explore different changes.

Are there any other options? Am I missing something.

If startup.m is the only option today. Could the extension leverage the code.workspace file to help find dependencies?

Thanks Eric

dklilley commented 7 months ago

Hi @eric-dishman-ctct,

In the latest version of the extension (v1.2.0), we have added execution support. As part of this, folders now have a "MATLAB: Add Folder To Path" option in the context menu. I believe you should be able to use this to add your "Packages" directory to the MATLAB path, which will enable navigation to the expected file.

If this does not work for you, please feel free to create a new issue for this.

eric-dishman-ctct commented 7 months ago

@dklilley Thanks for responding. I just downloaded the latest extension. This is AMAZING! I can't wait to see what you guys have in store for the future. The latest update solves my problem!

Having access to the headless MATLAB makes a HUGE difference in what is possible now.