@@ -91,23 +91,22 @@ local function filter_by_severity(severity, diagnostics)
91
91
end
92
92
93
93
---@private
94
-
local function prefix_source(source, diagnostics)
95
-
vim.validate { source = {source, function(v)
96
-
return v == "always" or v == "if_many"
97
-
end, "'always' or 'if_many'" } }
98
-
99
-
if source == "if_many" then
100
-
local sources = {}
101
-
for _, d in pairs(diagnostics) do
102
-
if d.source then
103
-
sources[d.source] = true
94
+
local function count_sources(bufnr)
95
+
local seen = {}
96
+
local count = 0
97
+
for _, namespace_diagnostics in pairs(diagnostic_cache[bufnr]) do
98
+
for _, diagnostic in ipairs(namespace_diagnostics) do
99
+
if diagnostic.source and not seen[diagnostic.source] then
100
+
seen[diagnostic.source] = true
101
+
count = count + 1
104
102
end
105
103
end
106
-
if #vim.tbl_keys(sources) <= 1 then
107
-
return diagnostics
108
-
end
109
104
end
105
+
return count
106
+
end
110
107
108
+
---@private
109
+
local function prefix_source(diagnostics)
111
110
return vim.tbl_map(function(d)
112
111
if not d.source then
113
112
return d
560
559
--- - virtual_text: (default true) Use virtual text for diagnostics. Options:
561
560
--- * severity: Only show virtual text for diagnostics matching the given
562
561
--- severity |diagnostic-severity|
563
-
--- * source: (string) Include the diagnostic source in virtual
564
-
--- text. One of "always" or "if_many".
562
+
--- * source: (boolean or string) Include the diagnostic source in virtual
563
+
--- text. Use "if_many" to only show sources if there is more than
564
+
--- one diagnostic source in the buffer. Otherwise, any truthy value
565
+
--- means to always show the diagnostic source.
565
566
--- * format: (function) A function that takes a diagnostic as input and
566
567
--- returns a string. The return value is the text used to display
567
568
--- the diagnostic. Example:
@@ -925,8 +926,11 @@ M.handlers.virtual_text = {
925
926
if opts.virtual_text.format then
926
927
diagnostics = reformat_diagnostics(opts.virtual_text.format, diagnostics)
927
928
end
928
-
if opts.virtual_text.source then
929
-
diagnostics = prefix_source(opts.virtual_text.source, diagnostics)
929
+
if
930
+
opts.virtual_text.source
931
+
and (opts.virtual_text.source ~= "if_many" or count_sources(bufnr) > 1)
932
+
then
933
+
diagnostics = prefix_source(diagnostics)
930
934
end
931
935
if opts.virtual_text.severity then
932
936
severity = opts.virtual_text.severity
@@ -1151,8 +1155,11 @@ end
1151
1155
--- - header: (string or table) String to use as the header for the floating window. If a
1152
1156
--- table, it is interpreted as a [text, hl_group] tuple. Overrides the setting
1153
1157
--- from |vim.diagnostic.config()|.
1154
-
--- - source: (string) Include the diagnostic source in the message. One of "always" or
1155
-
--- "if_many". Overrides the setting from |vim.diagnostic.config()|.
1158
+
--- - source: (boolean or string) Include the diagnostic source in the message.
1159
+
--- Use "if_many" to only show sources if there is more than one source of
1160
+
--- diagnostics in the buffer. Otherwise, any truthy value means to always show
1161
+
--- the diagnostic source. Overrides the setting from
1162
+
--- |vim.diagnostic.config()|.
1156
1163
--- - format: (function) A function that takes a diagnostic as input and returns a
1157
1164
--- string. The return value is the text used to display the diagnostic.
1158
1165
--- Overrides the setting from |vim.diagnostic.config()|.
@@ -1264,8 +1271,8 @@ function M.open_float(opts, ...)
1264
1271
diagnostics = reformat_diagnostics(opts.format, diagnostics)
1265
1272
end
1266
1273
1267
-
if opts.source then
1268
-
diagnostics = prefix_source(opts.source, diagnostics)
1274
+
if opts.source and (opts.source ~= "if_many" or count_sources(bufnr) > 1) then
1275
+
diagnostics = prefix_source(diagnostics)
1269
1276
end
1270
1277
1271
1278
local prefix_opt = if_nil(opts.prefix, (scope == "cursor" and #diagnostics <= 1) and "" or function(_, i)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4