MATLAB-extension-for-vscode icon indicating copy to clipboard operation
MATLAB-extension-for-vscode copied to clipboard

Linter Issues for Renamed Class Definitions

Open Gusmano-2-OSU opened this issue 10 months ago • 6 comments

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

  • OS Version: Windows 11
  • VS Code Version: 1.87.2

Gusmano-2-OSU avatar Mar 26 '24 16:03 Gusmano-2-OSU

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.

dklilley avatar Mar 26 '24 18:03 dklilley

  1. r2024a
  2. Matlab is connected via the official MATLAB extension for VS Code.

Gusmano-2-OSU avatar Mar 26 '24 19:03 Gusmano-2-OSU

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

dklilley avatar Mar 26 '24 19:03 dklilley

  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

goldrik avatar Mar 28 '24 19:03 goldrik

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 avatar Mar 28 '24 20:03 dklilley

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.

dklilley avatar Mar 29 '24 17:03 dklilley