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

Autocompletion doesn't detect newly created files and directories unless I restart the language server. #2460

Closed
anthony-S93 opened this issue Feb 14, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@anthony-S93
Copy link
Contributor

anthony-S93 commented Feb 14, 2023

Description

To illustrate the issue, I will start with a simple directory with two files (test.py and mod.py).
When I open test.py and try to import mod.py, everything works fine (the completion engine detects mod.py just fine)
2023-02-14-213727_824x452_scrot

But now, if I add a new file (newmod.py) to the directory, the completion engine fails to detect the new file.
2023-02-14-213922_712x284_scrot

Until I restart the language server by running :LspRestart, the completion engine will not detect newly added files.

Needless to say, having to run :LspRestart every time I add a new file to my working directory is a tad annoying. I suspect that the issue lies with pyright (because I didn't notice this issue with other language servers such as jdtls; only pyright is affected AFAIK), though I'm not entirely certain.

There are similar reports made here and here.

Neovim version

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

Nvim-lspconfig version

No response

Operating system and version

EndeavourOS (Linux Kernel 6.1.11-arch1-1)

Affected language servers

pyright

Steps to reproduce

  1. Create a test directory ~/code/
  2. cd ~/code
  3. touch test.py mod.py
  4. nvim test.py
  5. Attempt to import mod.py from inside test.py and verify that the completion engine is working.
  6. Now, open another terminal (so that we can use the same neovim session we used in step 5) and cd into ~/code again.
  7. touch newmod.py
  8. Go back to neovim and try to import newmod.py from test.py

Actual behavior

Completion engine does not detect newly added files, modules, and directories for Pyright.

Expected behavior

Completion engine detects newly added files and directories.

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 lspconfig_path = join_paths(package_root, 'test', 'start', 'nvim-lspconfig')

if vim.fn.isdirectory(lspconfig_path) ~= 1 then
  vim.fn.system { 'git', 'clone', 'https://github.com/neovim/nvim-lspconfig', lspconfig_path }
end

vim.lsp.set_log_level 'trace'
require('vim.lsp.log').set_format_func(vim.inspect)
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 = 'pyright'
local cmd = { 'pyright-langserver', '--stdio' } -- needed for elixirls, lua_ls, omnisharp
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 {
  cmd = cmd,
  on_attach = on_attach,
}

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.]]

LSP log

--

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
Development

No branches or pull requests

2 participants