codota / tabnine-nvim

Tabnine Client for Neovim
https://tabnine.com
342 stars 31 forks source link

[FEATURE] Ability to fix the workspace directory (to workaround using autochdir #152

Closed allan-simon closed 6 months ago

allan-simon commented 7 months ago

Is your feature request related to a problem? Please describe.

Currently Tabnine seems to my current working directory for the "workspace" used by TabnineChat

However my vim settings use "autochdir" , so Tabnine seems to only take as "workspace" the current directory of my current active panel

Describe the solution you'd like

I would like to be able to hardwire it

Describe alternatives you've considered

it can also search for .git directory

amirbilu commented 7 months ago

@allan-simon I was thinking a lot before setting it to getcwd() but could not think of anything better. How would an API for choosing a workspace could look like in your opinion?

aarondill commented 7 months ago

would something like vim.lsp.buf.list_workspace_folders()[1] or getcwd() work?

allan-simon commented 7 months ago

exactly , lsp has already all the internal mechanism to determine the workspace root directory so you don't need to reimplement it on your side :)

https://github.com/neovim/nvim-lspconfig/tree/master/lua/lspconfig/server_configurations

https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/tsserver.lua#L15 for example here it will determine the root directory as any parent directory with a package.json or a .git

amirbilu commented 7 months ago

If list_workspace_folders is stable API that would be great. BTW - Tabnine knows to index multiple workspaces at once. So no need for [1]. I'm ooo today.. so will issue a PR tomorrow

aarondill commented 7 months ago

@amirbilu i believe that list_workspace_folders is stable. btw, it may return an empty table (if no lsp detects a root), so it may be a good idea to check the length and default to the cwd if it's empty

allan-simon commented 7 months ago

at least it is listed on their documentation https://neovim.io/doc/user/lsp.html#lsp-api

amirbilu commented 7 months ago

so I've been looking at list_worpskace_folders and it seems to be working, but only when lsp is ready, which means we need to into to trigger inside the lsp on_attach, this can be done but it means tabnine setup will be a bit more complicated now. What's your perspective on this?

allan-simon commented 7 months ago

Personally it's ok if tabnine does not start "straight" away (the same as for lsp) as it enhance my workflow and is not a vital part of it (I mean I code if during 3 seconds of my session I don't have LSP or Tabnine )

amirbilu commented 7 months ago

so what are you suggesting? polling?

allan-simon commented 7 months ago

https://github.com/rcarriga/nvim-notify/wiki/Usage-Recipes/#lsp-status-updates

does something like this will work ?

vim.lsp.handlers["$/progress"] = function(_, result, ctx)
 local client_id = ctx.client_id

 local val = result.value

 if not val.kind then
   return
 end
 if val.kind == "end" then
     your code here

?

(I haven't tested it , just spent some times to see if lsp had already some kind of event handler on which you could attach)

amirbilu commented 6 months ago

this seems to be working.. i'll issue a PR soon

amirbilu commented 6 months ago

@allan-simon apologies on the delay.. can you please check if this is working for you?

https://github.com/codota/tabnine-nvim/pull/159/files

amirbilu commented 6 months ago

closing this as solved