Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Incorrect diagnostics positions #1577

Open
5 tasks done
name-snrl opened this issue May 28, 2023 · 1 comment
Open
5 tasks done

Incorrect diagnostics positions #1577

name-snrl opened this issue May 28, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@name-snrl
Copy link

FAQ

  • I have checked the FAQ and it didn't resolve my problem.

Issues

  • I have checked existing issues and there are no issues with the same problem.

Neovim Version

NVIM v0.9.0

Dev Version?

  • I am using a stable Neovim release version, or if I am using a dev version of Neovim I have confirmed that my issue is reproducible on a stable version.

Operating System

NixOS rev: 963006aab35e3e8ebbf6052b6bf4ea712fdd3c28

Minimal Config

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
  local path_sep = on_windows and "\\" or "/"
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local null_ls_config = function()
  local null_ls = require("null-ls")
  -- add only what you need to reproduce your issue
  null_ls.setup({
    sources = {
      null_ls.builtins.diagnostics.shellcheck,
    },
    debug = true,
  })
end

local function load_plugins()
  -- only add other plugins if they are necessary to reproduce the issue
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      {
        "jose-elias-alvarez/null-ls.nvim",
        requires = { "nvim-lua/plenary.nvim" },
        config = null_ls_config,
      },
      --{
      --  'neovim/nvim-lspconfig',
      --  config = function() require 'lspconfig'.bashls.setup { } end,
      --},
    },
    config = {
      package_root = package_root,
      compile_path = compile_path,
    },
  })
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
  load_plugins()
  require("packer").sync()
else
  load_plugins()
  require("packer").sync()
end

Steps to Reproduce

First of all, for me this problem is not related to shellcheck, but to ltrs. I just haven't found an LS that does the same thing as null-ls. Anyway, I think it's the same problem. And it affects any null-ls diagnostic builtins.

The problem occurs if any character that counts as two (Cyrillic, Japanese Kana, etc.) is written in front of the diagnosed site. It leads to a shift of the diagnosed position.

Steps to reproduce:

  1. create sample file
  2. open file nvim --clean -u <cfg_path> <sample_file>
    nix way: nix run nixpkgs/963006aab35e3e8ebbf6052b6bf4ea712fdd3c28#neovim-unwrapped -- --clean -u <cfg_path> <sample_file>
  3. now comment out null_ls.builtins.diagnostics.shellcheck, and uncomment lspconfig lines
  4. repeat the first two steps

Sample file:

#!/usr/bin/env bash

echo "лдофыва $foo"
echo "$bar"

Results:

  • with bashls
    image

  • just shellcheck via null-ls
    image

Reproducibility Check

  • I confirm that my minimal config is based on the minimal_init.lua template and that my issue is reproducible by running nvim --clean -u minimal_init.lua and following the steps above.

Expected Behavior

The same as with other LS

Actual Behavior

Incorrect position of the diagnosed site

Debug Log

[TRACE Sun 28 May 2023 04:50:45 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method exit
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/client.lua:97: starting null-ls client
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:102: received LSP request for method initialize
[DEBUG Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/client.lua:152: unable to notify client for method textDocument/didOpen (client not active): {
  textDocument = {
    uri = "file:///home/name_snrl/trash/test.sh"
  }
}
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method initialized
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method textDocument/didOpen
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_OPEN
[DEBUG Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:320: spawning command "shellcheck" at /home/name_snrl/trash with args { "--format", "json1", "--source-path=/home/name_snrl/trash", "--external-sources", "-" }
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:204: error output: nil
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/helpers/generator_factory.lua:205: output: {"comments":[{"file":"-","line":3,"endLine":3,"column":15,"endColumn":19,"level":"warning","code":2154,"message":"foo is referenced but not assigned.","fix":null},{"file":"-","line":4,"endLine":4,"column":7,"endColumn":11,"level":"warning","code":2154,"message":"bar is referenced but not assigned.","fix":null}]}

[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/diagnostics.lua:181: received diagnostics from source 1
[TRACE Sun 28 May 2023 04:53:59 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/diagnostics.lua:182: { {
    code = 2154,
    col = 14,
    end_col = 18,
    end_lnum = 2,
    end_row = 3,
    lnum = 2,
    message = "foo is referenced but not assigned.",
    row = 3,
    severity = 2,
    source = "shellcheck"
  }, {
    code = 2154,
    col = 6,
    end_col = 10,
    end_lnum = 3,
    end_row = 4,
    lnum = 3,
    message = "bar is referenced but not assigned.",
    row = 4,
    severity = 2,
    source = "shellcheck"
  } }
[TRACE Sun 28 May 2023 04:58:15 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:102: received LSP request for method shutdown
[TRACE Sun 28 May 2023 04:58:15 +05] /tmp/nvim/site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method exit

Help

Yes

Implementation Help

I need an explanation of the difference between how null-ls and other LSs provide diagnostic data. As I see it, null-ls just uses vim.diagnostic.set(), but how do other LSs do it?

I think we need to add some hook to convert row column values to virtual

Requirements

  • I have read and followed the instructions above and understand that my issue will be closed if I did not provide the required information.
@name-snrl name-snrl added the bug Something isn't working label May 28, 2023
@name-snrl
Copy link
Author

At first glance, it seems to have what we need

https://github.com/neovim/neovim/blob/master/runtime/lua/vim/lsp/diagnostic.lua#L104-L134

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant