aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2021-10-08 12:28:02 -0600
committerGitHub <noreply@github.com>2021-10-08 12:28:02 -0600
commitd5dd0aa1e633691ea6fa9b366b366a0a13cf7eba (patch)
tree8f73d7fdb79c31912e4c83140aa44e8c1dcd01c3 /runtime/lua/vim/diagnostic.lua
parent3f097321955e32b0724e0f0d059ecef3d764aac8 (diff)
downloadrneovim-d5dd0aa1e633691ea6fa9b366b366a0a13cf7eba.tar.gz
rneovim-d5dd0aa1e633691ea6fa9b366b366a0a13cf7eba.tar.bz2
rneovim-d5dd0aa1e633691ea6fa9b366b366a0a13cf7eba.zip
fix(diagnostic): error on invalid severity value (#15965)
Users can pass string values for severities that match with the enum names (e.g. "Warn" or "Info") which are converted to the corresponding numerical value in `to_severity`. Invalid strings were simply left as-is, which caused confusing errors later on. Instead, report an invalid severity string right up front to make the problem clear.
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r--runtime/lua/vim/diagnostic.lua5
1 files changed, 4 insertions, 1 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index b58055f07e..e8aba6b7a3 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -27,7 +27,10 @@ local global_diagnostic_options = {
---@private
local function to_severity(severity)
- return type(severity) == 'string' and M.severity[string.upper(severity)] or severity
+ if type(severity) == 'string' then
+ return assert(M.severity[string.upper(severity)], string.format("Invalid severity: %s", severity))
+ end
+ return severity
end
---@private