vshaxe/vshaxe

Using haxe-language-server with coc.nvim

vushu opened this issue ยท 31 comments

vushu commented

Hi I would really like some description on how to build the haxe language server or/and get a compiled release of the server.

Help would be appreciated.

cheers!

For building, see https://github.com/vshaxe/vshaxe/wiki/Installation#from-source.

Binaries of the language server are shipped with the VSCode extension, so you could just grab server/bin/server.js from there.

Are you trying to use the language server in another editor? :)

Oh, and building the whole stack probably requires a Haxe 4 nightly build at the moment. The language-server itself is probably fine with Haxe 4 rc.1 (haxelib run vshaxe-build --target language-server).

vushu commented

Thanks alot! Yes I try to use it together with neovim :)

Have you already seen all the discussion in #171?

vushu commented

Yes I have, I wasn't sure about how to use vshaxe-build.

Closing here for now, let me know if you have any more questions. :)

vushu commented

I didnt manage to get it working, using https://github.com/autozimu/LanguageClient-neovim
While Reading the thread you linked to, I ended up using vaxe from the branch neovaxe which should be using this language server, but it doesnt seem to work well.

Hm, I'm not sure what the state of that branch is.. (I don't think I was even aware that it exists. :)) Perhaps @jdonaldson can comment on that?

vushu commented

It would be soo sweet if haxe language server could be integrated with https://github.com/neoclide/coc.nvim, it looks quite promising, it's an all in one solution for autocompletion for vim and neovim, with easy installation.

I have also tried to use this language server, with coc.nvim but still getting some errors, I am not sure why, but i managed to get kotlin language server working.

Damn, how many language client implementations are there for Neovim at this point? I feel like there must be at least five or so. :D

vushu commented

https://github.com/autozimu/LanguageClient-neovim
https://github.com/neoclide/coc.nvim
https://github.com/prabirshrestha/vim-lsp
https://github.com/natebosch/vim-lsc
https://spacevim.org/layers/language-server-protocol/

way too many for my taste I just wan't to stick with one, the thing is none of them works with haxe-language-server out of the box and I have been tinkering soo much around with different kinds. It just bothers me that haxe isn't well implemented in just one of them :/

IIRC, there were some issues because haxe-language-server waits until the first onDidChangeConfiguration event to start haxe.exe, and some implementations don't send that at all, or only when configured to do so.

IIRC there were some underlying differences between the way that haxe lanuage server and the way LanguageClient-neovim interpreted spec. I tried to point out what needed to change, but it got pretty complex, and I came away thinking it was still a bit too early to tackle it. Maybe that's changed now?

vushu commented

neoclide/coc.nvim#510 (comment)

The author of coc.nvim says the server doesnt respond to the completion request and can do nothing ๐Ÿ˜“

Hm, there isn't a workspace/didChangeConfiguration notification in that log file, which probably confirms my earlier suspicions. haxe-language-server probably shouldn't rely on that / I've been wanting to look into using the workspace/configuration request instead.

there isn't a workspace/didChangeConfiguration notification in that log file

The settings is null so the client doesn't send them to avoid issues.
Some language server would crash when have empty configurations.

@vushu you can add "settings":{"haxe.executable": "haxe"} to the language server configuration to make it send didChangeConfiguration.

vushu commented

Thanks for the response @chemzqm somethings did change, I now get a timeout
[coc.nvim] source languageserver.haxe timeout after 2000ms
when looking at the log I see that the server responded

[Trace - 04:16:25] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Haxe version does not support JSON-RPC, using legacy --display API."
}

looks like the server is kind of picky?

#my channel output:
output_channel2.txt

That message doesn't indidcate that completion won't work, merely that it has to use Haxe's old API for it (haxe-language-server works best with Haxe 4). So the issue must be elsewhere.

vushu commented

Using haxe 4.0.0-rc.1+1fdd3d5

I get this following log:
output_channel3.txt

Ok, that's more expected. It can't find the library types because you didn't give it any display configuration (the auto-detection of HXML files and all that happens in the VSCode extension, not in the language server).

The way this normally works is by setting the displayArguments field in the initialize options. In your log, it seems that coc.nvim simply sends any empty object here:

"initializationOptions": {}

You would want something like "initializationOptions": {"displayArguments": ["build.hxml"]} there. I'm not sure if coc.nvim allows customizing that.

vushu commented

I think after updating to haxe 4, I am getting some imports, so we must be getting closer.

Screenshot from 2019-03-12 17-15-04

When looking at:
https://github.com/neoclide/coc.nvim/wiki/Language-servers#register-custom-language-servers
I looks like it's possible, but doesn't seem to work,

log after adding initializationOptions:
output_channel4.txt

I am seeing initializationOptions in that log actually:

"initializationOptions": {
    "displayArguments": [
           "build.hxml"
    ]
}

Or do you just mean it doesn't have any effect on the language server?

Hm, this is strange:

[Trace - 17:24:47] Received notification 'window/logMessage'.
Params: {
    "type": 4,
    "message": "Failed - try fixing the error(s) and restarting the language server:\n\nError: Could not process argument build.hxml (file not found)\ninvalid character:"
}
vushu commented

I finally made a breakthrough :D
I just renamed my heaps project compile.hxml to build.hxml
Screenshot from 2019-03-12 17-50-38
It freaking works! Thanks so much guys :D

vushu commented

Here is my coc-settings.json file:

{
  "languageserver": {
    "haxe": {
      "command": "node",
      "args": ["/<you-home-folder>/.vscode/extensions/nadako.vshaxe-2.7.0/server/bin/server.js"],
      "filetypes": ["haxe"],
      "trace.server": "verbose",
      "initializationOptions": {
        "displayArguments": ["build.hxml"]
      },
      "settings": {
        "haxe.executable":"haxe"
      }
    }
  }
}

Important to do a haxelib install in the project, and having a build.hxml

Are you sure you want to have both "build.hxml" and "compile.hxml" in there? Presumably only one of the files exists?

vushu commented

Well yeah, you could just leave it with only build.hxml, since that is more commonly used I guess, I was just following heaps guides where they used compile.hxml naming.๐Ÿ˜Š

I mean, "displayArguments": ["compile.hxml"] should be fine too, but I'm not sure why you'd want to have both. :)

vushu commented

I just thought I was using it as fallback, if the other doesnt exist, (changed above comment). ๐Ÿ˜

Thanks again for sharing your config - I've added it the readme of haxe-language-server: https://github.com/vshaxe/haxe-language-server#usage-with-neovim

vushu commented

Cool, glad that I could help ๐Ÿ˜Š