Skip to content

Commit

Permalink
refactor!: improve lazy-loading by registering custom filetype `yaml.…
Browse files Browse the repository at this point in the history
…kpops`
  • Loading branch information
disrupted committed Mar 28, 2024
1 parent 6c1d403 commit 1fe216c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ example using [Lazy](https://github.com/folke/lazy.nvim) plugin manager
```lua
{
'disrupted/kpops.nvim',
ft = 'yaml',
ft = 'yaml.kpops',
opts = {
settings = {
kpops = {
generate_schema = true,
},
},
},
config = true,
dependencies = { 'neovim/nvim-lspconfig' }
}
```
Expand Down
11 changes: 11 additions & 0 deletions ftdetect/kpops.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local kpops = require('kpops.cli')
if not kpops.is_installed() then
return
end
vim.filetype.add({
pattern = {
['pipeline?.*%.yaml'] = 'yaml.kpops',
['defaults_?.*%.yaml'] = 'yaml.kpops',
['config?.*%.yaml'] = 'yaml.kpops',
},
})
6 changes: 6 additions & 0 deletions lua/kpops/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local kpops = require('kpops.cli')
local lsp = require('kpops.lsp')
local commands = require('kpops.commands')
local config = require('kpops.config')
Expand All @@ -6,6 +7,11 @@ local M = {}

-- -@param opts table<string, any>
M.setup = function(opts)
if not kpops.is_installed() then
vim.notify('KPOps is not installed', vim.log.levels.WARN)
return
end

commands.setup()
config = vim.tbl_deep_extend('force', config, opts or {})
lsp.setup(config)
Expand Down
9 changes: 1 addition & 8 deletions lua/kpops/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ M.setup = function(conf)
-- https://github.com/redhat-developer/yaml-language-server
default_config = {
cmd = { 'yaml-language-server', '--stdio' },
filetypes = { 'yaml' },
filetypes = { 'yaml.kpops' },
root_dir = function(filename)
if not kpops.is_installed() then
return nil
end
if not schema.is_kpops_file(filename) then
return nil -- not a KPOps project, abort LSP startup
end

local cwd = lspconfig.util.find_git_ancestor(filename) or vim.loop.cwd()
return cwd
end,
Expand Down

0 comments on commit 1fe216c

Please sign in to comment.