Skip to content
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

server must always send publishDiagnostics with a URI #169

Closed
EbonJaeger opened this issue Nov 14, 2020 · 7 comments · Fixed by #175
Closed

server must always send publishDiagnostics with a URI #169

EbonJaeger opened this issue Nov 14, 2020 · 7 comments · Fixed by #175
Labels

Comments

@EbonJaeger
Copy link

EbonJaeger commented Nov 14, 2020

Describe the bug
I know this is probably unsupported, but I am trying to get vala-language-server to work with Neovim's built-in LSP support in the 0.5.0 nightlies. For the short time it's usable, it seems to work well, but there seems to be an issue with diagnostics reporting. I'm not sure yet if this is an issue with the language server, or Neovim's implementation, but figured I'd try here first.

The error shown inside Neovim is:
Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/uri.lua:116: attempt to index local 'uri' (a nil value)

I traced this back to the diagnostics reporting seemingly passing a nil code location here:
https://github.com/neovim/neovim/blob/35325ddac04b1b59b7982797021cdaabdabc87fb/runtime/lua/vim/lsp/diagnostic.lua#L956

Configuration
I think these are the minimum things needed to replicate the environment:

~/.config/nvim/lua/lsp_config/vala_language_server.lua:

local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'

configs.vala_language_server = {
    default_config = {
        cmd = {'vala-language-server'};
        filetypes = {'vala', 'genie'};
        root_dir = util.root_pattern(".git");
        settings = {};
    };
}

~/.config/nvim/lua/lsp_config.lua:

local nvim_lsp = require('lspconfig')

-- Setup language server functions
local on_attach_nvim = function(client)
    require('completion').on_attach(client)
end

nvim_lsp.vala_language_server.setup{ on_attach = on_attach_nvim }

~/.config/nvim/lua/init.lua:

-- Load LSP config
local ok, _ = pcall(function() require('lsp_config') end)

~/.config/nvim/init.vim:

call plug#begin('~/.config/nvim/plugged')

" LSP Plugins
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/completion-nvim'
Plug 'tjdevries/nlua.nvim'
Plug 'tjdevries/lsp_extensions.nvim'

call plug#end()

lua require'init'

syntax on
filetype plugin indent on

Software
OS and version (e.g. Ubuntu 20.04): Solus 4.1
Code editor (e.g. VSCode): Neovim
Vala Language Server (e.g. git commit, or PPA/AUR version): 0.48.1 (a22be6b8faf7099db5b04e92ffedcb1e4792828c)
Vala version (valac --version): 0.48.9 and 0.50.1

To Reproduce
Source code repo: https://github.com/solus-project/budgie-desktop

Steps to reproduce the behavior:

  1. Open src/raven/raven.vala
  2. Wait approx. 3 seconds for errors to appear in the Neovim status area
@HiPhish
Copy link

HiPhish commented Mar 4, 2021

I have the same issue. When I intercepted the message in the diagnostics handling code I got the following:

{
  diagnostics = { {
      message = "`GOBJECT' is already defined",
      severity = 2
    } }
}

The Neovim client expect there to be a URI entry as well, and the specification for textDocument/publishDiagnostics seems to agree:

interface PublishDiagnosticsParams {
	/**
	 * The URI for which diagnostic information is reported.
	 */
	uri: DocumentUri;

	/**
	 * Optional the version number of the document the diagnostics are published
	 * for.
	 *
	 * @since 3.15.0
	 */
	version?: uinteger;

	/**
	 * An array of diagnostic information items.
	 */
	diagnostics: Diagnostic[];
}

EDIT: Here is a sample Vala file which triggered the behaviour:

/**
 * Baby's first Vala class.
 *
 * I have no idea what I'm doing here.
 */
public class MyClass : GLib.Object {
	public int i = 3;
}

@Prince781 Prince781 added the bug label Mar 5, 2021
@Prince781 Prince781 changed the title Error when using with Neovim's upcoming built-in LSP support server must always send publishDiagnostics with a URI Mar 5, 2021
Prince781 added a commit that referenced this issue Mar 5, 2021
If a diagnostic is not associated with a file, associate it with the
project root folder, rather than sending "null"
@Prince781
Copy link
Member

@EbonJaeger @HiPhish could you test VLS from the bug/publishDiagnostics-without-uri branch and let me know if it fixes your issue?

@EbonJaeger
Copy link
Author

EbonJaeger commented Mar 5, 2021

@Prince781 thanks for looking into this! I have good news and bad news. The good news: the particular error no longer appears. The bad news: instead it throws a few of these errors:
Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/diagnostic.lua:220: attempt to index local 'range' (a nil value)
Which would be in this function in the Lua runtime:

--- Store Diagnostic[] by line
---
---@param diagnostics Diagnostic[]
---@return table<number, Diagnostic[]>
local _diagnostic_lines = function(diagnostics)
  if not diagnostics then return end

  local diagnostics_by_line = {}
  for _, diagnostic in ipairs(diagnostics) do
    local start = diagnostic.range.start -- <= Line 220
    local line_diagnostics = diagnostics_by_line[start.line]
    if not line_diagnostics then
      line_diagnostics = {}
      diagnostics_by_line[start.line] = line_diagnostics
    end
    table.insert(line_diagnostics, diagnostic)
  end
  return diagnostics_by_line
end

I'm not really familiar enough with the protocol to be of much help, unfortunately. :/
My guess is that it's being called by the set_virtual_text function in the runtime, which calls that function.

Prince781 added a commit that referenced this issue Mar 5, 2021
If a diagnostic is not associated with a file, associate it with the
project root folder, rather than sending "null"
@Prince781
Copy link
Member

@EbonJaeger try again now

@HiPhish
Copy link

HiPhish commented Mar 5, 2021

I get a seqfault:

$ guix environment vala-language-server

$ meson  -Dprefix=$HOME/Desktop/vls build
The Meson build system
Version: 0.53.2
Source dir: /home/hiphish/Applications/lsp/vala-language-server
Build dir: /home/hiphish/Applications/lsp/vala-language-server/build
Build type: native build
Project name: vala-language-server
Project version: 0.48.1
C compiler for the host machine: cc (gcc 10.2.1 "cc (GCC) 10.2.1 20201203")
C linker for the host machine: cc ld.bfd 2.34
Vala compiler for the host machine: valac (valac 0.50.2)
Host machine cpu family: x86_64
Host machine cpu: x86_64
Found pkg-config: /gnu/store/4spqmyviwbb9kawcf2mrdsiz8ic41k66-profile/bin/pkg-config (0.29.2)
Run-time dependency libvala-0.50 found: YES 0.50.2
Run-time dependency gobject-2.0 found: YES 2.62.6
Run-time dependency jsonrpc-glib-1.0 found: YES 3.33.3
Run-time dependency glib-2.0 found: YES 2.62.6
Run-time dependency gio-2.0 found: YES 2.62.6
Run-time dependency gee-0.8 found: YES 0.20.3
Run-time dependency json-glib-1.0 found: YES 1.4.4
Library posix found: YES
Configuring config.vala using configuration
Run-time dependency gio-unix-2.0 found: YES 2.62.6
Found pkg-config: /gnu/store/4spqmyviwbb9kawcf2mrdsiz8ic41k66-profile/bin/pkg-config (0.29.2)
Found CMake: /usr/bin/cmake (3.19.4)
Build-time dependency scdoc found: NO (tried pkgconfig and cmake)
Program sh found: YES (/gnu/store/4spqmyviwbb9kawcf2mrdsiz8ic41k66-profile/bin/sh)
Program sed found: YES (/gnu/store/4spqmyviwbb9kawcf2mrdsiz8ic41k66-profile/bin/sed)
Program gnome-builder found: NO
plugins/gnome-builder/meson.build:15: WARNING: Assuming version 3.38 for GNOME Builder plugin ABI
Configuring vala_langserv.plugin using configuration
Build targets in project: 2

Found ninja-1.10.0 at /gnu/store/4spqmyviwbb9kawcf2mrdsiz8ic41k66-profile/bin/ninja

$ ninja -C build
ninja: Entering directory `build'
[33/33] Linking target src/vala-language-server.

$ ./build/src/vala-language-server
Segmentation fault

The same happens on master as well, so it's probably unrelated to your changes. I am on Void Linux, but I use Guix as a secondary package manager.

@EbonJaeger
Copy link
Author

Everything seems to be working fine for me now. :D

@Prince781
Copy link
Member

@HiPhish I think you should produce a stack trace and then create a new bug report.

Prince781 added a commit that referenced this issue Mar 5, 2021
If a diagnostic is not associated with a file, associate it with the
project root folder, rather than sending "null"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants