nametake / golangci-lint-langserver

golangci-lint language server
MIT License
201 stars 19 forks source link

Avoid returning negative positions #34

Closed rliebz closed 6 months ago

rliebz commented 9 months ago

According to the LSP spec, the line and character must both be unsigned integers. The spec also specifically calls out that -1 is not supported: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position

With some code structures, it is possible to produce an error such as the following from golangci-lint run --out-format=json:

{
  "FromLinter": "typecheck",
  "Text": ": # github.com/my/package [github.com/my/package.test]\n./main.go:31:2: undefined: asdf",
  "Severity": "",
  "SourceLines": [
    "package main"
  ],
  "Replacement": null,
  "Pos": {
    "Filename": "main.go",
    "Offset": 0,
    "Line": 1,
    "Column": 0
  },
  "ExpectNoLint": false,
  "ExpectedNoLintLinter": ""
}

This ultimately does result in some issues with tooling compatibility, for example: https://github.com/folke/trouble.nvim/issues/224#issuecomment-1495410321

By preventing the number from dropping below zero, this class of error should no longer be present.

rliebz commented 6 months ago

@nametake let me know if there's anything I can do to help get this merged

nametake commented 6 months ago

Thank you!