Ramilito / kubectl.nvim

⎈ Streamline your Kubernetes management within Neovim—control and monitor your cluster seamlessly, all without leaving your coding environment.
Apache License 2.0
322 stars 9 forks source link

Reload alias completion #182

Closed mosheavni closed 2 months ago

mosheavni commented 2 months ago

When I open the plugin, and click \ really fast, the completions retrieved from kubectl api-resources did not load yet.

Instead of closing and reopening the aliases float, we can reassign self.data with M.cached_api_resources.values inside the \ mapping

The problem when I tried to solve it, that even after I define it, sometimes it's still a string instead of table. This UGLY hack that I got working is:

image

right after this one: https://github.com/Ramilito/kubectl.nvim/blob/a47aea3e9c55a584bad9c3df76a5f5b8a8a3ac07/lua/kubectl/views/init.lua#L120

code

      if type(self.data) == "string" or next(self.data) == nil then
        self.data = M.cached_api_resources.values
      end
      if type(self.data) == "string" then
        vim.print("this BS is still a string")
        self.data = vim.split(M.cached_api_resources.values, "\n")
      end

this BS is still a string is always printed on the second try of \ completion Obviously I'm opening this issue since the code is too ugly for a PR.

Demo of the completion working after api-resources were loaded: 2024-08-19_10-49-03 (1)

Any suggestions?

Ramilito commented 2 months ago

I think that's not super ugly and fixes the issue, although we can do a small improvement and reuse our builder, so what about this variant? It at the same spot your code is currently:

      -- Filter suggestions based on input
      local filtered_suggestions = {}

      self.data = M.cached_api_resources.values
      self:splitData():decodeJson()
mosheavni commented 2 months ago

I think that's not super ugly and fixes the issue, although we can do a small improvement and reuse our builder, so what about this variant? It at the same spot your code is currently:

      -- Filter suggestions based on input
      local filtered_suggestions = {}

      self.data = M.cached_api_resources.values
      self:splitData():decodeJson()

Excellent! it's working! do you want me to open a PR? it's your code after all..

Ramilito commented 2 months ago

Merged it to main!