From 8f0232af2a08ad881ac438a3ad85d2d6f7f6f05c Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Sun, 19 May 2024 21:06:32 +0800 Subject: [PATCH] [Optimized]: Remove some useless logic code --- lua/LspUI/inlay_hint/init.lua | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lua/LspUI/inlay_hint/init.lua b/lua/LspUI/inlay_hint/init.lua index 37c3b31..27a8714 100644 --- a/lua/LspUI/inlay_hint/init.lua +++ b/lua/LspUI/inlay_hint/init.lua @@ -1,14 +1,11 @@ -local api, lsp, fn = vim.api, vim.lsp, vim.fn +local api, lsp = vim.api, vim.lsp local inlay_hint_feature = lsp.protocol.Methods.textDocument_inlayHint local command = require("LspUI.command") local config = require("LspUI.config") local lib_util = require("LspUI.lib.util") --- TODO: this is a patch --- when 0.10 release, remove it -local inlay_hint = type(lsp.inlay_hint) == "table" and lsp.inlay_hint.enable - or lsp.inlay_hint +local inlay_hint = lsp.inlay_hint.enable local M = {} @@ -25,7 +22,6 @@ local is_open -- init for inlay hint M.init = function() - -- TODO: this logic can be changed to async if not config.options.inlay_hint.enable then return end @@ -36,14 +32,16 @@ M.init = function() is_initialized = true + -- when init the inlay_hint, open is true is_open = true + -- whether register the inlay_hint command if config.options.inlay_hint.command_enable then command.register_command(command_key, M.run, {}) end vim.schedule(function() - -- init for existed buffers + -- init for existed buffers (linked file) do local all_buffers = api.nvim_list_bufs() for _, buffer_id in pairs(all_buffers) do @@ -123,9 +121,8 @@ end M.run = function() is_open = not is_open + -- open if is_open then - -- open - for _, buffer_id in pairs(buffer_list) do if api.nvim_buf_is_valid(buffer_id) then inlay_hint(true, { @@ -133,15 +130,15 @@ M.run = function() }) end end - else - -- close + return + end - for _, buffer_id in pairs(buffer_list) do - if api.nvim_buf_is_valid(buffer_id) then - inlay_hint(false, { - bufnr = buffer_id, - }) - end + -- close + for _, buffer_id in pairs(buffer_list) do + if api.nvim_buf_is_valid(buffer_id) then + inlay_hint(false, { + bufnr = buffer_id, + }) end end end