Skip to content

Commit

Permalink
fix(ui): render labels only in the document range (#360)
Browse files Browse the repository at this point in the history
Co-authored-by: JordanH <[email protected]>
  • Loading branch information
JordanllHarper and JordanH-Apadmi authored Jun 25, 2024
1 parent 990a134 commit fd0443e
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lua/flutter-tools/labels.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local lazy = require("flutter-tools.lazy")
local ui = lazy.require("flutter-tools.ui") ---@module "flutter-tools.ui"
local config = lazy.require("flutter-tools.config") ---@module "flutter-tools.labels"

local api = vim.api
local fmt = string.format

local M = {}

Expand All @@ -16,18 +14,16 @@ local function render_labels(labels, opts)
local prefix = opts and opts.prefix or "// "

for _, item in ipairs(labels) do
local line = item.range["end"].line
local ok, err = pcall(api.nvim_buf_set_extmark, 0, namespace, tonumber(line), -1, {
virt_text = { {
prefix .. item.label,
highlight,
} },
virt_text_pos = "eol",
hl_mode = "combine",
})
if not ok then
local name = api.nvim_buf_get_name(0)
ui.notify(fmt("error drawing label for %s on line %d.\nbecause: ", name, line, err), ui.ERROR)
local line = tonumber(item.range["end"].line)
if line <= api.nvim_buf_line_count(0) then
api.nvim_buf_set_extmark(0, namespace, line, -1, {
virt_text = { {
prefix .. item.label,
highlight,
} },
virt_text_pos = "eol",
hl_mode = "combine",
})
end
end
end
Expand Down

0 comments on commit fd0443e

Please sign in to comment.