Skip to content

Commit

Permalink
add higlighting options
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy committed Mar 15, 2024
1 parent 75ab851 commit eda2ace
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ vim.keymap.set("n", "gx", lsplinks.gx)
}
```

### Default Configuration:

``` lua
lsplinks.setup({
highlight = true,
hl_group = "Underlined",
})
```

### Demo 1:

Jump to `$ref` links in swagger/openapi files.
Expand Down
26 changes: 23 additions & 3 deletions lua/lsplinks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ local M = {}
---@field range lsp.Range
---@field target string

---@class lsplinks.Options
---@field hl_group string | nil
---@field highlight boolean | nil

---@type table<integer, lsp.DocumentLink[]>
local links_by_buf = {}

---@type lsplinks.Options
local options = {
hl_group = "Underlined",
highlight = true,
}

---@type integer
local ns = api.nvim_create_namespace("lsplinks")

Expand Down Expand Up @@ -60,7 +70,15 @@ end
local augroup = api.nvim_create_augroup("lsplinks", { clear = true })

--- Setup autocommands for refreshing links
function M.setup()
---@param opts lsplinks.Options | nil
function M.setup(opts)
opts = opts or {}
if opts.hl_group ~= nil then
options.hl_group = opts.hl_group
end
if opts.highlight ~= nil then
options.highlight = opts.highlight
end
api.nvim_create_autocmd({ "InsertLeave", "BufEnter", "CursorHold", "LspAttach" }, {
group = augroup,
callback = M.refresh,
Expand Down Expand Up @@ -165,7 +183,9 @@ function M.refresh()
})
end
links_by_buf[ctx.bufnr] = result
M.display()
if options.highlight then
M.display()
end
end)
end

Expand All @@ -189,7 +209,7 @@ function M.display()
pcall(api.nvim_buf_set_extmark, 0, ns, link.range.start.line, link.range.start.character, {
end_row = link.range["end"].line,
end_col = link.range["end"].character,
hl_group = "Underlined",
hl_group = options.hl_group,
})
end
end
Expand Down

0 comments on commit eda2ace

Please sign in to comment.