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

lua lsp uses always current work dir when LSP initalized when editing file #512

Closed
Konfekt opened this issue May 16, 2024 · 3 comments · May be fixed by #562
Closed

lua lsp uses always current work dir when LSP initalized when editing file #512

Konfekt opened this issue May 16, 2024 · 3 comments · May be fixed by #562

Comments

@Konfekt
Copy link
Contributor

Konfekt commented May 16, 2024

According to the LSP logs, the root directory is always that of the current working directory when the LSP was added:
In /path/to/lua-language-server/log/ a log file for this working directory shows up containing

  rootPath = "/home/konfekt",
  rootUri = "file:///home/konfekt/",

after Vim was started in ~/, editing a file in a project dir below ~/, throwing an error that more than 100000 files were scanned.

Instead, one would expect the rootPath to be set to the current working directory.

According to https://luals.github.io/wiki/faq/#why-is-the-server-scanning-the-wrong-folder

When not using Visual Studio Code, check the rootUri field in your configuration - some clients allow users to customize this value. If the value is correct or cannot be modified, please report the issue to the developer of the client you are using.

I am using latest LSP master and Vim 9.1.369 on Ubuntu 22.04

@Konfekt
Copy link
Contributor Author

Konfekt commented May 16, 2024

For the time being, a partial workaround is defering the addition of the lua server up to the point that a Lua file has been openend and the project root set as work dir by adding to ftplugin/lua.vim lines such as

if !empty(FugitiveGitDir()) | Glcd | endif
if !exists('##vimrcFileTypeLuaLsp')
  augroup vimrcFileTypeLuaLsp
  autocmd BufWinEnter <buffer> call LspAddServer(lspLuaServers)
   \ | autocmd! vimrcFileTypeLuaLsp
  augroup END
endif

where vimrc defines

  let lspLuaServers = [
	      \ #{ name: 'lua',
        \    filetype: ['lua'],
        \    path: 'lua-language-server'
        \ }]

@Konfekt
Copy link
Contributor Author

Konfekt commented Sep 28, 2024

Is there a better workaround to change the current work dir from the initial one (the current work at the start of vim)?
For example, when loading a session or opening a file outside of the repo.

@Konfekt
Copy link
Contributor Author

Konfekt commented Sep 28, 2024

Cleaner would be to set up FileType autocmds depending on filetype: ['...'] in g:lspServers.

@Konfekt Konfekt closed this as completed Sep 28, 2024
Konfekt added a commit to Konfekt/lsp that referenced this issue Sep 28, 2024
Only set workspace root once the first file of that file type is opened;
otherwise the workspace root often is $HOME (say when using Gvim, or
opening a file in a Git repo) and the LS scans too many files

Partially resolves [0]
as ideally this workspace root would automatically change with the CWD,
in particular after loading a session (:h mksession)

Links:

[0]: yegappan#512
Konfekt added a commit to Konfekt/lsp that referenced this issue Sep 28, 2024
Only set workspace root once the first file of that file type is opened;
otherwise the workspace root often is $HOME (say when using Gvim, or
opening a file in a Git repo) and the LS scans too many files

Partially resolves [0]
as ideally this workspace root would automatically change with the CWD,
in particular after loading a session (:h mksession)

Links:

[0]: yegappan#512
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant