LuaLS / LuaLS/lua-language-server

`workspace/symbols` doesn't seem to respect workspaces or rootUri / root_dir

Đang mở
#2,456 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Lua
Star
4.4k
Fork
442
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

NeoVim

### Which OS are you using?

MacOS

### What is the issue affecting?

Other

### Expected Behaviour

1. Results should only come from the current project, i.e. that rooted at root_dir, or at the very least only come from the listed workspace folders.
2. All symbols appearing in the files named by the above condition should appear in the results (at least, `document/symbols` should be a subset of `workspace/symbols` for any document in the current project)

### Actual Behaviour

1. Most results come outside root_dir; in fact, most results come from outside any workspace folder, meaning that the results are essentially global.
2. Some expected results from within the current workspace don't appear.

For evidence of (1), here's some results from`vim.lsp.buf.workspace_symbol()`:

```
# current project, which matches root_dir and is a configured workspace
lua/neogit/status.lua|653 col 3| [Variable] vim.o.autochdir

# from my nvim config, which is not the current root_dir but is a configured workspace
/Users/neilvyas/.config/nvim/lua/plugins/modes.lua|61 col 9| [Variable] vim.opt.background

# from random lua files anywhere on my system; from outside of root_dir or any workspace
/Users/neilvyas/.local/share/nvim/mason/packages/lua-language-server/libexec/meta/Lua 5.4 en-us utf8/io.lua|171 col 11| [Class] file*

```

For evidence of (2), we can see that `document/symbols` returns results which `workspace/symbols` does not (this is actually what clued me into this being a possible bug). For example, the following result from `document/symbols`, issued from `lua/neogit/status.lua`, does not appear in `workspace/symbols`:

```
lua/neogit/status.lua|506 col 16| [Function] refresh_status_buffer
```

### Reproduction steps

1. Configure lua_ls using the recommended instructions from `mason.nvim` https://github.com/williamboman/mason.nvim#configuration, `mason-lspconfig.nvim` https://github.com/williamboman/mason-lspconfig.nvim, and `lspconfig.nvim` https://github.com/neovim/nvim-lspconfig.
2. Edit a lua buffer.
3. Issue `vim.lsp.buf.workspace_symbol()`

### Additional Notes

You might think that this issue stems from neovim's LSP client; however, the code related to workspace/symbols is so minimal that I doubt the error arises there: https://github.com/neovim/neovim/blob/v0.8.1/runtime/lua/vim/lsp/handlers.lua#L253

From my cursory investigation of lua_ls's implementation, it seems like the issue might be to do with how `allGlobals` is populated, since this is ultimately what populates workspace/symbols: https://github.com/LuaLS/lua-language-server/blob/f836d90eb629c22219cbcdff9bfcd7f45f1751f3/script/vm/global.lua#L209

What follows are selections from the output of `vim.print(vim.lsp.get_client_by_id(1))`, which shows a bunch of data related to how `lua_ls` is configured by and attached to neovim.

Here, you can see that the root_dir is set properly for the current buffer (editing the neogit plugin), and there are workspaces corresponding to the other buffers I have open (the detour.nvim plugin and editing my neovim configuration, which is written in lua):

image

This seems to be the problem referenced by the only similar issue I found, #1731 , but I think it indicates that, in fact, that issue does not apply any more, and I cannot udnerstand what the resolution in that issue was anyway.

Here, you can see that the workspace related capabilities seem to be setup properly:

image

### Log File

_No response_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với phần triển khai workspace/symbols và việc điền allGlobals được tham chiếu trong script/vm/global.lua. Tái hiện vấn đề thông qua vim.lsp.buf.workspace_symbol() của Neovim bằng thiết lập workspace đã nêu, sau đó so sánh kết quả với document/symbols. Được xem là hoàn tất khi kết quả chỉ giới hạn trong phạm vi workspace đã cấu hình và bao gồm các symbol được document/symbols tìm thấy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
lua, neovim
Lĩnh vực
developer-experience, tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.