Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): render labels only in the document range #360

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading