someone-stole-my-name / yaml-companion.nvim

Get, set and autodetect YAML schemas in your buffers.
MIT License
221 stars 17 forks source link

Kubernetes auto detect not working #23

Closed Arkoprabho closed 1 year ago

Arkoprabho commented 1 year ago

Expected behaviour: When opening a file that has kind: autocomplete should work and the schema should be detected.

Do note that when the file starts with the directive: # yaml-language-server: $schema=https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/v1.26.0-standalone-strict/all.json the autocomplete works as expected.

LspInfo:

 Use [q] or [Esc] to quit the window

 Language client log: lsp.log
 Detected filetype:   yaml

 2 client(s) attached to this buffer: 

 Client: yamlls (id: 1, pid: nil, bufnr: [3])
    filetypes:       yaml, yaml.docker-compose
    autostart:       true
    root directory:  Running in single file mode.
    cmd:             yaml-language-server --stdio

 Client: null-ls (id: 2, pid: 5001, bufnr: [3, 8])
    filetypes:       lua, go, python, terraform, tf, typescriptreact, json, scss, typescript, html, yaml, vue, jsonc, markdown, javascriptreact, graphql, javascript, less, markdown.mdx, css, handlebars, kotlin, dockerfile
    autostart:       false
    root directory:  /path/to/folder
    cmd:             <function>

 Configured servers list: yamlls, sumneko_lua, gopls, tsserver, dockerls, terraform_lsp, csharp_ls, kotlin_language_server, pyright

lua =require("yaml-companion.config").options

{                                                                                                                                                                                                                     
  builtin_matchers = {                                                                                                                                                                                                
    cloud_init = {                                                                                                                                                                                                    
      enabled = true                                                                                                                                                                                                  
    },                                                                                                                                                                                                                
    kubernetes = {                                                                                                                                                                                                    
      enabled = true                                                                                                                                                                                                  
    }                                                                                                                                                                                                                 
  },                                                                                                                                                                                                                  
  log_level = {                                                                                                                                                                                                       
    context = "info",                                                                                                                                                                                                 
    lsp = "info"                                                                                                                                                                                                      
  },                                                                                                                                                                                                                  
  lspconfig = {                                                                                                                                                                                                       
    flags = {                                                                                                                                                                                                         
      debounce_text_changes = 150                                                                                                                                                                                     
    },                                                                                                                                                                                                                
    on_attach = <function 1>,                                                                                                                                                                                         
    settings = {                                                                                                                                                                                                      
      redhat = {                                                                                                                                                                                                      
        telemetry = {                                                                                                                                                                                                 
          enabled = false                                                                                                                                                                                             
        }                                                                                                                                                                                                             
      },                                                                                                                                                                                                              
      yaml = {                                                                                                                                                                                                        
        format = {                                                                                                                                                                                                    
          enable = true                                                                                                                                                                                               
        },                                                                                                                                                                                                            
        hover = true,                                                                                                                                                                                                 
        schemaDownload = {                                                                                                                                                                                            
          enable = true                                                                                                                                                                                               
        },                                                                                                                                                                                                            
        schemaStore = {                                                                                                                                                                                               
          enable = true,                                                                                                                                                                                              
          url = "https://www.schemastore.org/api/json/catalog.json"                                                                                                                                                   
        },                                                                                                                                                                                                            
        schemas = {                                                                                                                                                                                                   
          kubernetes = "/*.yaml",                                                                                                                                                                                     
          result = {}                                                                                                                                                                                                 
        },                                                                                                                                                                                                            
        trace = {                                                                                                                                                                                                     
          server = "debug"                                                                                                                                                                                            
        },                                                                                                                                                                                                            
        validate = true                                                                                                                                                                                               
      }                                                                                                                                                                                                               
    },                                                                                                                                                                                                                
    single_file_support = true                                                                                                                                                                                        
  },
schemas = {                                                                                                                                                                                                         
    result = {}                                                                                                                                                                                                       
  }                                                                                                                                                                                                                   
}  

lua =require("yaml-companion").get_buf_schema(0)

{                                                                                                                                                                                                                     
  result = { {                                                                                                                                                                                                        
      name = "none",                                                                                                                                                                                                  
      uri = "none"                                                                                                                                                                                                    
    } }                                                                                                                                                                                                               
}

The plugin config is default as mentioned in the readme

someone-stole-my-name commented 1 year ago

The built-in Kubernetes matcher only triggers when kind is equal to one of the values in https://github.com/someone-stole-my-name/yaml-companion.nvim/blob/main/lua/yaml-companion/builtin/kubernetes/resources.lua. If you want to set any file with kind in it to Kubernetes, you should create your own alternative matcher:

Arkoprabho commented 1 year ago
image

I have been trying with Deployments and Pods. I tried explicitly confirming the kubernetes schema from the telescope picker. It has the output as mentioned in the root comment

Arkoprabho commented 1 year ago

Not sure if the closing of the issue was intentional or not, hence the tag @someone-stole-my-name

someone-stole-my-name commented 1 year ago

What is your nvim version? Do you have more details about how to reproduce your issue? The behaviour you describe is tested here, so it should work 😓

Arkoprabho commented 1 year ago
nvim --version

nvim --version                      
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Ventura-arm64.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.8.1/share/nvim"

Run :checkhealth for more info

Do you think it might be to do with the yaml-language-server? My line of thought here is that if it is the language server, then it shouldn't work even with the schema defined explicitly. Is that a correct understanding? Another thought process is that it seems to be working without the plugin. The tests and the code logic looks ok 🤔 . Might be a bad configuration or a gotcha. My dotfiles are here. If we do find something that we can mention as a part of documentation or code update, I'll be delighted to submit a PR for the same.

Arkoprabho commented 1 year ago

Give me some time to come up with a way to replicate the issue with least possible setup.

Arkoprabho commented 1 year ago

After some more digging these are my observations:

  1. null-ls causes conflicts. This is a well documented issue in the neovim community. So wasn't an issue to get around.
  2. Separating the setup step from the require causes the it to not work as expected.
    local yaml_companion = require("yaml-companion")
    yaml_companion.setup({
    -- ovverrides here
    })

    The above code doesnt work. But

    local yaml_companion = require("yaml-companion").setup({
    -- ovverrides here
    })

    This works. 🤔

someone-stole-my-name commented 1 year ago

Glad you got it working 🚀 The setup function returns the config you must use when configuring the server.

local cfg = require("yaml-companion").setup({})
require("lspconfig")["yamlls"].setup(cfg)

You can't throw away the result of setup and configure the server with your own table. If you need to customize the setup table, you can pass your own flags inside require("yaml-companion").setup({ lspconfig = {...} }) or leave it empty to use the default.