Skip to content

Commit e8199a2

Browse files
committed
feat: dim readOnly variables
1 parent 516c118 commit e8199a2

7 files changed

Lines changed: 24 additions & 14 deletions

File tree

lua/dap-view/globals.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ return {
44
NAMESPACE = vim.api.nvim_create_namespace("dap-view"),
55
NAMESPACE_VT = vim.api.nvim_create_namespace("dap-view-vt"),
66
HL_PREFIX = "NvimDapView",
7+
HAS_0_12 = vim.fn.has("nvim-0.12") == 1,
78
}

lua/dap-view/highlight.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ local globals = require("dap-view.globals")
22

33
local api = vim.api
44

5-
local has_0_12 = vim.fn.has("nvim-0.12") == 1
6-
75
---@param name string
86
---@param link string?
97
---@param opts vim.api.keyset.highlight?
@@ -54,7 +52,7 @@ local define_base_links = function()
5452
hl_create("Function", "Function")
5553
hl_create("Constant", "Constant")
5654

57-
if not has_0_12 then
55+
if not globals.HAS_0_12 then
5856
return
5957
end
6058

lua/dap-view/hover/view.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ local function show_variables(variables_reference, parent_path, line, depth, can
7979
state.hover_path_to_evaluate_name[path] = variable.evaluateName
8080
state.hover_path_to_parent_reference[path] = variables_reference
8181

82-
local type_hl_group = variable.type and hl.types_to_hl_group[variable.type:lower()]
82+
local type_hl_group = hl.hl_from_variable(variable)
8383

8484
local hl_start = depth + #prefix
8585
canvas.highlights[#canvas.highlights + 1] = {
@@ -135,7 +135,7 @@ M.show = function(bufnr)
135135

136136
canvas.contents[#canvas.contents + 1] = trimmed_content
137137

138-
local type_hl_group = hover.response.type and hl.types_to_hl_group[hover.response.type:lower()]
138+
local type_hl_group = hl.hl_from_variable(hover.response)
139139

140140
local hl_start = #prefix
141141
canvas.highlights[#canvas.highlights + 1] = {
@@ -157,7 +157,7 @@ M.show = function(bufnr)
157157

158158
width = #result
159159

160-
local type_hl_group = hover.response.type and hl.types_to_hl_group[hover.response.type:lower()]
160+
local type_hl_group = hl.hl_from_variable(hover.response)
161161

162162
canvas.highlights[#canvas.highlights + 1] = {
163163
type_hl_group and { type_hl_group, { height, 0 }, { height, -1 } } or nil,

lua/dap-view/scopes/view.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ local function show_variables(variables_reference, parent_path, line, depth, can
8686
state.variable_path_to_evaluate_name[path] = variable.evaluateName
8787
state.variable_path_to_parent_reference[path] = variables_reference
8888

89-
local type_hl_group = (updated and "WatchUpdated")
90-
or (variable.type and hl.types_to_hl_group[variable.type:lower()])
89+
local type_hl_group = (updated and "WatchUpdated") or hl.hl_from_variable(variable)
9190

9291
local hl_start = depth + #prefix
9392
canvas.highlights[#canvas.highlights + 1] = {

lua/dap-view/util/hl.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ M.types_to_hl_group = {
4242
asyncfunction = "Function",
4343
}
4444

45+
---@param v dap.Variable|dap.EvaluateResponse
46+
M.hl_from_variable = function(v)
47+
local hl = v.type and M.types_to_hl_group[v.type:lower()]
48+
49+
if
50+
globals.HAS_0_12
51+
and v.presentationHint
52+
and vim.tbl_contains(v.presentationHint.attributes or {}, "readOnly")
53+
then
54+
hl = hl .. "Dim"
55+
end
56+
57+
return hl
58+
end
59+
4560
return M

lua/dap-view/util/statusline.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ local global = require("dap-view.globals")
22

33
local M = {}
44

5-
local nightly = vim.fn.has("nvim-0.12") == 1
6-
75
---@param text string
86
---@param group string
97
---@param inherit boolean?
108
---@param clean boolean?
119
M.hl = function(text, group, inherit, clean)
12-
local field = (inherit and nightly) and "$" or "#"
10+
local field = (inherit and global.HAS_0_12) and "$" or "#"
1311
local part = "%" .. field .. global.HL_PREFIX .. group .. field .. text
1412
if clean or clean == nil then
1513
return part .. "%*"

lua/dap-view/watches/view.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ local function show_variables(children, reference, line, depth)
3838
local hl_start = depth + #prefix
3939
hl.hl_range("WatchExpr", { line, hl_start }, { line, hl_start + #variable.name })
4040

41-
local hl_group = (child.updated and "WatchUpdated")
42-
or (variable.type and hl.types_to_hl_group[variable.type:lower()])
41+
local hl_group = (child.updated and "WatchUpdated") or hl.hl_from_variable(variable)
4342

4443
if hl_group then
4544
hl.hl_range(hl_group, { line, hl_start + #variable.name + 3 }, { line, -1 })
@@ -131,7 +130,7 @@ M.show = function()
131130

132131
local hl_group = err and "WatchError"
133132
or view.updated and "WatchUpdated"
134-
or response and response.type and hl.types_to_hl_group[response.type:lower()]
133+
or response and hl.hl_from_variable(response)
135134

136135
if hl_group then
137136
local hl_start = #prefix + #expression + 3

0 commit comments

Comments
 (0)