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
241 stars 16 forks source link

Autocomplete does not always work #148

Closed rover-random closed 6 months ago

rover-random commented 6 months ago

Describe the bug Code completion for built-in MATLAB works: image

Say in my working directory foobar I have a namespace mypackage: image

I would like to be able to type in vscode mypa and see mypackage autocompleted, and from there the functions in the namespace mypackage. But I do not: image

Sometimes this happens for me, and sometimes it doesn't! I cannot discern why it sometimes works and sometimes does not. Things I have considered and have seemed to make some difference, but have not conclusively solved the problem:

I am on Windows.

dklilley commented 6 months ago

Hi @rover-random , thanks for reaching out!

I believe the issue is that +mypackage needs to be on the path. By default, the current working directory in VS Code is not MATLAB's cwd, nor is it added to the path. We have received similar requests before (e.g. #98), so this is something which is on our radar.

In the file "Explorer" tab in VS Code, try right-clicking in some empty space (in your screenshot, anywhere below "myscript.m") and selecting "MATLAB: Add Folder To Path". Does autocompletion of mypackage and its subfunctions work after this?

rover-random commented 6 months ago

@dklilley right clicking and adding to path was the solution. Wow, thanks! That's been driving me nuts.

dklilley commented 6 months ago

Glad to hear it!

We definitely want to improve this to be more seamless.