Skip to content

Commit 4776785

Browse files
committed
feat(lsp): add gh_action_ls for github actions
1 parent 7527674 commit 4776785

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

lua/core/settings.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ settings["lsp_deps"] = {
113113
"clangd",
114114
-- "docker_compose_language_service",
115115
"dockerls",
116-
-- NOTE: not-yet registered in mason.nvim, install it via `npm i -g gh-actions-language-server`
117-
-- "gh_actions_ls",
116+
"gh_actions_ls",
118117
"gitlab_ci_ls",
119118
"html",
120119
"htmx",

lua/modules/configs/completion/servers/gh_actions_ls.lua

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
-- https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/configs/gh_actions_ls.lua
22
return {
33
cmd = { "gh-actions-language-server", "--stdio" },
4-
filetypes = { "yaml.github" },
4+
filetypes = { "yaml" },
55

6-
-- Only attach to yaml files that are GitHub workflows instead of all yaml
7-
-- files. (A nil root_dir and no single_file_support results in the LSP not
8-
-- attaching.) For details, see #3558
9-
root_dir = function(filename)
10-
local dirs_to_check = {
11-
".github/workflows",
12-
".forgejo/workflows",
13-
".gitea/workflows",
14-
}
15-
16-
local dir = vim.fs.dirname(filename)
17-
for _, subdir in ipairs(dirs_to_check) do
18-
local match = vim.fs.find(subdir, { path = dir, upward = true })[1]
19-
if match and vim.fn.isdirectory(match) == 1 and vim.fs.dirname(filename) == match then
20-
return match
21-
end
6+
-- `root_dir` ensures that the LSP does not attach to all yaml files
7+
root_dir = function(bufnr, on_dir)
8+
local parent = vim.fs.dirname(vim.api.nvim_buf_get_name(bufnr))
9+
if
10+
vim.endswith(parent, "/.github/workflows")
11+
or vim.endswith(parent, "/.forgejo/workflows")
12+
or vim.endswith(parent, "/.gitea/workflows")
13+
then
14+
on_dir(parent)
2215
end
23-
24-
return nil
2516
end,
2617

27-
-- Disabling "single file support" is a hack to avoid enabling this LS for
28-
-- every random yaml file, so `root_dir()` can control the enablement.
29-
single_file_support = false,
30-
3118
capabilities = {
3219
workspace = {
3320
didChangeWorkspaceFolders = {

lua/modules/configs/completion/servers/yamlls.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
return {
33
cmd = { "yaml-language-server", "--stdio" },
44
filetypes = { "yaml", "yaml.docker-compose", "yaml.gitlab" },
5-
root_dir = function(fname)
6-
return vim.fs.dirname(vim.fs.find(".git", { path = fname, upward = true })[1])
7-
end,
5+
root_markers = { ".git" },
86
single_file_support = true,
97
debounce_text_changes = 150,
108
settings = {
@@ -24,6 +22,12 @@ return {
2422
},
2523
schemas = require("schemastore").yaml.schemas({
2624
extra = {
25+
{
26+
name = "github-action",
27+
description = "github-action YAML schema",
28+
fileMatch = { "*/.github/workflows/*.{yml,yaml}" },
29+
url = "https://json.schemastore.org/github-workflow.json",
30+
},
2731
{
2832
name = "docker-compose",
2933
description = "docker-compose YAML schema",

0 commit comments

Comments
 (0)