Skip to content

Commit

Permalink
feat: use existing hxml for haxe ls configuration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tobil4sk committed Aug 25, 2024
1 parent 9e0b5c5 commit dc97f6c
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lua/lspconfig/server_configurations/haxe_language_server.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
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' },
Expand All @@ -10,9 +16,21 @@ return {
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
print 'displayArguments already set. Skipping'
return
end

local hxml = find_hxml(new_root_dir)[1]
if hxml then
print('setting hxml configuration: ' .. hxml)
new_config.init_options.displayArguments = { hxml }
else
print 'No hxml file found'
end
end,
},
docs = {
description = [[
Expand All @@ -36,12 +54,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", ".git")]],
init_options = 'default value is set by on_new_config',
},
},
}

0 comments on commit dc97f6c

Please sign in to comment.