nametake / golangci-lint-langserver

golangci-lint language server
MIT License
229 stars 20 forks source link

Avoid returning negative positions #34

Closed rliebz closed 11 months ago

rliebz commented 1 year 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 11 months ago

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

nametake commented 11 months ago

Thank you!