LuaLS / LuaLS/lua-language-server

Renamed file considered deleted inside directory junction

未關閉
#3,279 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Lua
星號
4.4k
分支
442
PR 合併指標
30 天內沒有已合併 PR

描述

### How are you using the lua-language-server?

NeoVim

### Which OS are you using?

Windows

### What is the issue affecting?

Other

### Expected Behaviour

LS correctly works with files inside directory junction or symlinks.

### Actual Behaviour

LS functionality stops working after saving such a file in editor.

### Reproduction steps

1. Enable LuaLS in NeoVim.
2. Put NeoVim config files inside directory junction. E.g. I have `init.lua` file in directory `C:\dev\dotfiles\nvim` and I've created the junction to that directory in `C:\Users\RobotComp.ru\AppData\Local\nvim`. NVim reads config files from `C:\Users\RobotComp.ru\AppData\Local\nvim`.
3. Open `init.lua` in NVim, change something and save it with `:w` command.
4. After that, **any interactions with LS stop working** (hover, go to definition, etc.)
5. If I re-edit file with `:e %` command, everything starts working again.

### Additional Notes

I did some research and found the following.

When saving `init.lua`, NVim renames it several times (to `init.lua~` and back). Don't know why.
The logs (see error.log) show that the `filewatch(rename)` function is called on LS, which calls `isExists()`.
And although the file exists, `isExists()` returns false, so the file is considered deleted, and the LS "forgets" about it.

More specifically, the problem occurs in `script/filewatch.lua:18`:

```
if res :string():gsub('^%w+:', string.lower)
~= path:string():gsub('^%w+:', string.lower) then
return false
end
```

Here, it turns out that `res` contains the actual path to the file (`C:\dev\dotfiles\nvim\init.lua`), and `path` contains the path with the junction (`C:\Users\RobotComp.ru\AppData\Local\nvim\init.lua`).

Commenting out these lines makes everything work correctly (see fixed.log). However, I didn't make a PR with such changes because I didn't fully understand why this path comparison was needed at all. It seems like it fixes some other bug?

Thanks in advance :)

### Log File

[00:20:20.415][debug][#0:script\filewatch.lua:98]: filewatch: rename C:\Users\RobotComp.ru\AppData\Local\nvim\init.lua
[00:20:20.415][debug][#0:script\filewatch.lua:98]: filewatch: modify C:\Users\RobotComp.ru\AppData\Local\nvim\init.lua
[00:20:20.415][debug][#0:script\filewatch.lua:98]: filewatch: rename C:\Users\RobotComp.ru\AppData\Local\nvim\init.lua~
**[00:20:20.415][debug][#0:script\workspace\workspace.lua:592]: FileChangeType.Deleted file:///c%3A/Users/RobotComp.ru/AppData/Local/nvim/init.lua**
[00:20:20.416][debug][#0:script\workspace\workspace.lua:592]: FileChangeType.Deleted file:///c%3A/Users/RobotComp.ru/AppData/Local/nvim/init.lua~

[error.log](https://github.com/user-attachments/files/22867004/error.log)
[fixed.log](https://github.com/user-attachments/files/22867005/fixed.log)

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

在 Windows 上使用透過目錄聯接儲存的 NeoVim 設定重現該問題,然後閱讀 script/filewatch.lua:18,並追蹤記錄中顯示的重新命名處理。完成的標準是:儲存 init.lua 不再導致 language server 將聯接路徑視為已刪除,同時 hover 和 go-to-definition 繼續正常運作。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua, neovim
領域
tooling
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。