Compare commits
2 Commits
65680cb255
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c8524df9d | |||
| b84e46bda1 |
19
init.lua
19
init.lua
@@ -5,6 +5,25 @@ end
|
|||||||
|
|
||||||
vim.env.PATH = vim.fn.stdpath('data') .. '/mason/bin:' .. vim.env.PATH
|
vim.env.PATH = vim.fn.stdpath('data') .. '/mason/bin:' .. vim.env.PATH
|
||||||
|
|
||||||
|
vim.filetype.add({
|
||||||
|
pattern = {
|
||||||
|
['.*/templates/.*%.ya?ml'] = 'helm',
|
||||||
|
['.*/manifests/.*%.ya?ml'] = 'helm',
|
||||||
|
['.*/crds/.*%.ya?ml'] = 'helm',
|
||||||
|
['.*/kubernetes/.*%.ya?ml'] = 'helm',
|
||||||
|
['.*/k8s/.*%.ya?ml'] = 'helm',
|
||||||
|
['.*/charts/.*%.ya?ml'] = 'helm',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function _G.see(val)
|
||||||
|
local lines = vim.split(vim.inspect(val), '\n')
|
||||||
|
vim.cmd('new')
|
||||||
|
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines)
|
||||||
|
vim.bo.buftype = 'nofile'
|
||||||
|
vim.bo.bufhidden = 'wipe'
|
||||||
|
end
|
||||||
|
|
||||||
require('core.options')
|
require('core.options')
|
||||||
require('core.keymaps')
|
require('core.keymaps')
|
||||||
require('core.events')
|
require('core.events')
|
||||||
|
|||||||
25
lsp/helm_ls.lua
Normal file
25
lsp/helm_ls.lua
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
---@brief
|
||||||
|
---
|
||||||
|
--- https://github.com/mrjosh/helm-ls
|
||||||
|
---
|
||||||
|
--- Helm Language server. (This LSP is in early development)
|
||||||
|
---
|
||||||
|
--- `helm Language server` can be installed by following the instructions [here](https://github.com/mrjosh/helm-ls).
|
||||||
|
---
|
||||||
|
--- The default `cmd` assumes that the `helm_ls` binary can be found in `$PATH`.
|
||||||
|
---
|
||||||
|
--- If need Helm file highlight use [vim-helm](https://github.com/towolf/vim-helm) plugin.
|
||||||
|
|
||||||
|
---@type vim.lsp.Config
|
||||||
|
return {
|
||||||
|
cmd = { 'helm_ls', 'serve' },
|
||||||
|
filetypes = { 'helm', 'yaml.helm-values' },
|
||||||
|
root_markers = { 'Chart.yaml' },
|
||||||
|
capabilities = {
|
||||||
|
workspace = {
|
||||||
|
didChangeWatchedFiles = {
|
||||||
|
dynamicRegistration = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
83
lsp/yamlls.lua
Normal file
83
lsp/yamlls.lua
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
---@brief
|
||||||
|
---
|
||||||
|
--- https://github.com/redhat-developer/yaml-language-server
|
||||||
|
---
|
||||||
|
--- `yaml-language-server` can be installed via `yarn`:
|
||||||
|
--- ```sh
|
||||||
|
--- yarn global add yaml-language-server
|
||||||
|
--- ```
|
||||||
|
---
|
||||||
|
--- To use a schema for validation, there are two options:
|
||||||
|
---
|
||||||
|
--- 1. Add a modeline to the file. A modeline is a comment of the form:
|
||||||
|
---
|
||||||
|
--- ```
|
||||||
|
--- # yaml-language-server: $schema=<urlToTheSchema|relativeFilePath|absoluteFilePath}>
|
||||||
|
--- ```
|
||||||
|
---
|
||||||
|
--- where the relative filepath is the path relative to the open yaml file, and the absolute filepath
|
||||||
|
--- is the filepath relative to the filesystem root ('/' on unix systems)
|
||||||
|
---
|
||||||
|
--- 2. Associated a schema url, relative , or absolute (to root of project, not to filesystem root) path to
|
||||||
|
--- the a glob pattern relative to the detected project root. Check `:checkhealth vim.lsp` to determine the resolved project
|
||||||
|
--- root.
|
||||||
|
---
|
||||||
|
--- ```lua
|
||||||
|
--- vim.lsp.config('yamlls', {
|
||||||
|
--- ...
|
||||||
|
--- settings = {
|
||||||
|
--- yaml = {
|
||||||
|
--- ... -- other settings. note this overrides the lspconfig defaults.
|
||||||
|
--- schemas = {
|
||||||
|
--- ["https://json.schemastore.org/github-workflow.json"] = "/.github/workflows/*",
|
||||||
|
--- ["../path/relative/to/file.yml"] = "/.github/workflows/*",
|
||||||
|
--- ["/path/from/root/of/project"] = "/.github/workflows/*",
|
||||||
|
--- },
|
||||||
|
--- },
|
||||||
|
--- }
|
||||||
|
--- })
|
||||||
|
--- ```
|
||||||
|
---
|
||||||
|
--- Currently, kubernetes is special-cased in yammls, see the following upstream issues:
|
||||||
|
--- * [#211](https://github.com/redhat-developer/yaml-language-server/issues/211).
|
||||||
|
--- * [#307](https://github.com/redhat-developer/yaml-language-server/issues/307).
|
||||||
|
---
|
||||||
|
--- To override a schema to use a specific k8s schema version (for example, to use 1.18):
|
||||||
|
---
|
||||||
|
--- ```lua
|
||||||
|
--- vim.lsp.config('yamlls', {
|
||||||
|
--- ...
|
||||||
|
--- settings = {
|
||||||
|
--- yaml = {
|
||||||
|
--- ... -- other settings. note this overrides the lspconfig defaults.
|
||||||
|
--- schemas = {
|
||||||
|
--- ["https://raw.githubusercontent.com/yannh/kubernetes-json-schema/refs/heads/master/v1.32.1-standalone-strict/all.json"] = "/*.k8s.yaml",
|
||||||
|
--- ... -- other schemas
|
||||||
|
--- },
|
||||||
|
--- },
|
||||||
|
--- }
|
||||||
|
--- })
|
||||||
|
--- ```
|
||||||
|
|
||||||
|
---@type vim.lsp.Config
|
||||||
|
return {
|
||||||
|
cmd = { 'yaml-language-server', '--stdio' },
|
||||||
|
filetypes = { 'yaml', 'yaml.docker-compose', 'yaml.gitlab', 'yaml.helm-values' },
|
||||||
|
root_markers = { '.git' },
|
||||||
|
settings = {
|
||||||
|
-- https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting
|
||||||
|
redhat = { telemetry = { enabled = false } },
|
||||||
|
-- formatting disabled by default in yaml-language-server; enable it
|
||||||
|
yaml = {
|
||||||
|
format = { enable = true },
|
||||||
|
validate = false, -- Disable all schema validation
|
||||||
|
},
|
||||||
|
},
|
||||||
|
on_init = function(client)
|
||||||
|
--- https://github.com/neovim/nvim-lspconfig/pull/4016
|
||||||
|
--- Since formatting is disabled by default if you check `client:supports_method('textDocument/formatting')`
|
||||||
|
--- during `LspAttach` it will return `false`. This hack sets the capability to `true` to facilitate
|
||||||
|
--- autocmd's which check this capability
|
||||||
|
client.server_capabilities.documentFormattingProvider = true
|
||||||
|
end,
|
||||||
|
}
|
||||||
@@ -1,7 +1,26 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
-- vim.filetype.add({
|
||||||
|
-- pattern = {
|
||||||
|
-- ['.*/templates/.*%.ya?ml'] = 'yaml.helm-values',
|
||||||
|
-- ['.*/templates/.*%.tpl'] = 'yaml.helm-values',
|
||||||
|
-- },
|
||||||
|
-- })
|
||||||
|
|
||||||
|
-- vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead' }, {
|
||||||
|
-- pattern = '**/templates/**/*.y?ml',
|
||||||
|
-- callback = function()
|
||||||
|
-- vim.bo.filetype = 'yaml.helm-values'
|
||||||
|
-- end,
|
||||||
|
-- })
|
||||||
|
--
|
||||||
function M.get()
|
function M.get()
|
||||||
return {
|
return {
|
||||||
|
-- {
|
||||||
|
-- ft = 'helm',
|
||||||
|
-- ts = 'helm',
|
||||||
|
-- lsp = 'helm-ls',
|
||||||
|
-- },
|
||||||
{
|
{
|
||||||
ft = 'yaml',
|
ft = 'yaml',
|
||||||
ts = 'yaml',
|
ts = 'yaml',
|
||||||
|
|||||||
@@ -152,13 +152,17 @@ local function save_cache(root, files)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function project_root()
|
local function project_root()
|
||||||
local obj = vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { text = true }):wait()
|
|
||||||
if obj.code == 0 and obj.stdout and obj.stdout ~= '' then
|
|
||||||
return vim.trim(obj.stdout)
|
|
||||||
end
|
|
||||||
return vim.fn.getcwd(0, 0)
|
return vim.fn.getcwd(0, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- local function project_root()
|
||||||
|
-- local obj = vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { text = true }):wait()
|
||||||
|
-- if obj.code == 0 and obj.stdout and obj.stdout ~= '' then
|
||||||
|
-- return vim.trim(obj.stdout)
|
||||||
|
-- end
|
||||||
|
-- return vim.fn.getcwd(0, 0)
|
||||||
|
-- end
|
||||||
|
|
||||||
local function normalize_rel(root, p)
|
local function normalize_rel(root, p)
|
||||||
if not p or p == '' then
|
if not p or p == '' then
|
||||||
return ''
|
return ''
|
||||||
@@ -244,53 +248,49 @@ local function render()
|
|||||||
|
|
||||||
-- For grep mode, reformat lines with fixed-width path column
|
-- For grep mode, reformat lines with fixed-width path column
|
||||||
local offset_map = {} -- maps display line -> character offset for highlighting
|
local offset_map = {} -- maps display line -> character offset for highlighting
|
||||||
|
-- In render(), replace the grep reformatting section:
|
||||||
|
-- In render(), replace the grep reformatting section:
|
||||||
if S.mode == 'grep' and total > 0 then
|
if S.mode == 'grep' and total > 0 then
|
||||||
local path_width = M.config.grep_path_width or 40
|
local path_width = M.config.grep_path_width or 40
|
||||||
|
|
||||||
for i = 1, #view do
|
for i = 1, #view do
|
||||||
local line = view[i]
|
local line = view[i]
|
||||||
if line then
|
if line then
|
||||||
-- Parse original vimgrep format: file:line:col:content
|
local file, lnum, col, content_start_pos = line:match('^(.-):(%d+):(%d+):()')
|
||||||
local file, lnum, col = line:match('^(.-):(%d+):(%d+):')
|
if file and lnum and col and content_start_pos then
|
||||||
if file and lnum and col then
|
|
||||||
-- Pad line number to 3 chars with underscores
|
|
||||||
local padded_lnum = lnum
|
local padded_lnum = lnum
|
||||||
while #padded_lnum < 3 do
|
while #padded_lnum < 3 do
|
||||||
padded_lnum = ' ' .. padded_lnum
|
padded_lnum = ' ' .. padded_lnum
|
||||||
end
|
end
|
||||||
|
|
||||||
local lineinfo = ':' .. padded_lnum .. '|'
|
local lineinfo = ':' .. padded_lnum .. '|'
|
||||||
local content_start = #file + 1 + #lnum + 1 + #col + 2 -- file + :lnum: + col:
|
local content_part = line:sub(content_start_pos)
|
||||||
local content_part = line:sub(content_start)
|
|
||||||
|
|
||||||
-- Calculate how much space we need for file + lineinfo
|
|
||||||
local prefix_len = #file + #lineinfo
|
local prefix_len = #file + #lineinfo
|
||||||
local formatted_line
|
local formatted_line
|
||||||
|
local new_content_start -- 1-based position where content starts in formatted line
|
||||||
|
|
||||||
if prefix_len > path_width then
|
if prefix_len > path_width then
|
||||||
-- Need to truncate the filepath part only
|
|
||||||
local available_for_file = path_width - #lineinfo
|
local available_for_file = path_width - #lineinfo
|
||||||
if available_for_file > 1 then
|
if available_for_file > 1 then
|
||||||
local truncated_file = '…' .. file:sub(-(available_for_file - 1))
|
local truncated_file = '…' .. file:sub(-(available_for_file - 1))
|
||||||
formatted_line = truncated_file .. lineinfo .. content_part
|
formatted_line = truncated_file .. lineinfo .. content_part
|
||||||
-- Offset is: original_file_length - truncated_file_length
|
new_content_start = #truncated_file + #lineinfo + 1
|
||||||
offset_map[i] = #file - #truncated_file
|
|
||||||
else
|
else
|
||||||
-- Extreme case: line info itself is too long, just show what we can
|
|
||||||
formatted_line = ('…' .. file):sub(1, path_width) .. lineinfo .. content_part
|
formatted_line = ('…' .. file):sub(1, path_width) .. lineinfo .. content_part
|
||||||
offset_map[i] = #file - (path_width - #lineinfo)
|
new_content_start = path_width + #lineinfo + 1
|
||||||
end
|
end
|
||||||
elseif prefix_len < path_width then
|
elseif prefix_len < path_width then
|
||||||
-- Right-align by padding before the filepath
|
|
||||||
local padding = string.rep(' ', path_width - prefix_len)
|
local padding = string.rep(' ', path_width - prefix_len)
|
||||||
formatted_line = padding .. file .. lineinfo .. content_part
|
formatted_line = padding .. file .. lineinfo .. content_part
|
||||||
offset_map[i] = -(path_width - prefix_len) -- negative for padding added
|
new_content_start = #padding + #file + #lineinfo + 1
|
||||||
else
|
else
|
||||||
formatted_line = file .. lineinfo .. content_part
|
formatted_line = file .. lineinfo .. content_part
|
||||||
offset_map[i] = 0
|
new_content_start = #file + #lineinfo + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
view[i] = formatted_line
|
view[i] = formatted_line
|
||||||
|
offset_map[i] = content_start_pos - new_content_start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -397,12 +397,16 @@ local function compute_positions_grep(lines, q)
|
|||||||
if q == '' then
|
if q == '' then
|
||||||
return lines, {}
|
return lines, {}
|
||||||
end
|
end
|
||||||
-- Match rg's --smart-case: case-insensitive unless query has uppercase
|
|
||||||
local case_insensitive = not q:match('[A-Z]')
|
local case_insensitive = not q:match('[A-Z]')
|
||||||
local qmatch = case_insensitive and q:lower() or q
|
local qmatch = case_insensitive and q:lower() or q
|
||||||
local positions = {}
|
local positions = {}
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
local lmatch = case_insensitive and tostring(line or ''):lower() or tostring(line or '')
|
local file, lnum, col, content_start_pos = line:match('^(.-):(%d+):(%d+):()')
|
||||||
|
if not content_start_pos then
|
||||||
|
positions[i] = nil
|
||||||
|
else
|
||||||
|
local content = line:sub(content_start_pos)
|
||||||
|
local lmatch = case_insensitive and content:lower() or content
|
||||||
local spans = {}
|
local spans = {}
|
||||||
local sidx = 1
|
local sidx = 1
|
||||||
while true do
|
while true do
|
||||||
@@ -410,7 +414,8 @@ local function compute_positions_grep(lines, q)
|
|||||||
if not s then
|
if not s then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
table.insert(spans, { s - 1, e })
|
-- Use content_start_pos from the pattern match, not manual calculation
|
||||||
|
table.insert(spans, { content_start_pos - 1 + s - 1, content_start_pos - 1 + e })
|
||||||
sidx = e + 1
|
sidx = e + 1
|
||||||
if #spans > 64 then
|
if #spans > 64 then
|
||||||
break
|
break
|
||||||
@@ -418,6 +423,7 @@ local function compute_positions_grep(lines, q)
|
|||||||
end
|
end
|
||||||
positions[i] = (#spans > 0) and spans or nil
|
positions[i] = (#spans > 0) and spans or nil
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return lines, positions
|
return lines, positions
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -715,7 +721,6 @@ local function grep_async(query, cb)
|
|||||||
'/',
|
'/',
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Add excludes before the pattern
|
|
||||||
for _, p in ipairs(M.config.exclude_patterns or {}) do
|
for _, p in ipairs(M.config.exclude_patterns or {}) do
|
||||||
table.insert(args, '--glob')
|
table.insert(args, '--glob')
|
||||||
table.insert(args, '!' .. p)
|
table.insert(args, '!' .. p)
|
||||||
@@ -730,11 +735,19 @@ local function grep_async(query, cb)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
local list = {}
|
local list = {}
|
||||||
|
local seen = {} -- track file:line to deduplicate
|
||||||
if obj.stdout and #obj.stdout > 0 then
|
if obj.stdout and #obj.stdout > 0 then
|
||||||
for line in obj.stdout:gmatch('[^\n]+') do
|
for line in obj.stdout:gmatch('[^\n]+') do
|
||||||
|
local file, lnum = line:match('^(.-):(%d+):%d+:')
|
||||||
|
if file and lnum then
|
||||||
|
local key = file .. ':' .. lnum
|
||||||
|
if not seen[key] then
|
||||||
|
seen[key] = true
|
||||||
list[#list + 1] = line
|
list[#list + 1] = line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
if #list > M.config.max_items then
|
if #list > M.config.max_items then
|
||||||
local tmp = {}
|
local tmp = {}
|
||||||
for i = 1, M.config.max_items do
|
for i = 1, M.config.max_items do
|
||||||
|
|||||||
Reference in New Issue
Block a user