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

denols: jumping to definition then returning breaks lsp #1998

Closed
sigmaSd opened this issue Jul 13, 2022 · 3 comments · Fixed by #2000 or #2070
Closed

denols: jumping to definition then returning breaks lsp #1998

sigmaSd opened this issue Jul 13, 2022 · 3 comments · Fixed by #2000 or #2070
Labels
bug Something isn't working

Comments

@sigmaSd
Copy link
Contributor

sigmaSd commented Jul 13, 2022

Description

jumping to definition then returning breaks lsp
denovim

coc-deno used to have the same issue but it was recently fixed fannheyward/coc-deno#139

Neovim version

NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3

Nvim-lspconfig version

41a8269

Operating system and version

Linux mrcool 5.18.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 02 Jul 2022 21:03:06 +0000 x86_64 GNU/Linux

Affected language servers

denols

Steps to reproduce

  1. echo "console.log(4)" > test.ts
  2. nvim test.ts
  3. move cursor to log and press gd to go to definition
  4. press ctrl-o to return

Actual behavior

Notice that lsp is not working correctly any more and have errors and the console and log have type any

Expected behavior

the lsp should continue working correctly.

Minimal config

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.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 function load_plugins()
    require('packer').startup {
        {
            'wbthomason/packer.nvim',
            'neovim/nvim-lspconfig',
        },
        config = {
            package_root = package_root,
            compile_path = compile_path,
        },
    }
end

_G.load_config = function()
    vim.lsp.set_log_level 'trace'
    if vim.fn.has 'nvim-0.5.1' == 1 then
        require('vim.lsp.log').set_format_func(vim.inspect)
    end
    local nvim_lsp = require 'lspconfig'
    local on_attach = function(_, bufnr)
        local function buf_set_option(...)
            vim.api.nvim_buf_set_option(bufnr, ...)
        end

        buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

        -- Mappings.
        local opts = { buffer = bufnr, noremap = true, silent = true }
        vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
        vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
        vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
        vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
        vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
        vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
        vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
        vim.keymap.set('n', '<space>wl', function()
            print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
        end, opts)
        vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
        vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
        vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
        vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
        vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
        vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
        vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
    end

    -- Add the server that troubles you here
    local name = 'denols'
    if not name then
        print 'You have not defined a server name, please edit minimal_init.lua'
    end
    if not nvim_lsp[name].document_config.default_config.cmd and not cmd then
        print [[You have not defined a server default cmd for a server
      that requires it please edit minimal_init.lua]]
    end

    nvim_lsp[name].setup {
        on_attach = on_attach,
        single_file_support = true,
    }

    print [[You can find your log at $HOME/.cache/nvim/lsp.log. Please paste in a github issue under a details tag as described in the issue template.]]
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()
    vim.cmd [[autocmd User PackerComplete ++once lua load_config()]]
else
    load_plugins()
    require('packer').sync()
    _G.load_config()
end

LSP log

https://gist.github.com/sigmaSd/dbfd52efc9cf4f96e3e237f3cf65d9e8

@sigmaSd sigmaSd added the bug Something isn't working label Jul 13, 2022
@sigmaSd
Copy link
Contributor Author

sigmaSd commented Jul 13, 2022

@justinmk
Copy link
Member

#1995

@sigmaSd
Copy link
Contributor Author

sigmaSd commented Jul 14, 2022

This is not fixed by #1995

In my testing it's fixed by commenting out this line https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/denols.lua#L38

sigmaSd added a commit to sigmaSd/nvim-lspconfig that referenced this issue Jul 14, 2022
fix neovim#1998

I don't have a good idea *how* do this fixes the issue, but so far in my testing with this pr it seems to work perfectly.
@justinmk justinmk reopened this Jul 14, 2022
justinmk pushed a commit that referenced this issue Jul 17, 2022
- remove unneeded lsp attach
- default to single_file_support=true

fix #1998
justinmk pushed a commit that referenced this issue Aug 23, 2022
I found the root cause of denols problems:
neovim/neovim#19797

With that pr applied (and with this revert) denols works perfectly
almost identical to vscode deno, its missing some features but I imagine
those are out of scope for lspconfig.

Problems will reappear until nvim fixes:
#1998

This is an ok tradeoff because `single_file_support=true`
causes other issues:
#2069
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants