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

autostart=false: server does not automatically attach when editing new, nonexistent file #2711

Open
Diomendius opened this issue Jul 12, 2023 · 1 comment · Fixed by #2712 · May be fixed by #3355
Open

autostart=false: server does not automatically attach when editing new, nonexistent file #2711

Diomendius opened this issue Jul 12, 2023 · 1 comment · Fixed by #2712 · May be fixed by #3355
Labels
bug Something isn't working

Comments

@Diomendius
Copy link
Contributor

Description

When autostart = false and any language server has been manually started, editing an existing file of a compatible file type automatically attaches the server to the new buffer, but editing a nonexistent file (with the appropriate extension such that filetype is automatically set to a compatible filetype) does not attach the server.

When autostart = true, language servers automatically attach to buffers regardless of whether the buffer is backed by an existing file.

Neovim version

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

Nvim-lspconfig version

deade69

Operating system and version

Arch Linux, up to date as of 2023-07-09

Affected language servers

all

Steps to reproduce

This assumes Pyright is installed, though these steps and the provided config should be simple to adapt to any language server, as this issue is specific to nvim-lspconfig, not any language server.

  1. touch foo.py
  2. nvim -nu minimal_init.lua foo.py
  3. :LspStart
  4. :LspInfo, observe that pyright is attached to the current buffer and the workspace root is the current working directory.
  5. :e bar.py
  6. :LspInfo, observe that no language server is attached.
  7. :w
  8. :e
  9. :LspInfo, observe that pyright is attached to the current buffer.

Actual behavior

At step 6, the language server has not attached to the newly opened buffer.

Expected behavior

Already-started language servers should automatically attach to all compatible files within their workspace, not just those that already exist.

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'

nvim_lsp.pyright.setup {
  cmd = { 'pyright-langserver', '--stdio' },
  on_attach = on_attach,
  autostart = false,
  root_dir = function() return vim.fn.getcwd() end,
}

LSP log

https://gist.github.com/Diomendius/e359bacac0b4db45f0cf0a1b1cdc26aa

@Diomendius
Copy link
Contributor Author

As #3347 reverted the fix for this, this should be reopened until a better fix is implemented.

@glepnir glepnir reopened this Oct 4, 2024
@justinmk justinmk changed the title Server does not automatically attach when editing nonexistent file in workspace when autostart = false autostart=false: server does not automatically attach when editing new, nonexistent file Oct 4, 2024
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