Skip to content

Commit

Permalink
fix(zls): inclide build.zig in root dir search
Browse files Browse the repository at this point in the history
File `build.zig` by convention sits at the root dir and thus can be used
to correctly identify the root directory.

This is particularly useful if `zls` has `enable_build_on_save` set to
`true`, since then the language server uses workspace path (root_dir) to
execute `zig build` command, output of which is then used to publish
diagnostic errors.

Without `build.zig` root directory can incorrectly be deduced some
layers too high at the root of the git repo. In such case
`enable_build_on_save` silently fails and does not report build error
diagnostics.
  • Loading branch information
lawrence-laz committed Dec 18, 2023
1 parent e50a8fc commit 6e200c6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/server_configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12048,7 +12048,7 @@ require'lspconfig'.zls.setup{}
```
- `root_dir` :
```lua
util.root_pattern("zls.json", ".git")
util.root_pattern("zls.json", "build.zig", ".git")
```
- `single_file_support` :
```lua
Expand Down
2 changes: 1 addition & 1 deletion doc/server_configurations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12048,7 +12048,7 @@ require'lspconfig'.zls.setup{}
```
- `root_dir` :
```lua
util.root_pattern("zls.json", ".git")
util.root_pattern("zls.json", "build.zig", ".git")
```
- `single_file_support` :
```lua
Expand Down
4 changes: 2 additions & 2 deletions lua/lspconfig/server_configurations/zls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ return {
default_config = {
cmd = { 'zls' },
filetypes = { 'zig', 'zir' },
root_dir = util.root_pattern('zls.json', '.git'),
root_dir = util.root_pattern('zls.json', 'build.zig', '.git'),
single_file_support = true,
},
docs = {
Expand All @@ -14,7 +14,7 @@ https://github.com/zigtools/zls
Zig LSP implementation + Zig Language Server
]],
default_config = {
root_dir = [[util.root_pattern("zls.json", ".git")]],
root_dir = [[util.root_pattern("zls.json", "build.zig", ".git")]],
},
},
}

0 comments on commit 6e200c6

Please sign in to comment.