Skip to content
New issue

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

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

Already on GitHub? # to your account

Lua error at multiline strings in util.lua: 'Column value outside range' #224

Closed
kaddkaka opened this issue Oct 28, 2022 · 3 comments
Closed
Labels

Comments

@kaddkaka
Copy link

Warnings that refer to the position where a multiline string ends causes errors when hover in Trouble buffer and goto doesn't work.

Small example, create a python file with following content:

1
"""
"""

To get the following warnings in the Trouble buffer:

   banana.py  3
 │     [pointless-statement] Statement seems to have no effect pylint (W0104) [1, 1]
 │     [pointless-string-statement] String statement has no effect pylint (W0105) [3, 0]
 │     [missing-module-docstring] Missing module docstring pylint (C0114) [1, 1]

When placing the cursor on the middle warning this is the error output:

Error executing vim.schedule lua callback: /home/david/.vim/plugged/trouble.nvim/lua/trouble/view.lua:465: Column value outside range
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        /home/david/.vim/plugged/trouble.nvim/lua/trouble/view.lua:465: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

When pressing <enter> on that entry, this is the error output:

E5108: Error executing lua /home/david/.vim/plugged/trouble.nvim/lua/trouble/util.lua:18: Column value outside range
stack traceback:
        [C]: in function 'nvim_win_set_cursor'
        /home/david/.vim/plugged/trouble.nvim/lua/trouble/util.lua:18: in function 'jump_to_item'
        /home/david/.vim/plugged/trouble.nvim/lua/trouble/view.lua:443: in function 'jump'
        /home/david/.vim/plugged/trouble.nvim/lua/trouble/init.lua:177: in function 'action'
        [string ":lua"]:1: in main chunk

It works fine to hover and "go to" on other warnings, it's just errors referring to last line of multiline string it seems like.

@snoord
Copy link

snoord commented Apr 4, 2023

This issue appears when a language server publishes a diagnostic which has an unsupported range.position.start.character value.

In my case this diagnostic field was set to -1 when golangci-lint-langserver would report specific diagnostics, usually related to the relevant file as a whole (e.g. when said file hadn't been go fmted yet).

I resolved this by attaching a custom textDocument/publishDiagnostics handler specifically to golangci-lint-langserver during the nvim-lspconfig setup call. The custom handler changes any range.position.(start|end).character value of -1 to 0 before passing it back to the original handler:

local lspconfig = require("lspconfig")
local on_publish_diagnostics = vim.lsp.handlers["textDocument/publishDiagnostics"]
lspconfig.golangci_lint_ls.setup({
  -- <...>
  handlers = {
    -- stops an out-of-range column error when viewing diagnostics with Trouble.nvim
    ["textDocument/publishDiagnostics"] = function(_, result, ctx, config)
      for idx, diag in ipairs(result.diagnostics) do
        for position, value in pairs(diag.range) do
          if value.character == -1 then
            result.diagnostics[idx].range[position].character = 0
          end
        end
      end

      return on_publish_diagnostics(_, result, ctx, config)
    end,
  },
})

@siraphobk
Copy link

@snoord I just recently found this error too when using golangci-lint-ls. Your solution works flawlessly!

rliebz added a commit to rliebz/golangci-lint-langserver that referenced this issue 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`:

```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.
thejan2009 pushed a commit to thejan2009/golangci-lint-langserver that referenced this issue Jan 5, 2024
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.
@folke folke added the fixed v3 label Mar 29, 2024
@folke
Copy link
Owner

folke commented Mar 29, 2024

Development on the main branch is EOL.

Trouble has been rewritten and will be merged in main soon.

This issue/feature either no longer exists or has been implemented on dev.

For more info, see https://github.com/folke/trouble.nvim/tree/dev

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

No branches or pull requests

4 participants