mirror of
https://github.com/neovim/nvim-lspconfig
synced 2024-09-16 14:24:07 +02:00
feat: improve default haxe_language_server init_options (#3284)
* feat: add '.git' as root pattern for haxe_language_server * feat: use existing hxml for haxe ls configuration Previously, it would detect the root dir by matching with "*.hxml", however, it would use "build.hxml" as the default `displayArguments` even though it may not exist. This could cause the error: ``` haxe_language_server: -32603: Error: Could not process argument build.hxml (file not found) Invalid character: ``` Now it will use the first ".hxml" file that is found in the project. It will only do this if no `displayArguments` value has been set in the `setup()` call, so it will still respect user set values. If no hxml file is found, then it uses empty `displayArguments`, which is still better than a broken configuration.
This commit is contained in:
parent
911167921d
commit
acf17dc452
1 changed files with 35 additions and 8 deletions
|
@ -1,18 +1,33 @@
|
|||
local util = require 'lspconfig.util'
|
||||
|
||||
local function find_hxml(path)
|
||||
return vim.fs.find(function(name)
|
||||
return name:match '.hxml$'
|
||||
end, { path = path, type = 'file' })
|
||||
end
|
||||
|
||||
return {
|
||||
default_config = {
|
||||
cmd = { 'haxe-language-server' },
|
||||
filetypes = { 'haxe' },
|
||||
root_dir = util.root_pattern '*.hxml',
|
||||
root_dir = util.root_pattern('*.hxml', '.git'),
|
||||
settings = {
|
||||
haxe = {
|
||||
executable = 'haxe',
|
||||
},
|
||||
},
|
||||
init_options = {
|
||||
displayArguments = { 'build.hxml' },
|
||||
},
|
||||
init_options = {},
|
||||
on_new_config = function(new_config, new_root_dir)
|
||||
if new_config.init_options.displayArguments then
|
||||
return
|
||||
end
|
||||
|
||||
local hxml = find_hxml(new_root_dir)[1]
|
||||
if hxml then
|
||||
vim.notify('Using HXML: ' .. hxml)
|
||||
new_config.init_options.displayArguments = { hxml }
|
||||
end
|
||||
end,
|
||||
},
|
||||
docs = {
|
||||
description = [[
|
||||
|
@ -36,12 +51,24 @@ lspconfig.haxe_language_server.setup({
|
|||
})
|
||||
```
|
||||
|
||||
By default, an HXML compiler arguments file named `build.hxml` is expected in
|
||||
your project's root directory. If your file is named something different,
|
||||
specify it using the `init_options.displayArguments` setting.
|
||||
By default, the language server is configured with the HXML compiler arguments
|
||||
contained in the first `.hxml` file found in your project's root directory.
|
||||
If you want to specify which one to use, set the `init_options.displayArguments`
|
||||
setting:
|
||||
|
||||
```lua
|
||||
lspconfig.haxe_language_server.setup({
|
||||
-- ...
|
||||
init_options = {
|
||||
displayArguments = { "build.hxml" },
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
]],
|
||||
default_config = {
|
||||
root_dir = [[root_pattern("*.hxml")]],
|
||||
root_dir = [[root_pattern("*.hxml", ".git")]],
|
||||
init_options = 'default value is set by on_new_config',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue