tzachar / cmp-tabnine

TabNine plugin for hrsh7th/nvim-cmp
MIT License
286 stars 27 forks source link

How to open Tabnine Hub on a headless server? #58

Closed zhyu closed 2 years ago

zhyu commented 2 years ago

I know run the command CmpTabnineHub actually starts an app listens on port 5555, I could use ssh port forwarding to access it. However, I think the hub needs to be accessed via localhost:5555/a-random-string, so without knowing the random string, the webapp doesn't load.

Could cmp-tabnine get response from tabnine server and print the connection string after running CmpTabnineHub?

tzachar commented 2 years ago

I don't think TabNine supports this. As TabNine uses xdg-open with the url, you can circumvent the issue by having your own xdg-open available in your PATH before starting nvim, and logging the arguments sent to it to solve your issue.

zhyu commented 2 years ago

Good point about xdg-open, I will give it a try later.

Before switching to nvim-cmp, I have been using coc.nvim. And the extension to coc.nvim for Tabnine is https://github.com/neoclide/coc-tabnine, which configures Tabnine via special commands. It does tell me the URL I should visit to open the Hub: image

So I think maybe the server responses to the config call with the URL somehow?

zhyu commented 2 years ago

So I tried to dump the response from Tabnine after sending the config command to it, and got the following:

{
  message = {
    reason = "Couldn't start web browser at http://127.0.0.1:5555/sec-fxdeccwilpzmniggbpdi. See https://tabnine.com/faq#browser_failed"
  },
  status = "Failure"
}

Accessing the URL above with ssh port forwarding works as expected.

I think it's possible for the plugin to handle the response and display it.

zhyu commented 2 years ago

I just found if we send quite = true when opening the hub, TabNine returns the following:

{
  message = "http://127.0.0.1:5555/sec-ssgemthelgmbjhgpscax",
  status = "Success"
}

So one alternative is: having a new command other than CmpTabnineHub (or let user config the behavior) to start the server without calling xdg-open, and then tells user the URL.

Maybe it's better than #59, @tzachar what do you think about it?