Skip to content

Commit f55fe54

Browse files
committed
feat: deprecate lsp.color config and add warning for Neovim 0.12+ users
1 parent 5c0ad1f commit f55fe54

4 files changed

Lines changed: 165 additions & 20 deletions

File tree

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,6 @@ require("flutter-tools").setup {
276276
auto_open = false -- if true this will open the outline automatically when it is first populated
277277
},
278278
lsp = {
279-
color = { -- show the derived colours for dart variables
280-
enabled = false, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10
281-
background = false, -- highlight the background
282-
background_color = nil, -- required, when background is transparent (i.e. background_color = { r = 19, g = 17, b = 24},)
283-
foreground = false, -- highlight the foreground
284-
virtual_text = true, -- show the highlight using virtual text
285-
virtual_text_str = "", -- the virtual text character to highlight
286-
},
287279
on_attach = my_custom_on_attach,
288280
capabilities = my_custom_capabilities, -- e.g. lsp_status capabilities
289281
--- OR you can specify a function to deactivate or change or control how the config is created
@@ -308,6 +300,30 @@ require("flutter-tools").setup {
308300
You can override any options available in the `lspconfig` setup, this call essentially wraps
309301
it and adds some extra `flutter` specific handlers and utilisation options.
310302

303+
### Document colors
304+
305+
Plugin-managed `lsp.color` rendering is deprecated and will be removed when flutter-tools.nvim requires Neovim `0.12+`.
306+
307+
On Neovim `0.12+`, use the built-in LSP document color support instead:
308+
309+
```lua
310+
vim.api.nvim_create_autocmd("LspAttach", {
311+
callback = function(ev)
312+
vim.lsp.document_color.enable(true, { bufnr = ev.buf })
313+
end,
314+
})
315+
```
316+
317+
If you want to opt out of Neovim's built-in document colors for some buffers:
318+
319+
```lua
320+
vim.api.nvim_create_autocmd("LspAttach", {
321+
callback = function(ev)
322+
vim.lsp.document_color.enable(false, { bufnr = ev.buf })
323+
end,
324+
})
325+
```
326+
311327
**NOTE:**
312328
By default this plugin excludes analysis of the packages in the flutter SDK. If for example
313329
you jump to the definition of `StatelessWidget`, the lsp will not try and index the 100s (maybe 1000s) of

doc/flutter-tools.txt

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,6 @@ both are set.
312312
auto_open = false -- if true this will open the outline automatically when it is first populated
313313
},
314314
lsp = {
315-
color = { -- show the derived colours for dart variables
316-
enabled = false, -- whether or not to highlight color variables at all, only supported on flutter >= 2.10
317-
background = false, -- highlight the background
318-
background_color = nil, -- required, when background is transparent (i.e. background_color = { r = 19, g = 17, b = 24},)
319-
foreground = false, -- highlight the foreground
320-
virtual_text = true, -- show the highlight using virtual text
321-
virtual_text_str = "■", -- the virtual text character to highlight
322-
},
323315
on_attach = my_custom_on_attach,
324316
capabilities = my_custom_capabilities, -- e.g. lsp_status capabilities
325317
--- OR you can specify a function to deactivate or change or control how the config is created
@@ -345,6 +337,32 @@ You can override any options available in the `lspconfig` setup, this call
345337
essentially wraps it and adds some extra `flutter` specific handlers and
346338
utilisation options.
347339

340+
341+
DOCUMENT COLORS ~
342+
343+
Plugin-managed `lsp.color` rendering is deprecated and will be removed when
344+
flutter-tools.nvim requires Neovim `0.12+`.
345+
346+
On Neovim `0.12+`, use the built-in LSP document color support instead:
347+
348+
>lua
349+
vim.api.nvim_create_autocmd("LspAttach", {
350+
callback = function(ev)
351+
vim.lsp.document_color.enable(true, { bufnr = ev.buf })
352+
end,
353+
})
354+
<
355+
356+
If you want to opt out of Neovim's built-in document colors for some buffers:
357+
358+
>lua
359+
vim.api.nvim_create_autocmd("LspAttach", {
360+
callback = function(ev)
361+
vim.lsp.document_color.enable(false, { bufnr = ev.buf })
362+
end,
363+
})
364+
<
365+
348366
**NOTE:** By default this plugin excludes analysis of the packages in the
349367
flutter SDK. If for example you jump to the definition of `StatelessWidget`,
350368
the lsp will not try and index the 100s (maybe 1000s) of files in that

lua/flutter-tools/config.lua

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,46 @@ local deprecations = {
155155
fallback = "widget_guides",
156156
message = "please use 'widget_guides' instead",
157157
},
158+
lsp = {
159+
nested = {
160+
color = {
161+
when = function() return vim.fn.has("nvim-0.12") == 1 end,
162+
message = "plugin-managed document colors are deprecated and will be removed when flutter-tools.nvim requires Neovim 0.12+. On Neovim 0.12+, use vim.lsp.document_color.enable() instead",
163+
},
164+
},
165+
},
158166
}
159167

168+
local function notify_deprecation(key, message)
169+
vim.defer_fn(function()
170+
ui.notify(fmt("%s is deprecated: %s", key, message), ui.WARN, { once = true })
171+
end, 1000)
172+
end
173+
174+
local function should_notify_deprecation(deprecation)
175+
return not deprecation.when or deprecation.when()
176+
end
177+
178+
local function handle_nested_deprecation(prefix, value, deprecation)
179+
if type(value) ~= "table" or type(deprecation.nested) ~= "table" then return end
180+
for key, nested_value in pairs(value) do
181+
local nested_deprecation = deprecation.nested[key]
182+
if nested_deprecation then
183+
if nested_deprecation.message and should_notify_deprecation(nested_deprecation) then
184+
notify_deprecation(("%s.%s"):format(prefix, key), nested_deprecation.message)
185+
end
186+
handle_nested_deprecation(("%s.%s"):format(prefix, key), nested_value, nested_deprecation)
187+
end
188+
end
189+
end
190+
160191
local function handle_deprecation(key, value, conf)
161192
local deprecation = deprecations[key]
162193
if not deprecation then return end
163-
vim.defer_fn(
164-
function() ui.notify(fmt("%s is deprecated: %s", key, deprecation.message), ui.WARN) end,
165-
1000
166-
)
194+
if deprecation.message and should_notify_deprecation(deprecation) then
195+
notify_deprecation(key, deprecation.message)
196+
end
197+
handle_nested_deprecation(key, value, deprecation)
167198
if deprecation.fallback then conf[deprecation.fallback] = value end
168199
end
169200

tests/config_spec.lua

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
describe("config", function()
2+
local config
3+
local ui
4+
local notifications
5+
local original_has
6+
7+
before_each(function()
8+
notifications = {}
9+
original_has = vim.fn.has
10+
11+
package.loaded["flutter-tools.config"] = nil
12+
package.loaded["flutter-tools.ui"] = nil
13+
14+
ui = require("flutter-tools.ui")
15+
ui.notify = function(msg, level) table.insert(notifications, { msg = msg, level = level }) end
16+
17+
config = require("flutter-tools.config")
18+
end)
19+
20+
after_each(function()
21+
vim.fn.has = original_has
22+
package.loaded["flutter-tools.config"] = nil
23+
package.loaded["flutter-tools.ui"] = nil
24+
end)
25+
26+
it("warns when lsp.color is configured on Neovim 0.12+", function()
27+
vim.fn.has = function(feature)
28+
if feature == "nvim-0.12" then return 1 end
29+
return original_has(feature)
30+
end
31+
32+
config.set({
33+
lsp = {
34+
color = {
35+
enabled = true,
36+
},
37+
},
38+
})
39+
40+
vim.wait(1200)
41+
42+
assert.equal(1, #notifications)
43+
assert.equal(
44+
"lsp.color is deprecated: plugin-managed document colors are deprecated and will be removed when flutter-tools.nvim requires Neovim 0.12+. On Neovim 0.12+, use vim.lsp.document_color.enable() instead",
45+
notifications[1].msg
46+
)
47+
assert.equal(ui.WARN, notifications[1].level)
48+
end)
49+
50+
it("does not warn when lsp.color is configured before Neovim 0.12", function()
51+
vim.fn.has = function(feature)
52+
if feature == "nvim-0.12" then return 0 end
53+
return original_has(feature)
54+
end
55+
56+
config.set({
57+
lsp = {
58+
color = {
59+
enabled = true,
60+
},
61+
},
62+
})
63+
64+
vim.wait(1200)
65+
66+
assert.same({}, notifications)
67+
end)
68+
69+
it("does not warn when lsp.color is omitted", function()
70+
config.set({
71+
lsp = {
72+
debug = config.debug_levels.DEBUG,
73+
},
74+
})
75+
76+
vim.wait(1200)
77+
78+
assert.same({}, notifications)
79+
end)
80+
end)

0 commit comments

Comments
 (0)