2020-05-18 06:49:50 -07:00
|
|
|
local api = vim.api
|
|
|
|
|
2022-02-21 13:21:42 -07:00
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.priorities = {
|
|
|
|
syntax = 50,
|
|
|
|
treesitter = 100,
|
|
|
|
diagnostics = 150,
|
|
|
|
user = 200,
|
|
|
|
}
|
2020-05-18 06:49:50 -07:00
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2022-02-21 13:21:42 -07:00
|
|
|
function M.create(higroup, hi_info, default)
|
2022-07-09 09:40:32 -07:00
|
|
|
vim.deprecate('vim.highlight.create', 'vim.api.nvim_set_hl', '0.9')
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
local options = {}
|
|
|
|
-- TODO: Add validation
|
|
|
|
for k, v in pairs(hi_info) do
|
2022-05-09 02:23:51 -07:00
|
|
|
table.insert(options, string.format('%s=%s', k, v))
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
end
|
2022-07-07 09:27:18 -07:00
|
|
|
vim.cmd(
|
|
|
|
string.format(
|
|
|
|
[[highlight %s %s %s]],
|
|
|
|
default and 'default' or '',
|
|
|
|
higroup,
|
|
|
|
table.concat(options, ' ')
|
|
|
|
)
|
|
|
|
)
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
end
|
|
|
|
|
2021-08-22 13:55:28 -07:00
|
|
|
---@private
|
2022-02-21 13:21:42 -07:00
|
|
|
function M.link(higroup, link_to, force)
|
2022-07-09 09:40:32 -07:00
|
|
|
vim.deprecate('vim.highlight.link', 'vim.api.nvim_set_hl', '0.9')
|
2022-05-09 02:23:51 -07:00
|
|
|
vim.cmd(string.format([[highlight%s link %s %s]], force and '!' or ' default', higroup, link_to))
|
lsp: vim.lsp.diagnostic (#12655)
Breaking Changes:
- Deprecated all `vim.lsp.util.{*diagnostics*}()` functions.
- Instead, all functions must be found in vim.lsp.diagnostic
- For now, they issue a warning ONCE per neovim session. In a
"little while" we will remove them completely.
- `vim.lsp.callbacks` has moved to `vim.lsp.handlers`.
- For a "little while" we will just redirect `vim.lsp.callbacks` to
`vim.lsp.handlers`. However, we will remove this at some point, so
it is recommended that you change all of your references to
`callbacks` into `handlers`.
- This also means that for functions like |vim.lsp.start_client()|
and similar, keyword style arguments have moved from "callbacks"
to "handlers". Once again, these are currently being forward, but
will cease to be forwarded in a "little while".
- Changed the highlight groups for LspDiagnostic highlight as they were
inconsistently named.
- For more information, see |lsp-highlight-diagnostics|
- Changed the sign group names as well, to be consistent with
|lsp-highlight-diagnostics|
General Enhancements:
- Rewrote much of the getting started help document for lsp. It also
provides a much nicer configuration strategy, so as to not recommend
globally overwriting builtin neovim mappings.
LSP Enhancements:
- Introduced the concept of |lsp-handlers| which will allow much better
customization for users without having to copy & paste entire files /
functions / etc.
Diagnostic Enhancements:
- "goto next diagnostic" |vim.lsp.diagnostic.goto_next()|
- "goto prev diagnostic" |vim.lsp.diagnostic.goto_prev()|
- For each of the gotos, auto open diagnostics is available as a
configuration option
- Configurable diagnostic handling:
- See |vim.lsp.diagnostic.on_publish_diagnostics()|
- Delay display until after insert mode
- Configure signs
- Configure virtual text
- Configure underline
- Set the location list with the buffers diagnostics.
- See |vim.lsp.diagnostic.set_loclist()|
- Better performance for getting counts and line diagnostics
- They are now cached on save, to enhance lookups.
- Particularly useful for checking in statusline, etc.
- Actual testing :)
- See ./test/functional/plugin/lsp/diagnostic_spec.lua
- Added `guisp` for underline highlighting
NOTE: "a little while" means enough time to feel like most plugins and
plugin authors have had a chance to refactor their code to use the
updated calls. Then we will remove them completely. There is no need to
keep them, because we don't have any released version of neovim that
exposes these APIs. I'm trying to be nice to people following HEAD :)
Co-authored: [Twitch Chat 2020](https://twitch.tv/teej_dv)
2020-11-12 20:21:34 -07:00
|
|
|
end
|
|
|
|
|
2020-05-31 11:56:00 -07:00
|
|
|
--- Highlight range between two positions
|
|
|
|
---
|
2021-08-22 13:55:28 -07:00
|
|
|
---@param bufnr number of buffer to apply highlighting to
|
|
|
|
---@param ns namespace to add highlight to
|
|
|
|
---@param higroup highlight group to use for highlighting
|
2022-02-21 13:21:42 -07:00
|
|
|
---@param start first position (tuple {line,col})
|
|
|
|
---@param finish second position (tuple {line,col})
|
|
|
|
---@param opts table with options:
|
|
|
|
-- - regtype type of range (:help setreg, default charwise)
|
|
|
|
-- - inclusive boolean indicating whether the range is end-inclusive (default false)
|
|
|
|
-- - priority number indicating priority of highlight (default priorities.user)
|
|
|
|
function M.range(bufnr, ns, higroup, start, finish, opts)
|
|
|
|
opts = opts or {}
|
2022-05-09 02:23:51 -07:00
|
|
|
local regtype = opts.regtype or 'v'
|
2022-02-21 13:21:42 -07:00
|
|
|
local inclusive = opts.inclusive or false
|
|
|
|
local priority = opts.priority or M.priorities.user
|
2020-05-31 11:56:00 -07:00
|
|
|
|
|
|
|
-- sanity check
|
2022-02-21 13:21:42 -07:00
|
|
|
if start[2] < 0 or finish[1] < start[1] then
|
|
|
|
return
|
|
|
|
end
|
2020-05-31 11:56:00 -07:00
|
|
|
|
2022-02-21 13:21:42 -07:00
|
|
|
local region = vim.region(bufnr, start, finish, regtype, inclusive)
|
2020-05-31 11:56:00 -07:00
|
|
|
for linenr, cols in pairs(region) do
|
2022-01-15 15:19:20 -07:00
|
|
|
local end_row
|
|
|
|
if cols[2] == -1 then
|
|
|
|
end_row = linenr + 1
|
|
|
|
cols[2] = 0
|
|
|
|
end
|
|
|
|
api.nvim_buf_set_extmark(bufnr, ns, linenr, cols[1], {
|
|
|
|
hl_group = higroup,
|
|
|
|
end_row = end_row,
|
|
|
|
end_col = cols[2],
|
|
|
|
priority = priority,
|
2022-02-21 13:21:42 -07:00
|
|
|
strict = false,
|
2022-01-15 15:19:20 -07:00
|
|
|
})
|
2020-05-31 11:56:00 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-09 02:23:51 -07:00
|
|
|
local yank_ns = api.nvim_create_namespace('hlyank')
|
2022-06-02 00:49:57 -07:00
|
|
|
local yank_timer
|
2020-05-18 06:49:50 -07:00
|
|
|
--- Highlight the yanked region
|
2020-05-31 11:56:00 -07:00
|
|
|
---
|
2020-05-18 06:49:50 -07:00
|
|
|
--- use from init.vim via
|
2020-07-05 18:30:12 -07:00
|
|
|
--- au TextYankPost * lua vim.highlight.on_yank()
|
2020-05-18 06:49:50 -07:00
|
|
|
--- customize highlight group and timeout via
|
2020-07-05 18:30:12 -07:00
|
|
|
--- au TextYankPost * lua vim.highlight.on_yank {higroup="IncSearch", timeout=150}
|
|
|
|
--- customize conditions (here: do not highlight a visual selection) via
|
|
|
|
--- au TextYankPost * lua vim.highlight.on_yank {on_visual=false}
|
2020-05-31 11:56:00 -07:00
|
|
|
---
|
2022-02-21 13:21:42 -07:00
|
|
|
-- @param opts table with options controlling the highlight:
|
2020-07-05 18:30:12 -07:00
|
|
|
-- - higroup highlight group for yanked region (default "IncSearch")
|
|
|
|
-- - timeout time in ms before highlight is cleared (default 150)
|
|
|
|
-- - on_macro highlight when executing macro (default false)
|
|
|
|
-- - on_visual highlight when yanking visual selection (default true)
|
|
|
|
-- - event event structure (default vim.v.event)
|
2022-02-21 13:21:42 -07:00
|
|
|
function M.on_yank(opts)
|
|
|
|
vim.validate({
|
|
|
|
opts = {
|
|
|
|
opts,
|
|
|
|
function(t)
|
|
|
|
if t == nil then
|
|
|
|
return true
|
|
|
|
else
|
2022-05-09 02:23:51 -07:00
|
|
|
return type(t) == 'table'
|
2022-02-21 13:21:42 -07:00
|
|
|
end
|
|
|
|
end,
|
2022-05-09 02:23:51 -07:00
|
|
|
'a table or nil to configure options (see `:h highlight.on_yank`)',
|
2022-02-21 13:21:42 -07:00
|
|
|
},
|
|
|
|
})
|
2020-07-05 18:30:12 -07:00
|
|
|
opts = opts or {}
|
|
|
|
local event = opts.event or vim.v.event
|
|
|
|
local on_macro = opts.on_macro or false
|
|
|
|
local on_visual = (opts.on_visual ~= false)
|
|
|
|
|
2022-05-09 02:23:51 -07:00
|
|
|
if not on_macro and vim.fn.reg_executing() ~= '' then
|
2022-02-21 13:21:42 -07:00
|
|
|
return
|
|
|
|
end
|
2022-05-09 02:23:51 -07:00
|
|
|
if event.operator ~= 'y' or event.regtype == '' then
|
2022-02-21 13:21:42 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if not on_visual and event.visual then
|
|
|
|
return
|
|
|
|
end
|
2020-07-05 18:30:12 -07:00
|
|
|
|
2022-05-09 02:23:51 -07:00
|
|
|
local higroup = opts.higroup or 'IncSearch'
|
2020-07-05 18:30:12 -07:00
|
|
|
local timeout = opts.timeout or 150
|
2020-05-18 06:49:50 -07:00
|
|
|
|
|
|
|
local bufnr = api.nvim_get_current_buf()
|
|
|
|
api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
|
2022-06-02 00:49:57 -07:00
|
|
|
if yank_timer then
|
|
|
|
yank_timer:close()
|
|
|
|
end
|
2020-05-18 06:49:50 -07:00
|
|
|
|
|
|
|
local pos1 = vim.fn.getpos("'[")
|
|
|
|
local pos2 = vim.fn.getpos("']")
|
|
|
|
|
2022-02-21 13:21:42 -07:00
|
|
|
pos1 = { pos1[2] - 1, pos1[3] - 1 + pos1[4] }
|
|
|
|
pos2 = { pos2[2] - 1, pos2[3] - 1 + pos2[4] }
|
2020-05-18 06:49:50 -07:00
|
|
|
|
2022-02-21 13:21:42 -07:00
|
|
|
M.range(
|
|
|
|
bufnr,
|
|
|
|
yank_ns,
|
|
|
|
higroup,
|
|
|
|
pos1,
|
|
|
|
pos2,
|
|
|
|
{ regtype = event.regtype, inclusive = event.inclusive, priority = M.priorities.user }
|
2020-05-18 06:49:50 -07:00
|
|
|
)
|
2022-02-21 13:21:42 -07:00
|
|
|
|
2022-06-02 00:49:57 -07:00
|
|
|
yank_timer = vim.defer_fn(function()
|
|
|
|
yank_timer = nil
|
2022-02-21 13:21:42 -07:00
|
|
|
if api.nvim_buf_is_valid(bufnr) then
|
|
|
|
api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
|
|
|
|
end
|
|
|
|
end, timeout)
|
2020-05-18 06:49:50 -07:00
|
|
|
end
|
|
|
|
|
2022-02-21 13:21:42 -07:00
|
|
|
return M
|