Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lsp/gh_actions_ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,32 @@
--- npm install -g gh-actions-language-server
--- ```

--- Session token used to perform authenticated API requests
---@return string? token
local function token()
local result = vim.system({ 'gh', 'auth', 'token', '-h', 'github.com' }):wait()
return result.code == 0 and vim.trim(assert(result.stdout)) or nil
end

--- Repository metadata needed for full features
---@param root_dir string
---@return table? metadata about the repository
local function repos(root_dir)
local result = vim.system({ 'gh', 'repo', 'view', '--json', 'owner,name,isInOrganization' }):wait()
if result.code == 0 then
local data = vim.json.decode(assert(result.stdout))
return {
{
owner = data.owner.login --[[@as string]],
name = data.name --[[@as string]],
organizationOwned = data.isInOrganization --[[@as boolean]],
workspaceUri = vim.uri_from_fname(root_dir),
},
}
end
return nil
end

---@type vim.lsp.Config
return {
cmd = { 'gh-actions-language-server', '--stdio' },
Expand Down Expand Up @@ -47,6 +73,14 @@ return {
end,
},
init_options = {}, -- needs to be present https://github.com/neovim/nvim-lspconfig/pull/3713#issuecomment-2857394868
before_init = function(params, config)
if config.root_dir and vim.fn.executable('gh') == 1 then
params.initializationOptions = {
sessionToken = token(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably ad a :LspGhLogin or something like that, rather than calling this as soon as the config is resolved.

repos = repos(config.root_dir),
}
end
end,
capabilities = {
workspace = {
didChangeWorkspaceFolders = {
Expand Down