intersystems / language-server

Repository for the VS Code Language Server
https://marketplace.visualstudio.com/items?itemName=intersystems.language-server
Other
16 stars 6 forks source link

Error auto formatting classes #286

Closed cambot closed 1 year ago

cambot commented 1 year ago

I am setting up a new VS Code project and I am receiving this error in the VS Code output window when "InterSystems Language" is selected:

[Error - 3:07:06 PM] Request textDocument/rangeFormatting failed.
  Message: Request textDocument/rangeFormatting failed with message: Cannot read properties of undefined (reading 'length')
  Code: -32603 

I have these settings in my .code-workspace file:

{
    "folders": [
        {
            "name": "demo bug",
            "path": "."
        }
    ],
    "settings": {
        "editor.formatOnSave": true,
        "files.trimTrailingWhitespace": true,
        "files.trimFinalNewlines": true,
        "files.insertFinalNewline": true,
        "intersystems.language-server.formatting.system.case": "word",
        "intersystems.language-server.refactor.exceptionVariable": "eException",
        "workbench.tree.renderIndentGuides": "always"
    }
}

I'm connecting to a 2023 instance of HealthShare, but the interesting thing is that I also get the error when I disable my server connection. Switching namespaces and even instances within my settings.json file did not avoid the error.

I also tried manually clearing out various VS Code cache directories under C:\Users\{user name}\AppData\Roaming\Code\ as well as the editor window history and recently opened workspaces with the thinking there might be something cached that's bugging out the extension. None of these actions cleared out the error.

However, if I set format on save to false and rely on document formatting from the context menu (aka right clicking within the class file itself), "Format Selection" produces this error but "Format Document" does not. I'm not sure what the difference is but it's the only way I've found to trigger the correct behavior in my workspace. I should also note that I shared the single class in my project with other co-workers, and it loads into their system just fine. (so I do not think it is the class itself that's causing the problem)

I'm not sure if this is enough information to pinpoint what is happening or not. Are there other troubleshooting options that I've missed? I found this issue and am hoping the fix is similar.

Software Specs:

InterSystems Language Server: v2.3.5 VS Code Version: 1.79.2 (user setup) Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06 Date: 2023-06-14T08:57:04.379Z Electron: 22.5.7 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.19044

isc-bsaviano commented 1 year ago

Hi @cambot, thanks for the detailed issue report! There's definitely a bug here, but I can't identify the spot without a little more info. Does this error only happen with a single class? If so, can you post the text of it here (with any confidential code hidden)? Also, does that error in the Output panel give any location for it?

cambot commented 1 year ago

Unfortunately, I could not locate a stack trace that identified the source of the error. I shared everything from the output window in my original report.

I ended up ignoring the error so I could make some progress on my project and after I committed the offending file, I stopped seeing these errors. I haven't seen or been able to reproduce the error since.

isc-bsaviano commented 1 year ago

@cambot I'm glad you haven't experienced this issue again. I'm going to submit a minor change that should hopefully prevent similar issues form popping up in the future.