Skip to content

Avoid returning negative positions #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2023
Merged

Conversation

rliebz
Copy link
Contributor

@rliebz rliebz commented Oct 10, 2023

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: folke/trouble.nvim#224 (comment)

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

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`:

```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: folke/trouble.nvim#224 (comment)

By preventing the number from dropping below zero, this class of error
should no longer be present.
@rliebz
Copy link
Contributor Author

rliebz commented Dec 16, 2023

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

@nametake
Copy link
Owner

Thank you!

@nametake nametake merged commit 67f5ace into nametake:master Dec 16, 2023
@rliebz rliebz deleted the non-negative branch December 16, 2023 13:26
@@ -104,6 +110,13 @@ func (h *langHandler) lint(uri DocumentURI) ([]Diagnostic, error) {
return diagnostics, nil
}

func max(a, b int) int {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go 1.21 has max/min builtin, sadly golang allows shadowing of builtins.

can we bump golang go 1.21 and use builtin ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants