Skip to content

LSP Code Action Requests with wrong types are sent #177094

Open
@torik42

Description

@torik42

If VSCode somehow obtains faulty diagnostics, it also sends them – out of spec – to other LSP-servers in Code Action Requests. More specifically, it sends the position:

"start": {
    "line": null,
    "character": 0
},

To my understanding, the line has to be uinteger but not null. This results in failing LSP servers.

This specific issue might be fixed at the source of the faulty diagnostic. I have therefore created an issue in the LaTeX-Workshop extension. It turns out though, that they don’t use an LSP server, but the npm vscode module which requires the line to be of type number which allows for value NaN. Moreover, I think that VSCode should not send faulty LSP messages. For the case of diagnostics, it should either filter such diagnostics, which do not adhere to the LSP, or directly block them, when they are given to VSCode in the first place.

Does this issue occur when all extensions are disabled?: (probably) No

  • VS Code Version: Version: 1.76.1, Release: 23069, (actually using VSCodium)
  • OS Version: macOS 13.2.1 / Darwin x64 22.3.0 (also happens on Windows)

Steps to Reproduce:

What I describe here, is how I noticed this error. I expect, that it can also appear in a lot of other contexts.

  1. Install the LaTeX Workshop extension.
  2. Install any other LSP server which works in LaTeX documents and allows for Code Action Requests (I experience this with the still unpublished YaLafi-LS-VScode extension and will update this issue, as soon as a first version is published. The server itself is available here.)
  3. Open the following LaTeX file and build with xelatex.
    \documentclass{article}
    
    \usepackage{mathtools}
    \usepackage{unicode-math}
    
    \begin{document}
        This is some text.
    \end{document}
    This will issue two warnings with the faulty positions, they are displayed at the beginning of the file.
  4. Move around in the document. VSCode will send faulty Code Action Requests to the LSP server looking like this.
    {
        "jsonrpc": "2.0",
        "id": 10,
        "method": "textDocument/codeAction",
        "params":{
            "textDocument":{
                "uri": "file:///.../test.tex"
            },
            "range":{
                "start":{
                    "line": 7,
                    "character": 14
                },
                "end":{
                    "line": 7,
                    "character": 14
                }
            },
            "context":{
                "diagnostics":[
                    {
                        "range":{
                            "start":{
                                "line": null,
                                "character": 0
                            },
                            "end":{
                                "line": null,
                                "character": 65535
                            }
                        },
                        "message": "Using \\overbracket and \\underbracket from\n(unicode-math)\t`mathtools' package.\n(unicode-math)\t\n(unicode-math)\tUse \\Uoverbracket and \\Uunderbracket for\n(unicode-math)\toriginal `unicode-math' definition.\n",
                        "severity": 2,
                        "source": "LaTeX"
                    },
                    {
                        "range":{
                            "start":{
                                "line": null,
                                "character": 0
                            },
                            "end":{
                                "line": null,
                                "character": 65535
                            }
                        },
                        "message": "I'm going to overwrite the following commands\n(unicode-math)\tfrom the `mathtools' package: \n(unicode-math)\t\n(unicode-math)\t\\dblcolon, \\coloneqq, \\Coloneqq, \\eqqcolon.\n(unicode-math)\t\n(unicode-math)\t\n(unicode-math)\tNote that since I won't overwrite the other\n(unicode-math)\tcolon-like commands, using them will lead to\n(unicode-math)\tinconsistencies.\n",
                        "severity": 2,
                        "source": "LaTeX"
                    }
                ]
            }
        }
    }
  5. In my specific case with the server implemented using pygls I get the attached log test-pygls.log.

Edit: Added link and short comment about issue in LaTeX Workshop extension.

Metadata

Metadata

Labels

editor-code-actionsEditor inplace actions (Ctrl + .)feature-requestRequest for new features or functionalityhelp wantedIssues identified as good community contribution opportunities

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions