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

Linter Issues for Renamed Class Definitions #119

Open Gusmano-2-OSU opened 8 months ago

Gusmano-2-OSU commented 8 months ago

Describe the bug User-defined classes aren't properly linted, causing confusion at best and errors at worst.

To Reproduce

  1. Make a new file testClass.m.
  2. use the classdef snippet, make a new class testClass.
  3. Rename the file to TestClass.m -- the linter doesn't recognize any issues.
  4. Rename the classdef and constructor function to TestClass -- though this is correct and runs as expected, the linter gets angry.

Expected behavior At step 3, the linter should get angry. At step 4, the linter should calm down.

Screenshots The Linter needs to get angry here image

and calm here image

Useful Information

dklilley commented 8 months ago

Hi @Gusmano-2-OSU , thanks for raising this!

I am having trouble reproducing this behavior on my end. Could you send some additional info to help us determine what is happening?

  1. What MATLAB version are you using?
  2. When you see this behavior when you are connected to MATLAB through the MATLAB extension for VS Code, or when MATLAB is disconnected? If MATLAB is not connected, linting will only update when the file is saved.
Gusmano-2-OSU commented 8 months ago
  1. r2024a
  2. Matlab is connected via the official MATLAB extension for VS Code.
dklilley commented 8 months ago

Could you share a video of this occurring? This may assist with reproducing the issue on our end.

goldrik commented 8 months ago
  1. Created file testClass.m (no error, correct)
  2. Wrote classdef named testClass (no error, correct)
  3. Renamed file to TestClass.m (no error, bug)
  4. Renamed classdef to TestClass (error, bug)
  5. Renamed classdef back to testClass (no error, bug)

https://github.com/mathworks/MATLAB-extension-for-vscode/assets/8674612/33b51cf2-0a8d-463e-81d7-faf14fbfab61

dklilley commented 8 months ago

Thanks for sharing the additional info!

It seems like there may be two things at play here:

  1. Renaming the file does not trigger linting to refresh
  2. The old file name seems to be maintained somehow after the rename
dklilley commented 8 months ago

Thanks again for sharing these steps! I was able to reproduce this behavior.

It appears that, after the file is renamed, the onDidChangeContent handler is still being provided a TextDocument for which the URI has the old file name.