Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yamlls not using schema set by yaml-companion #48

Open
FedericoAntoniazzi opened this issue May 24, 2024 · 0 comments
Open

Yamlls not using schema set by yaml-companion #48

FedericoAntoniazzi opened this issue May 24, 2024 · 0 comments

Comments

@FedericoAntoniazzi
Copy link

Hello there, I've been using yaml-companion and yamlls for a year but suddenly decided to stop configuring schemas in yamlls. Yamlls is working perfectly on given schemas, but it seems to ignore the schemas set by yaml-companion (I made sure the paths and URLs work correctly).

May I ask for help troubleshooting this issue?

Configuration

Plugin install on Lazy nvim
  -- Yaml companion
  {
    "someone-stole-my-name/yaml-companion.nvim",
    -- event = "VeryLazy",
    dependencies = {
      "neovim/nvim-lspconfig",
      "nvim-lua/plenary.nvim",
      "nvim-telescope/telescope.nvim",
    },
    config = function()
      require("telescope").load_extension("yaml_schema")
    end,
    keys = {
      { "<leader>y", ":Telescope yaml_schema<CR>", mode = "n", desc = "Choose YAML Schema" },
    },
  },
Yaml LSP configuration
local Yaml = {}

local folderOfThisFile = (...):match("(.-)[^%.]+$")

local mergeSchemas = function(t1, t2)
  for k, v in pairs(t2) do
    t1[k] = v
  end
  return t1
end

-- Manually import CRD schemas
local crds_path = os.getenv("HOME") .. "/.config/nvim/lua/configs/lsps/crds/"
local schemas = {
  { name = "Fury KFD Distribution",             uri = "https://raw.githubusercontent.com/sighupio/fury-distribution/main/schemas/public/kfddistribution-kfd-v1alpha2.json" },
  { name = "Fury KFD EKS",                      uri = "https://raw.githubusercontent.com/sighupio/fury-distribution/main/schemas/public/ekscluster-kfd-v1alpha2.json" },
  { name = "Fury OnPremises",                   uri = "https://raw.githubusercontent.com/sighupio/fury-distribution/main/schemas/public/onpremises-kfd-v1alpha2.json" },
  { name = "CloudNativePG Backup",              uri = crds_path .. "cloudnative-pg/backup_v1.json" },
  { name = "CloudNativePG Cluster",             uri = crds_path .. "cloudnative-pg/cluster_v1.json" },
  { name = "CloudNativePG ClusterImageCatalog", uri = crds_path .. "cloudnative-pg/clusterimagecatalog_v1.json" },
  { name = "CloudNativePG ImageCatalog",        uri = crds_path .. "cloudnative-pg/imagecatalog_v1.json" },
  { name = "CloudNativePG Pooler",              uri = crds_path .. "cloudnative-pg/pooler_v1.json" },
  { name = "CloudNativePG ScheduledBackup",     uri = crds_path .. "cloudnative-pg/scheduledbackup_v1.json" },
}

function Yaml.setup(on_attach, capabilities)
  local cfg = require("yaml-companion").setup({
    -- Load CRDs from a folder
    -- schemas = mergeSchemas(require(folderOfThisFile .. "yaml_kubernetes_crds"), schemas),

    builtin_matchers = {
      kubernetes = { enabled = true },
    },

    lspconfig = {
      on_attach = on_attach,
      capabilities = capabilities,
      settings = {
        yaml = {
          -- For debug purposes, set hardcoded schemas on given filenames
          schemas = {
            [crds_path .. "cloudnative-pg/cluster_v1.json"] = "cluster.yaml",
            [crds_path .. "cloudnative-pg/backup_v1.json"] = "backup.yaml",
          },
          schemaStore = {
            enable = false,
          }
        }
      }
    }
  })

  require("lspconfig").yamlls.setup(cfg)
end

return Yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant