vscode-circuitpython icon indicating copy to clipboard operation
vscode-circuitpython copied to clipboard

[BUG] Changes to python.analysis.diagnosticSeverityOverrides are completely overwritten at startup

Open Jzooor opened this issue 3 years ago • 5 comments

Describe the bug When the extension starts up, the value for python.analysis.diagnosticSeverityOverrides in settings.json is completely overwritten, losing any user customized settings.

To Reproduce Steps to reproduce the behavior:

  1. Open settings.json
  2. Add "reportShadowedImports": "none" to "python.analysis.diagnosticSeverityOverrides" e.g.
    "python.analysis.diagnosticSeverityOverrides": {
        "reportMissingModuleSource": "none",
        "reportShadowedImports": "none"
    },
  1. Close and re-open workspace.
  2. See that "python.analysis.diagnosticSeverityOverrides" no longer has the added value from step 2.

Expected behavior All user customizations to "python.analysis.diagnosticSeverityOverrides" in settings.json should be kept (extra options, and changes to extensions desired values).

Desktop (please complete the following information):

  • OS: Win10
  • Version VS Code v1.73.1, CircuitPython extension v0.1.19

Additional context I want to add (and keep) "reportShadowedImports": "none" because Pylance complains that code.py overrides the stdlib module code.

Jzooor avatar Dec 07 '22 20:12 Jzooor

I gather the reason is that the activate function in extension.ts is just wholesale setting the value of "python.analysis.diagnosticSeverityOverrides" to be

{
    "reportMissingModuleSource": "none"
}

Which wipes out anything else in the settings.json file.

I don't know javascript or the VS extensions API very well, but I will try to see if I can figure out how to merge what the extension wants to be in the settings with what already exists there.

Jzooor avatar Dec 07 '22 20:12 Jzooor

I found if I created a .workplace file the settings.json does not get reverted in that section anymore but then there is a chance when a bundle has updated the date in the path is not updated.

wmerkens avatar Feb 04 '23 17:02 wmerkens

I have a .workplace file too to support multiple different projects but the extension still overwrites my overrides.

From what I can tell, the offending line is this: https://github.com/joedevivo/vscode-circuitpython/blob/475d25c6c7305090c5fd9fc8bc9006b69bb9038f/src/extension.ts#L8

I am not a ts developer but it seems like it's a simple fix to check if the setting doesn't exist and append it to the config.

I found that you can set

"python.analysis.diagnosticSeverityOverrides" : {
  "reportShadowedImports": "none"
}

at your user settings json and it seems like it doesn't overwrite it. From what I can tell from the code, it is overwriting workspace settings which are not the same as user settings.

This unfortunately has the impact of changing all of your python projects unrelated to circuitpython ones. You might end up forgetting about it later.

f0lie avatar Feb 13 '23 01:02 f0lie

Not a solution to the bug reported here per se but you can probably solve your original problem by instead renaming code.py to main.py. Per the documentation, this obviates a need to disable the warnings you're trying to avoid.

stefan-sherwood avatar Feb 18 '23 20:02 stefan-sherwood

I have this same issue, and I am not a TypeScript developer, but I am a python developer. I took a crack at the changes required, and would like somebody to review and approve:

https://github.com/joedevivo/vscode-circuitpython/pull/120

I don't know how to properly test the changes, so please review carefully.

jrwagz avatar May 13 '23 19:05 jrwagz