diff --git a/lua/litee/lib/config.lua b/lua/litee/lib/config.lua index 3bd8b7a..5cc10cb 100644 --- a/lua/litee/lib/config.lua +++ b/lua/litee/lib/config.lua @@ -26,8 +26,8 @@ M.config = { tree = { icon_set = "default", icon_set_custom = nil, - indent_guides = true - } + indent_guides = true, + }, } return M diff --git a/lua/litee/lib/details/init.lua b/lua/litee/lib/details/init.lua index 09e40f8..6b8be6e 100644 --- a/lua/litee/lib/details/init.lua +++ b/lua/litee/lib/details/init.lua @@ -6,8 +6,7 @@ local float_win = nil -- close_details_popups closes the created popup window -- if it exists. function M.close_details_popup() - if float_win ~= nil and - vim.api.nvim_win_is_valid(float_win) then + if float_win ~= nil and vim.api.nvim_win_is_valid(float_win) then vim.api.nvim_win_close(float_win, true) float_win = nil end @@ -27,11 +26,11 @@ end function M.details_popup(state, node, detail_func) local buf = vim.api.nvim_create_buf(false, true) if buf == 0 then - vim.api.nvim_err_writeln("details_popup: could not create details buffer") + vim.notify("details_popup: could not create details buffer", vim.log.levels.ERROR) return end - vim.api.nvim_buf_set_option(buf, 'bufhidden', 'delete') - vim.api.nvim_buf_set_option(buf, 'syntax', 'yaml') + vim.api.nvim_set_option_value("bufhidden", "delete", { buf = buf }) + vim.api.nvim_set_option_value("syntax", "yaml", { buf = buf }) local lines = detail_func(state, node) if lines == nil then @@ -46,18 +45,14 @@ function M.details_popup(state, node, detail_func) end end - vim.api.nvim_buf_set_option(buf, 'modifiable', true) + vim.api.nvim_set_option_value("modifiable", true, { buf = buf }) vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines) - vim.api.nvim_buf_set_option(buf, 'modifiable', false) - local popup_conf = vim.lsp.util.make_floating_popup_options( - width, - #lines, - { - border= "rounded", - focusable= false, - zindex = 99, - } - ) + vim.api.nvim_set_option_value("modifiable", false, { buf = buf }) + local popup_conf = vim.lsp.util.make_floating_popup_options(width, #lines, { + border = "rounded", + focusable = false, + zindex = 99, + }) float_win = vim.api.nvim_open_win(buf, false, popup_conf) end diff --git a/lua/litee/lib/highlights/auto.lua b/lua/litee/lib/highlights/auto.lua index 0b49eb4..1eab05f 100644 --- a/lua/litee/lib/highlights/auto.lua +++ b/lua/litee/lib/highlights/auto.lua @@ -1,5 +1,5 @@ -local lib_util = require('litee.lib.util') -local lib_hi = require('litee.lib.highlights') +local lib_util = require("litee.lib.util") +local lib_hi = require("litee.lib.highlights") local M = {} @@ -26,12 +26,7 @@ function M.highlight(node, set, win) if not vim.api.nvim_buf_is_valid(buf) then return end - vim.api.nvim_buf_clear_namespace( - buf, - M.higlight_ns, - 0, - -1 - ) + vim.api.nvim_buf_clear_namespace(buf, M.higlight_ns, 0, -1) if not set then return end @@ -54,15 +49,11 @@ function M.highlight(node, set, win) return end - vim.api.nvim_buf_add_highlight( - buf, - M.higlight_ns, - lib_hi.hls.SymbolJumpHL, - range["start"].line, - range["start"].character, - range["end"].character - ) - vim.api.nvim_win_set_cursor(win, {range["start"].line+1, 0}) + vim.api.nvim_buf_set_extmark(buf, M.higlight_ns, range["start"].line, range["start"].character, { + end_col = range["end"].character, + hl_group = lib_hi.hls.SymbolJumpHL, + }) + vim.api.nvim_win_set_cursor(win, { range["start"].line + 1, 0 }) end return M diff --git a/lua/litee/lib/highlights/init.lua b/lua/litee/lib/highlights/init.lua index cf31a92..63cfb77 100644 --- a/lua/litee/lib/highlights/init.lua +++ b/lua/litee/lib/highlights/init.lua @@ -3,81 +3,59 @@ local M = {} -- hls is a map of UI specific highlights used -- by the litee.nvim library. M.hls = { - SymbolDetailHL = "LTSymbolDetail", - SymbolHL = "LTSymbol", - SymbolJumpHL = "LTSymbolJump", - SymbolJumpRefsHL = "LTSymbolJumpRefs", - IndentGuideHL = "LTIndentGuide", - ExpandedGuideHL = "LTExpandedGuide", - CollapsedGuideHL = "LTCollapsedGuide", - SelectFiletreeHL = "LTSelectFiletree", - NormalSB = "LTNormalSB" + SymbolDetailHL = "LTSymbolDetail", + SymbolHL = "LTSymbol", + SymbolJumpHL = "LTSymbolJump", + SymbolJumpRefsHL = "LTSymbolJumpRefs", + IndentGuideHL = "LTIndentGuide", + ExpandedGuideHL = "LTExpandedGuide", + CollapsedGuideHL = "LTCollapsedGuide", + SelectFiletreeHL = "LTSelectFiletree", + NormalSB = "LTNormalSB", + SymbolNameColor0 = "LTSymbolNameColor0", + SymbolNameColor1 = "LTSymbolNameColor1", + SymbolNameColor2 = "LTSymbolNameColor2", + SymbolNameColor3 = "LTSymbolNameColor3", + SymbolNameColor4 = "LTSymbolNameColor4", + SymbolNameColor5 = "LTSymbolNameColor5", } -- setup_default_highlights configures a list of default -- highlights for the litee.nvim library. function M.setup_default_highlights() local dark = { - LTBoolean = 'hi LTBoolean guifg=#0087af guibg=None', - LTConstant = 'hi LTConstant guifg=#0087af guibg=None', - LTConstructor = 'hi LTConstructor guifg=#4DC5C6 guibg=None', - LTField = 'hi LTField guifg=#0087af guibg=None', - LTFunction = 'hi LTFunction guifg=#988ACF guibg=None', - LTMethod = 'hi LTMethod guifg=#0087af guibg=None', - LTNamespace = 'hi LTNamespace guifg=#87af87 guibg=None', - LTNumber = 'hi LTNumber guifg=#9b885c guibg=None', - LTOperator = 'hi LTOperator guifg=#988ACF guibg=None', - LTParameter = 'hi LTParameter guifg=#988ACF guibg=None', - LTParameterReference = 'hi LTParameterReference guifg=#4DC5C6 guibg=None', - LTString = 'hi LTString guifg=#af5f5f guibg=None', - LTSymbol = 'hi LTSymbol guifg=#87afd7 ', - LTSymbolDetail = 'hi LTSymbolDetail ctermfg=024 cterm=italic guifg=#988ACF gui=italic', - LTSymbolJump = 'hi LTSymbolJump ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#87afd7 gui=italic,bold', - LTSymbolJumpRefs = 'hi LTSymbolJumpRefs ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#9b885c gui=italic,bold', - LTType = 'hi LTType guifg=#9b885c guibg=None', - LTURI = 'hi LTURI guifg=#988ACF guibg=None', - LTIndentGuide = 'hi LTIndentGuide guifg=None guibg=None', - LTExpandedGuide = 'hi LTExpandedGuide guifg=None guibg=None', - LTCollapsedGuide = 'hi LTCollapsedGuide guifg=None guibg=None', - LTSelectFiletree = 'hi LTSelectFiletree ctermbg=131 ctermfg=246 cterm=None guibg=#af5f5f guifg=#e4e4e4 gui=None' + LTBoolean = "hi LTBoolean guifg=#0087af guibg=None", + LTConstant = "hi LTConstant guifg=#0087af guibg=None", + LTConstructor = "hi LTConstructor guifg=#4DC5C6 guibg=None", + LTField = "hi LTField guifg=#0087af guibg=None", + LTFunction = "hi LTFunction guifg=#988ACF guibg=None", + LTMethod = "hi LTMethod guifg=#0087af guibg=None", + LTNamespace = "hi LTNamespace guifg=#87af87 guibg=None", + LTNumber = "hi LTNumber guifg=#9b885c guibg=None", + LTOperator = "hi LTOperator guifg=#988ACF guibg=None", + LTParameter = "hi LTParameter guifg=#988ACF guibg=None", + LTParameterReference = "hi LTParameterReference guifg=#4DC5C6 guibg=None", + LTString = "hi LTString guifg=#af5f5f guibg=None", + LTSymbol = "hi LTSymbol guifg=#87afd7 ", + LTSymbolDetail = "hi LTSymbolDetail ctermfg=024 cterm=italic guifg=#988ACF gui=italic", + LTSymbolJump = "hi LTSymbolJump ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#87afd7 gui=italic,bold", + LTSymbolJumpRefs = "hi LTSymbolJumpRefs ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#9b885c gui=italic,bold", + LTType = "hi LTType guifg=#9b885c guibg=None", + LTURI = "hi LTURI guifg=#988ACF guibg=None", + LTIndentGuide = "hi LTIndentGuide guifg=None guibg=None", + LTExpandedGuide = "hi LTExpandedGuide guifg=None guibg=None", + LTCollapsedGuide = "hi LTCollapsedGuide guifg=None guibg=None", + LTSelectFiletree = "hi LTSelectFiletree ctermbg=131 ctermfg=246 cterm=None guibg=#af5f5f guifg=#e4e4e4 gui=None", + LTSymbolNameColor0 = "hi LTSymbolNameColor0 guifg=#8CCBEA guibg=None", + LTSymbolNameColor1 = "hi LTSymbolNameColor1 guifg=#A4E57E guibg=None", + LTSymbolNameColor2 = "hi LTSymbolNameColor2 guifg=#FFDB72 guibg=None", + LTSymbolNameColor3 = "hi LTSymbolNameColor3 guifg=#FF7272 guibg=None", + LTSymbolNameColor4 = "hi LTSymbolNameColor4 guifg=#FFB3FF guibg=None", + LTSymbolNameColor5 = "hi LTSymbolNameColor5 guifg=#9999FF guibg=None", } - local light = { - LTBoolean = 'hi LTBoolean guifg=#005f87 guibg=None', - LTConstant = 'hi LTConstant guifg=#005f87 guibg=None', - LTConstructor = 'hi LTConstructor guifg=#9b885c guibg=None', - LTField = 'hi LTField guifg=#005f87 guibg=None', - LTFunction = 'hi LTFunction guifg=#806CCF guibg=None', - LTMethod = 'hi LTMethod guifg=#005f87 guibg=None', - LTNamespace = 'hi LTNamespace guifg=#87af87 guibg=None', - LTNumber = 'hi LTNumber guifg=#9b885c guibg=None', - LTOperator = 'hi LTOperator guifg=#806CCF guibg=None', - LTParameter = 'hi LTParameter guifg=#806CCF guibg=None', - LTParameterReference = 'hi LTParameterReference guifg=#268889 guibg=None', - LTString = 'hi LTString guifg=#af5f5f guibg=None', - LTSymbol = 'hi LTSymbol guifg=#806CCF gui=underline', - LTSymbolDetail = 'hi LTSymbolDetail ctermfg=024 cterm=italic guifg=#005f87 gui=italic', - LTSymbolJump = 'hi LTSymbolJump ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#87afd7 gui=italic,bold', - LTSymbolJumpRefs = 'hi LTSymbolJumpRefs ctermfg=015 ctermbg=110 cterm=italic,bold,underline guifg=#464646 guibg=#9b885c gui=italic,bold', - LTType = 'hi LTType guifg=#268889 guibg=None', - LTURI = 'hi LTURI guifg=#806CCF guibg=None', - LTIndentGuide = 'hi LTIndentGuide guifg=None guibg=None', - LTExpandedGuide = 'hi LTExpandedGuide guifg=None guibg=None', - LTCollapsedGuide = 'hi LTCollapsedGuide guifg=None guibg=None', - LTSelectFiletree = 'hi LTSelectFiletree ctermbg=131 ctermfg=246 cterm=None guibg=#af5f5f guifg=#e4e4e4 gui=None' - } - local bg = vim.api.nvim_get_option("background") - if bg == "dark" then - for hl_name, hl in pairs(dark) do - if vim.fn.hlexists(hl_name) == 0 then - vim.cmd(hl) - end - end - end - if bg == "light" then - for hl_name, hl in pairs(light) do - if vim.fn.hlexists(hl_name) == 0 then - vim.cmd(hl) - end + for hl_name, hl in pairs(dark) do + if vim.fn.hlexists(hl_name) == 0 then + vim.cmd(hl) end end end diff --git a/lua/litee/lib/icons/init.lua b/lua/litee/lib/icons/init.lua index 57c8fd3..c8af1d7 100644 --- a/lua/litee/lib/icons/init.lua +++ b/lua/litee/lib/icons/init.lua @@ -3,349 +3,349 @@ local M = {} -- a lot of these are yoinked from: -- https://github.com/onsails/lspkind-nvim/blob/master/lua/lspkind/init.lua M.nerd = { - Account = '', - Array = "", - Bookmark = "", - Boolean = "", - Calendar = '', - Check = '', - CheckAll = '', - Circle = '', - CircleFilled = '', - CirclePause = '', - CircleSlash = '', - CircleStop = '', - Class = "ﴯ", - Collapsed = "", - Color = "", - Comment = '', - Constant = "", - Constructor = "", - DiffAdded = '', - Enum = "", - EnumMember = "", - Event = "", - Expanded = "", - Field = "ﰠ", - File = "", - Folder = "", - Function = "", - GitBranch = '', - GitCommit = 'ﰖ', - GitCompare = '', - GitIssue = '', - GitMerge = 'שּׁ', - GitPullRequest = '', - GitRepo = '', - IndentGuide = "⎸", - Info = '', - Interface = "", - Key = "", - Keyword = "", - Method = "", - Module = "", - MultiComment = '', - Namespace = "", - Notebook = "ﴬ", - Null = "ﳠ", - Number = "", - Object = "", - Operator = "", - Package = "", - Pass = '', - PassFilled = '', - Pencil = '', - Property = "ﰠ", - Reference = "", - Separator = "•", - Snippet = "", - Space = " ", - String = "", - Struct = "פּ", - Text = "", - TypeParameter = "", - Unit = "塞", - Value = "", - Variable = "", + Account = "", + Array = "", + Bookmark = "", + Boolean = "", + Calendar = "", + Check = "", + CheckAll = "", + Circle = "", + CircleFilled = "", + CirclePause = "", + CircleSlash = "", + CircleStop = "", + Class = "ﴯ", + Collapsed = "", + Color = "", + Comment = "", + Constant = "", + Constructor = "", + DiffAdded = "", + Enum = "", + EnumMember = "", + Event = "", + Expanded = "", + Field = "ﰠ", + File = "", + Folder = "", + Function = "", + GitBranch = "", + GitCommit = "ﰖ", + GitCompare = "", + GitIssue = "", + GitMerge = "שּׁ", + GitPullRequest = "", + GitRepo = "", + IndentGuide = " ", + Info = "", + Interface = "", + Key = "", + Keyword = "", + Method = "", + Module = "", + MultiComment = "", + Namespace = "", + Notebook = "ﴬ", + Null = "ﳠ", + Number = "", + Object = "", + Operator = "", + Package = "", + Pass = "", + PassFilled = "", + Pencil = "", + Property = "ﰠ", + Reference = "", + Separator = "•", + Snippet = "", + Space = " ", + String = "", + Struct = "פּ", + Text = "", + TypeParameter = "", + Unit = "塞", + Value = "", + Variable = "", } M.codicons = { - Account = '', - Array = "", - Bookmark = "", - Boolean = "", - Calendar = '', - Check = '', - CheckAll = '', - Circle = '', - CircleFilled = '', - CirclePause = '', - CircleSlash = '', - CircleStop = '', - Class = "", - Collapsed = "", - Color = "", - Comment = '', - CommentExclaim = '', - Constant = "", - Constructor = "", - DiffAdded = '', - Enum = "", - EnumMember = "", - Event = "", - Expanded = "", - Field = "", - File = "", - Folder = "", - Function = "", - GitBranch = '', - GitCommit = '', - GitCompare = '', - GitIssue = '', - GitMerge = '', - GitPullRequest = '', - GitRepo = '', - History = '', - IndentGuide = "⎸", - Info = '', - Interface = "", - Key = "", - Keyword = "", - Method = "", - Module = "", - MultiComment = '', - Namespace = "", - Notebook = "", - Notification = '', - Null = "", - Number = "", - Object = "", - Operator = "", - Package = "", - Pass = '', - PassFilled = '', - Pencil = '', - Property = "", - Reference = "", - RequestChanges = '', - Separator = "•", - Snippet = "", - Space = " ", - String = "", - Struct = "", - Sync = '', - Text = "", - TypeParameter = "", - Unit = "", - Value = "", - Variable = "", + Account = "", + Array = "", + Bookmark = "", + Boolean = "", + Calendar = "", + Check = "", + CheckAll = "", + Circle = "", + CircleFilled = "", + CirclePause = "", + CircleSlash = "", + CircleStop = "", + Class = "", + Collapsed = "", + Color = "", + Comment = "", + CommentExclaim = "", + Constant = "", + Constructor = "", + DiffAdded = "", + Enum = "", + EnumMember = "", + Event = "", + Expanded = "", + Field = "", + File = "", + Folder = "", + Function = "", + GitBranch = "", + GitCommit = "", + GitCompare = "", + GitIssue = "", + GitMerge = "", + GitPullRequest = "", + GitRepo = "", + History = "", + IndentGuide = " ", + Info = "", + Interface = "", + Key = "", + Keyword = "", + Method = "", + Module = "", + MultiComment = "", + Namespace = "", + Notebook = "", + Notification = "", + Null = "", + Number = "", + Object = "", + Operator = "", + Package = "", + Pass = "", + PassFilled = "", + Pencil = "", + Property = "", + Reference = "", + RequestChanges = "", + Separator = "•", + Snippet = "", + Space = " ", + String = "", + Struct = "", + Sync = "", + Text = "", + TypeParameter = "", + Unit = "", + Value = "", + Variable = "", } M.default = { - Account = "🗣", - Array = "\\[\\]", - Bookmark = "🏷", - Boolean = "∧", - Calendar = '🗓', - Check = '✓', - CheckAll = '🗸🗸', - Circle = '🞆', - CircleFilled = '●', - CirclePause = '⦷', - CircleSlash = '⊘', - CircleStop = '⦻', - Class = "c", - Collapsed = "▶", - Color = "🖌", - Comment = '🗩', - CommentExclaim = '🗩', - Constant = "c", - Constructor = "c", - DiffAdded = '+', - Enum = "Ε", - EnumMember = "Ε", - Event = "🗲", - Expanded = "▼", - Field = "𝐟", - File = "🗀", - Folder = "🗁", - Function = "ƒ", - GitBranch = ' ', - GitCommit = '⫰', - GitCompare = '⤄', - GitIssue = '⊙', - GitMerge = '⫰', - GitPullRequest = '⬰', - GitRepo = '🕮', - History = '⟲', - IndentGuide = "⎸", - Info = '🛈', - Interface = "I", - Key = "", - Keyword = "", - Method = "", - Module = "M", - MultiComment = '🗩', - Namespace = "N", - Notebook = "🕮", - Notification = '🕭', - Null = "null", - Number = "#", - Object = "{}", - Operator = "0", - Package = "{}", - Pass = '🗸', - PassFilled = '🗸', - Pencil = '', - Property = "🛠", - Reference = "⛉", - RequestChanges = '⨪', - Separator = "•", - Space = " ", - String = "\"", - Struct = "struct", - Sync = '🗘', - Text = "\"", - TypeParameter = "T", - Unit = "U", - Value = "v", - Variable = "V", + Account = "🗣", + Array = "\\[\\]", + Bookmark = "🏷", + Boolean = "∧", + Calendar = "🗓", + Check = "✓", + CheckAll = "🗸🗸", + Circle = "🞆", + CircleFilled = "●", + CirclePause = "⦷", + CircleSlash = "⊘", + CircleStop = "⦻", + Class = "c", + Collapsed = "▶", + Color = "🖌", + Comment = "🗩", + CommentExclaim = "🗩", + Constant = "c", + Constructor = "c", + DiffAdded = "+", + Enum = "Ε", + EnumMember = "Ε", + Event = "🗲", + Expanded = "▼", + Field = "𝐟", + File = "🗀", + Folder = "🗁", + Function = "ƒ", + GitBranch = " ", + GitCommit = "⫰", + GitCompare = "⤄", + GitIssue = "⊙", + GitMerge = "⫰", + GitPullRequest = "⬰", + GitRepo = "🕮", + History = "⟲", + IndentGuide = " ", + Info = "🛈", + Interface = "I", + Key = "", + Keyword = "", + Method = "", + Module = "M", + MultiComment = "🗩", + Namespace = "N", + Notebook = "🕮", + Notification = "🕭", + Null = "null", + Number = "#", + Object = "{}", + Operator = "0", + Package = "{}", + Pass = "🗸", + PassFilled = "🗸", + Pencil = "", + Property = "🛠", + Reference = "⛉", + RequestChanges = "⨪", + Separator = "•", + Space = " ", + String = '"', + Struct = "struct", + Sync = "🗘", + Text = '"', + TypeParameter = "T", + Unit = "U", + Value = "v", + Variable = "V", } M.simple = { - Account = "A", - Array = "\\[\\]", - Bookmark = "BM", - Boolean = "bool", - Calendar = 'cal', - Check = 'x', - CheckAll = 'xx', - Circle = 'o', - CircleFilled = 'O', - CirclePause = 'P', - CircleSlash = 'ø', - CircleStop = 'stop', - Class = "class", - Collapsed = ">", - Color = "color", - Comment = 'c', - CommentExclaim = 'c!', - Constant = "c", - Constructor = "C", - DiffAdded = '+', - Enum = "Ε", - EnumMember = "Ε", - Event = "e", - Expanded = "v", - Field = "f", - File = "F", - Folder = "D", - Function = "fn", - GitBranch = 'br', - GitCommit = 'ci', - GitCompare = 'cmp', - GitIssue = 'I', - GitMerge = 'M', - GitPullRequest = 'PR', - GitRepo = 'R', - History = 'H', - IndentGuide = " ", - Info = 'i', - Interface = "I", - Key = "k", - Keyword = "kw", - Method = "m", - Module = "M", - MultiComment = '#', - Namespace = "NS", - Notebook = "NB", - Notification = 'N', - Null = "null", - Number = "#", - Object = "{}", - Operator = "op", - Package = "{}", - Pass = 'y', - PassFilled = 'yy', - Pencil = 'e', - Property = "P", - Reference = "&", - RequestChanges = '-', - Separator = ".", - Space = " ", - String = "\"", - Struct = "S", - Sync = 's', - Text = "\"", - TypeParameter = "T", - Unit = "U", - Value = "v", - Variable = "V", + Account = "A", + Array = "\\[\\]", + Bookmark = "BM", + Boolean = "bool", + Calendar = "cal", + Check = "x", + CheckAll = "xx", + Circle = "o", + CircleFilled = "O", + CirclePause = "P", + CircleSlash = "ø", + CircleStop = "stop", + Class = "class", + Collapsed = ">", + Color = "color", + Comment = "c", + CommentExclaim = "c!", + Constant = "c", + Constructor = "C", + DiffAdded = "+", + Enum = "Ε", + EnumMember = "Ε", + Event = "e", + Expanded = "v", + Field = "f", + File = "F", + Folder = "D", + Function = "fn", + GitBranch = "br", + GitCommit = "ci", + GitCompare = "cmp", + GitIssue = "I", + GitMerge = "M", + GitPullRequest = "PR", + GitRepo = "R", + History = "H", + IndentGuide = " ", + Info = "i", + Interface = "I", + Key = "k", + Keyword = "kw", + Method = "m", + Module = "M", + MultiComment = "#", + Namespace = "NS", + Notebook = "NB", + Notification = "N", + Null = "null", + Number = "#", + Object = "{}", + Operator = "op", + Package = "{}", + Pass = "y", + PassFilled = "yy", + Pencil = "e", + Property = "P", + Reference = "&", + RequestChanges = "-", + Separator = ".", + Space = " ", + String = '"', + Struct = "S", + Sync = "s", + Text = '"', + TypeParameter = "T", + Unit = "U", + Value = "v", + Variable = "V", } M.icon_hls = { - Array = "LTConstant", - Boolean = "LTBoolean", - Class = "LTType", - Constant = "LTConstant", - Constructor = "LTFunction", - Enum = "LTType", - EnumMember = "LTField", - Event = "LTType", - Field = "LTField", - File = "LTURI", - Folder = "LTNamespace", - Function = "LTFunction", - Interface = "LTType", - Key = "LTType", - Keyword = "LTConstant", - Method = "LTFunction", - Module = "LTNamespace", - Namespace = "LTNamespace", - Null = "LTType", - Number = "LTNumber", - Object = "LTType", - Operator = "LTOperator", - Package = "LTNamespace", - Property = "LTMethod", - Reference = "LTType", - Snippet = "LTString", - String = "LTString", - Struct = "LTType", - Text = "LTString", - TypeParameter = "LTParameter", - Unit = "LTType", - Value = "LTType", - Variable = "LTConstant", + Array = "LTConstant", + Boolean = "LTBoolean", + Class = "LTType", + Constant = "LTConstant", + Constructor = "LTFunction", + Enum = "LTType", + EnumMember = "LTField", + Event = "LTType", + Field = "LTField", + File = "LTURI", + Folder = "LTNamespace", + Function = "LTFunction", + Interface = "LTType", + Key = "LTType", + Keyword = "LTConstant", + Method = "LTFunction", + Module = "LTNamespace", + Namespace = "LTNamespace", + Null = "LTType", + Number = "LTNumber", + Object = "LTType", + Operator = "LTOperator", + Package = "LTNamespace", + Property = "LTMethod", + Reference = "LTType", + Snippet = "LTString", + String = "LTString", + Struct = "LTType", + Text = "LTString", + TypeParameter = "LTParameter", + Unit = "LTType", + Value = "LTType", + Variable = "LTConstant", - Info = 'LTInfo', - Pass = 'LTSuccess', - PassFilled = 'LTSuccess', - Account = 'LTAccount', - Check = 'LTSuccess', - CheckAll = 'LTSuccess', - CircleFilled = 'LTDefault', - Circle = 'LTDefault', - CircleSlash = 'LTWarning', - GitCompare = 'LTGitCompare', - GitBranch = 'LTGitBranch', - GitPullRequest = 'LTGitPullRequest', - CircleStop = 'LTFailure', - DiffAdded = 'LTDiffAdded', - CirclePause = 'LTWarning', - GitCommit = 'LTGitCommit', + Info = "LTInfo", + Pass = "LTSuccess", + PassFilled = "LTSuccess", + Account = "LTAccount", + Check = "LTSuccess", + CheckAll = "LTSuccess", + CircleFilled = "LTDefault", + Circle = "LTDefault", + CircleSlash = "LTWarning", + GitCompare = "LTGitCompare", + GitBranch = "LTGitBranch", + GitPullRequest = "LTGitPullRequest", + CircleStop = "LTFailure", + DiffAdded = "LTDiffAdded", + CirclePause = "LTWarning", + GitCommit = "LTGitCommit", - Comment = 'LTComment', - MultiComment = 'LTMultiComment', + Comment = "LTComment", + MultiComment = "LTMultiComment", - Calendar = 'LTDefault', - Pencil = 'LTWarning', + Calendar = "LTDefault", + Pencil = "LTWarning", - History = 'LTWarning', - Sync = 'LTWarning', - CommentExclaim = 'LTWarning', - RequestChanges = 'LTFailure', - Notification = 'LTDiffAdded' + History = "LTWarning", + Sync = "LTWarning", + CommentExclaim = "LTWarning", + RequestChanges = "LTFailure", + Notification = "LTDiffAdded", } return M diff --git a/lua/litee/lib/init.lua b/lua/litee/lib/init.lua index 0aad121..5ce6cc0 100644 --- a/lua/litee/lib/init.lua +++ b/lua/litee/lib/init.lua @@ -1,7 +1,7 @@ -local commands = require('litee.lib.commands') -local config = require('litee.lib.config').config -local lib_hi = require('litee.lib.highlights') -local lib_icons = require('litee.lib.icons') +local commands = require("litee.lib.commands") +local config = require("litee.lib.config").config +local lib_hi = require("litee.lib.highlights") +local lib_icons = require("litee.lib.icons") local M = {} @@ -11,17 +11,17 @@ M.icon_set = nil local function icon_set() local tree = config.tree local base = lib_icons[tree.icon_set] or lib_icons["default"] - local icon_set = nil + local icons = nil if tree.icon_set_custom ~= nil then - icon_set = tree.icon_set_custom + icons = tree.icon_set_custom -- merge custom icon with the default - for key, val in pairs(base) do - icon_set[key] = icon_set[key] or base[key] + for key, _ in pairs(base) do + icons[key] = icons[key] or base[key] end else - icon_set = base + icons = base end - M.icon_set = icon_set + M.icon_set = icons end -- If a custom icon_set (table) is provided by the user, @@ -31,16 +31,16 @@ end -- When both arguments are provided, the custom icon_set is merged -- with the icons given by its name from `lib_icons`. function M.icon_set_update(custom, icon_key) - local icon_set = nil + local icons = nil if custom ~= nil then - icon_set = icon_key and lib_icons[icon_key] or M.icon_set - for key, val in pairs(custom) do - icon_set[key] = custom[key] + icons = icon_key and lib_icons[icon_key] or M.icon_set + for key, _ in pairs(custom) do + icons[key] = custom[key] end else - icon_set = lib_icons[icon_key] or lib_icons["default"] + icons = lib_icons[icon_key] or lib_icons["default"] end - return icon_set + return icons end local function merge_subconfig(component, user_subconfig) diff --git a/lua/litee/lib/jumps/init.lua b/lua/litee/lib/jumps/init.lua index 1474e43..7cb923e 100644 --- a/lua/litee/lib/jumps/init.lua +++ b/lua/litee/lib/jumps/init.lua @@ -1,6 +1,16 @@ -local config = require('litee.lib.config').config -local lib_hi = require('litee.lib.highlights') -local lib_panel = require('litee.lib.panel') +local config = require("litee.lib.config").config +local lib_hi = require("litee.lib.highlights") +local lib_panel = require("litee.lib.panel") + +local function jump_to_location(location) + local client = vim.lsp.get_clients({ bufnr = bufnr })[1] + local offset_encoding = client and client.offset_encoding or "utf-16" + if vim.lsp.util.show_document then + vim.lsp.util.show_document(location, offset_encoding, { focus = true }) + else + vim.lsp.util.jump_to_location(location, offset_encoding, true) + end +end local M = {} @@ -22,13 +32,13 @@ M.last_highlighted_buffer = nil local function move_or_create(orientation) local cur_win = vim.api.nvim_get_current_win() if orientation == "left" then - vim.cmd('wincmd l') + vim.cmd("wincmd l") elseif orientation == "right" then - vim.cmd('wincmd h') + vim.cmd("wincmd h") elseif orientation == "top" then - vim.cmd('wincmd j') + vim.cmd("wincmd j") elseif orientation == "bottom" then - vim.cmd('wincmd k') + vim.cmd("wincmd k") end if cur_win == vim.api.nvim_get_current_win() then if orientation == "left" then @@ -62,7 +72,7 @@ function M.jump_tab(location, node, offset_encoding) -- if the panel currently has a component "popped-out" -- close it before jumping. lib_panel.close_current_popout() - vim.lsp.util.jump_to_location(location, offset_encoding or "utf-8") + jump_to_location(location, offset_encoding or "utf-8") M.set_jump_hl(true, node) end @@ -83,7 +93,7 @@ function M.jump_split(split, location, node, offset_encoding) -- if the panel currently has a component "popped-out" -- close it before jumping. lib_panel.close_current_popout() - vim.lsp.util.jump_to_location(location, offset_encoding or "utf-8") + jump_to_location(location, offset_encoding or "utf-8") M.set_jump_hl(true, node) end @@ -103,14 +113,14 @@ function M.jump_neighbor(location, node, offset_encoding) -- if the panel currently has a component "popped-out" -- close it before jumping. lib_panel.close_current_popout() - vim.lsp.util.jump_to_location(location, offset_encoding or "utf-8") + jump_to_location(location, offset_encoding or "utf-8") M.set_jump_hl(true, node) -- cleanup any [No Name] buffers if they exist for _, buf in ipairs(vim.api.nvim_list_bufs()) do local name = vim.api.nvim_buf_get_name(buf) if name == "" then - vim.api.nvim_buf_delete(buf, {force=true}) + vim.api.nvim_buf_delete(buf, { force = true }) end end end @@ -147,14 +157,14 @@ function M.jump_invoking(location, win, node, offset_encoding) -- if the panel currently has a component "popped-out" -- close it before jumping. lib_panel.close_current_popout() - vim.lsp.util.jump_to_location(location, offset_encoding or "utf-8") + jump_to_location(location, offset_encoding or "utf-8") M.set_jump_hl(true, node) -- cleanup any [No Name] buffers if they exist for _, buf in ipairs(vim.api.nvim_list_bufs()) do local name = vim.api.nvim_buf_get_name(buf) if name == "" then - vim.api.nvim_buf_delete(buf, {force=true}) + vim.api.nvim_buf_delete(buf, { force = true }) end end @@ -174,16 +184,8 @@ end -- they will be highlighted as well. function M.set_jump_hl(set, node) if not set then - if - M.last_highlighted_buffer ~= nil - and vim.api.nvim_buf_is_valid(M.last_highlighted_buffer) - then - vim.api.nvim_buf_clear_namespace( - M.last_highlighted_buffer, - M.jump_higlight_ns, - 0, - -1 - ) + if M.last_highlighted_buffer ~= nil and vim.api.nvim_buf_is_valid(M.last_highlighted_buffer) then + vim.api.nvim_buf_clear_namespace(M.last_highlighted_buffer, M.jump_higlight_ns, 0, -1) end return end diff --git a/lua/litee/lib/lsp/hover.lua b/lua/litee/lib/lsp/hover.lua index 007b620..a1da046 100644 --- a/lua/litee/lib/lsp/hover.lua +++ b/lua/litee/lib/lsp/hover.lua @@ -5,8 +5,7 @@ local float_win = nil -- close_hover_popups closes the created popup window -- if it exists. function M.close_hover_popup() - if float_win ~= nil and - vim.api.nvim_win_is_valid(float_win) then + if float_win ~= nil and vim.api.nvim_win_is_valid(float_win) then vim.api.nvim_win_close(float_win, true) float_win = nil end @@ -23,25 +22,25 @@ function M.hover_handler(_, result, ctx, config) config = config or {} config.focus_id = ctx.method if not (result and result.contents) then - -- return { 'No information available' } - return + -- return { 'No information available' } + return end local lines = vim.lsp.util.convert_input_to_markdown_lines(result.contents) - lines = vim.lsp.util.trim_empty_lines(lines) + lines = vim.split(table.concat(lines, "\n"), "\n", { trimempty = true }) if vim.tbl_isempty(lines) then - -- return { 'No information available' } - return + -- return { 'No information available' } + return end -- create buffer for popup local buf = vim.api.nvim_create_buf(false, false) if buf == 0 then - vim.api.nvim_err_writeln("details_popup: could not create details buffer") + vim.notify("details_popup: could not create details buffer", vim.log.levels.ERROR) return end - vim.api.nvim_buf_set_option(buf, 'bufhidden', 'delete') - vim.api.nvim_buf_set_option(buf, 'syntax', 'markdown') - vim.api.nvim_buf_set_option(buf, 'filetype', 'markdown') + vim.api.nvim_set_option_value("bufhidden", "delete", { buf = buf }) + vim.api.nvim_set_option_value("syntax", "markdown", { buf = buf }) + vim.api.nvim_set_option_value("filetype", "markdown", { buf = buf }) lines = vim.lsp.util.stylize_markdown(buf, lines, {}) @@ -53,22 +52,17 @@ function M.hover_handler(_, result, ctx, config) end end - vim.api.nvim_buf_set_option(buf, 'modifiable', true) + vim.api.nvim_set_option_value("modifiable", true, { buf = buf }) vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines) - vim.api.nvim_buf_set_option(buf, 'modifiable', false) - local popup_conf = vim.lsp.util.make_floating_popup_options( - width, - #lines, - { - border= "rounded", - focusable= false, - zindex = 99, - } - ) + vim.api.nvim_set_option_value("modifiable", false, { buf = buf }) + local popup_conf = vim.lsp.util.make_floating_popup_options(width, #lines, { + border = "rounded", + focusable = false, + zindex = 99, + }) float_win = vim.api.nvim_open_win(buf, false, popup_conf) - return float_win + return float_win end - return M diff --git a/lua/litee/lib/lsp/init.lua b/lua/litee/lib/lsp/init.lua index 4c29b12..c76f8d5 100644 --- a/lua/litee/lib/lsp/init.lua +++ b/lua/litee/lib/lsp/init.lua @@ -1,5 +1,5 @@ -local lib_notify = require('litee.lib.notify') -local lib_tree_node = require('litee.lib.tree.node') +local lib_notify = require("litee.lib.notify") +local lib_tree_node = require("litee.lib.tree.node") local M = {} @@ -41,11 +41,7 @@ function M.gather_symbols_async_handler(node, co) end for _, res in ipairs(result) do - if - res.location.uri == uri and - res.location.range.start.line == - start_line - then + if res.location.uri == uri and res.location.range.start.line == start_line then coroutine.resume(co, res) return end @@ -115,11 +111,7 @@ function M.symbol_from_node(clients, node, bufnr) goto continue end for _, res in ipairs(out.result) do - if - res.uri == node.uri and - res.location.range.start.line == - node.call_hierarchy_item.range.start.line - then + if res.uri == node.uri and res.location.range.start.line == node.call_hierarchy_item.range.start.line then return res end end @@ -144,17 +136,17 @@ function M.conv_symbolinfo_to_docsymbol(symbolinfo) -- these are mandatory fields per the LSP spec, -- return nil if they arent there. if - symbolinfo.name == nil or - symbolinfo.kind == nil or - symbolinfo.location == nil or - symbolinfo.location.range == nil + symbolinfo.name == nil + or symbolinfo.kind == nil + or symbolinfo.location == nil + or symbolinfo.location.range == nil then return nil end - document_symbol.name = symbolinfo.name - document_symbol.kind = symbolinfo.kind - document_symbol.range = symbolinfo.location.range + document_symbol.name = symbolinfo.name + document_symbol.kind = symbolinfo.kind + document_symbol.range = symbolinfo.location.range document_symbol.children = {} document_symbol.details = "" document_symbol.tags = {} diff --git a/lua/litee/lib/lsp/wrappers.lua b/lua/litee/lib/lsp/wrappers.lua index 3218352..abffaea 100644 --- a/lua/litee/lib/lsp/wrappers.lua +++ b/lua/litee/lib/lsp/wrappers.lua @@ -1,4 +1,4 @@ -local lib_notify = require('litee.lib.notify') +local lib_notify = require("litee.lib.notify") local M = {} function M.buf_document_symbol() diff --git a/lua/litee/lib/navi/init.lua b/lua/litee/lib/navi/init.lua index 4a4b8e4..6f693bb 100644 --- a/lua/litee/lib/navi/init.lua +++ b/lua/litee/lib/navi/init.lua @@ -10,8 +10,7 @@ local M = {} -- @param post_cb function() A callback which fires just after -- the cursor move. function M.next(component_state, pre_cb, post_cb) - if component_state.win == nil - or not vim.api.nvim_win_is_valid(component_state.win) then + if component_state.win == nil or not vim.api.nvim_win_is_valid(component_state.win) then return end local cur_cursor = vim.api.nvim_win_get_cursor(component_state.win) @@ -20,9 +19,13 @@ function M.next(component_state, pre_cb, post_cb) return end cur_cursor[1] = cur_cursor[1] + 1 - if pre_cb ~= nil then pre_cb() end + if pre_cb ~= nil then + pre_cb() + end vim.api.nvim_win_set_cursor(component_state.win, cur_cursor) - if post_cb ~= nil then pre_cb() end + if post_cb ~= nil then + pre_cb() + end end -- next moves the cursor in the window of the provided @@ -35,8 +38,7 @@ end -- @param post_cb function() A callback which fires just after -- the cursor move. function M.previous(component_state, pre_cb, post_cb) - if component_state.win == nil - or not vim.api.nvim_win_is_valid(component_state.win) then + if component_state.win == nil or not vim.api.nvim_win_is_valid(component_state.win) then return end local cur_cursor = vim.api.nvim_win_get_cursor(component_state.win) @@ -44,9 +46,13 @@ function M.previous(component_state, pre_cb, post_cb) return end cur_cursor[1] = cur_cursor[1] - 1 - if pre_cb ~= nil then pre_cb() end + if pre_cb ~= nil then + pre_cb() + end vim.api.nvim_win_set_cursor(component_state.win, cur_cursor) - if post_cb ~= nil then pre_cb() end + if post_cb ~= nil then + pre_cb() + end end return M diff --git a/lua/litee/lib/notify/init.lua b/lua/litee/lib/notify/init.lua index 514b235..9c062bd 100644 --- a/lua/litee/lib/notify/init.lua +++ b/lua/litee/lib/notify/init.lua @@ -1,4 +1,4 @@ -local notify_config = require('litee.lib.config').config["notify"] +local notify_config = require("litee.lib.config").config["notify"] local M = {} local float_wins = {} @@ -24,9 +24,7 @@ function M.notify_popup_with_timeout(text, ms, sev) end M.notify_popup(text, sev) local timer = vim.loop.new_timer() - timer:start(ms, 0, vim.schedule_wrap( - M.close_notify_popup - )) + timer:start(ms, 0, vim.schedule_wrap(M.close_notify_popup)) end function M.notify_popup(text, sev) @@ -40,22 +38,22 @@ function M.notify_popup(text, sev) local buf = vim.api.nvim_create_buf(false, true) if buf == 0 then - vim.api.nvim_err_writeln("details_popup: could not create details buffer") + vim.notify("details_popup: could not create details buffer", vim.log.levels.ERROR) return end - vim.api.nvim_buf_set_option(buf, 'bufhidden', 'delete') - vim.api.nvim_buf_set_option(buf, 'syntax', 'yaml') + vim.api.nvim_set_option_value("bufhidden", "delete", { buf = buf }) + vim.api.nvim_set_option_value("syntax", "yaml", { buf = buf }) - local lines = {text} + local lines = { text } local width = 20 local line_width = vim.fn.strdisplaywidth(text) if line_width > width then width = line_width end - vim.api.nvim_buf_set_option(buf, 'modifiable', true) + vim.api.nvim_set_option_value("modifiable", true, { buf = buf }) vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines) - vim.api.nvim_buf_set_option(buf, 'modifiable', false) + vim.api.nvim_set_option_value("modifiable", false, { buf = buf }) local popup_conf = { relative = "editor", anchor = "SE", @@ -71,11 +69,11 @@ function M.notify_popup(text, sev) local float_win = vim.api.nvim_open_win(buf, false, popup_conf) table.insert(float_wins, float_win) if sev == "error" then - vim.api.nvim_win_set_option(float_win, 'winhl', "Normal:Error") + vim.api.nvim_set_option_value("winhl", "Normal:Error", { win = float_win }) elseif sev == "warning" then - vim.api.nvim_win_set_option(float_win, 'winhl', "Normal:WarningMsg") + vim.api.nvim_set_option_value("winhl", "Normal:WarningMsg", { win = float_win }) else - vim.api.nvim_win_set_option(float_win, 'winhl', "Normal:NormalFloat") + vim.api.nvim_set_option_value("winhl", "Normal:NormalFloat", { win = float_win }) end end diff --git a/lua/litee/lib/panel/autocmds.lua b/lua/litee/lib/panel/autocmds.lua index d616ea6..c5d1138 100644 --- a/lua/litee/lib/panel/autocmds.lua +++ b/lua/litee/lib/panel/autocmds.lua @@ -1,5 +1,5 @@ -local lib_state = require('litee.lib.state') -local lib_panel = require('litee.lib.panel') +local lib_state = require("litee.lib.state") +local lib_panel = require("litee.lib.panel") local M = {} diff --git a/lua/litee/lib/panel/init.lua b/lua/litee/lib/panel/init.lua index def85b8..f73f8a8 100644 --- a/lua/litee/lib/panel/init.lua +++ b/lua/litee/lib/panel/init.lua @@ -1,8 +1,8 @@ -local lib_state = require('litee.lib.state') -local config = require('litee.lib.config').config -local lib_notify = require('litee.lib.notify') -local lib_util = require('litee.lib.util') -local lib_util_win = require('litee.lib.util.window') +local lib_state = require("litee.lib.state") +local config = require("litee.lib.config").config +local lib_notify = require("litee.lib.notify") +local lib_util = require("litee.lib.util") +local lib_util_win = require("litee.lib.util.window") local M = {} @@ -42,7 +42,7 @@ local components = {} function M.register_component(component, pre_window_create, post_window_create) components[component] = { pre = pre_window_create, - post = post_window_create + post = post_window_create, } end @@ -79,7 +79,11 @@ function M.toggle_panel(state, keep_open, cycle, close) local cur_tab = vim.api.nvim_get_current_tabpage() state = lib_state.get_state(cur_tab) if state == nil then - lib_notify.notify_popup_with_timeout("Must open a litee component before toggling the panel.", 1750, "error") + lib_notify.notify_popup_with_timeout( + "Must open a litee component before toggling the panel.", + 1750, + "error" + ) return end end @@ -98,11 +102,7 @@ function M.toggle_panel(state, keep_open, cycle, close) -- components are open, close them, recording its dimensions -- for proper restore. - if - not keep_open or - cycle or - close - then + if not keep_open or cycle or close then if component_open then for component, _ in pairs(components) do if @@ -112,7 +112,7 @@ function M.toggle_panel(state, keep_open, cycle, close) then state[component].win_dimensions = { height = vim.api.nvim_win_get_height(state[component].win), - width = vim.api.nvim_win_get_width(state[component].win) + width = vim.api.nvim_win_get_width(state[component].win), } vim.api.nvim_win_close(state[component].win, true) end @@ -124,21 +124,26 @@ function M.toggle_panel(state, keep_open, cycle, close) end end + local last_component_win = nil for component, callbacks in pairs(components) do if state[component] ~= nil then if callbacks.pre(state) then M._open_window(component, state) -- restore cursor positions if possible. if component_cursors[component] ~= nil then - lib_util.safe_cursor_reset( - state[component].win, - component_cursors[component] - ) + lib_util.safe_cursor_reset(state[component].win, component_cursors[component]) end + -- remember the last created component window + last_component_win = state[component].win end end end - vim.api.nvim_set_current_win(cur_win) + -- set focus to the last created component window if it exists, otherwise return to original window + if last_component_win ~= nil and vim.api.nvim_win_is_valid(last_component_win) then + vim.api.nvim_set_current_win(last_component_win) + else + vim.api.nvim_set_current_win(cur_win) + end end -- Similar to toggle_panel but retrieves state from @@ -168,15 +173,13 @@ end -- the declarative evaluation of the panel layout. This occurs if the desired -- component is already being displayed. local function realize_current_and_desired(check_component, desired_component, current_layout, desired_layout, state) - local current_tabpage = vim.api.nvim_win_get_tabpage( - vim.api.nvim_get_current_win() - ) + local current_tabpage = vim.api.nvim_win_get_tabpage(vim.api.nvim_get_current_win()) -- check if the desired window exists. if - state[check_component] == nil or - state[check_component].win == nil or - (not vim.api.nvim_win_is_valid(state[check_component].win)) + state[check_component] == nil + or state[check_component].win == nil + or (not vim.api.nvim_win_is_valid(state[check_component].win)) then if check_component == desired_component then -- checked window is invalid, its also the desired window to open @@ -223,7 +226,9 @@ function M._open_window(desired_component, state) local desired_layout = {} for check_component, _ in pairs(components) do - if not realize_current_and_desired(check_component, desired_component, current_layout, desired_layout, state) then + if + not realize_current_and_desired(check_component, desired_component, current_layout, desired_layout, state) + then return end end @@ -248,14 +253,11 @@ function M.open_to(component, state) return false end local current_win = vim.api.nvim_get_current_win() - if current_win == state[component].win then + if current_win == state[component].win then vim.api.nvim_set_current_win(state[component].invoking_win) return end - if - state[component].win ~= nil - and vim.api.nvim_win_is_valid(state[component].win) - then + if state[component].win ~= nil and vim.api.nvim_win_is_valid(state[component].win) then vim.api.nvim_set_current_win(state[component].win) return end @@ -306,11 +308,7 @@ end -- @param after_focus Same as "before_focus" but runs inside -- the newly created popout floating win. function M.popout_to(component, state, before_focus, after_focus) - if - state == nil - or state[component] == nil - or components[component] == nil - then + if state == nil or state[component] == nil or components[component] == nil then return end @@ -327,16 +325,17 @@ function M.popout_to(component, state, before_focus, after_focus) local popup_conf = { relative = "editor", anchor = "NW", - width = math.floor(vim.opt.columns:get()/2), - height = math.floor(vim.opt.lines:get()/2), + width = math.floor(vim.opt.columns:get() / 2), + height = math.floor(vim.opt.lines:get() / 2), focusable = true, zindex = 98, border = "rounded", - row = math.floor(vim.opt.lines:get() - (vim.opt.cmdheight:get() + 1)/2), - col = math.floor(vim.opt.columns:get()/2), + row = math.floor(vim.opt.lines:get() - (vim.opt.cmdheight:get() + 1) / 2), + col = math.floor(vim.opt.columns:get() / 2), } - if M.popout_panel_state.panel_open + if + M.popout_panel_state.panel_open and state[component].win ~= nil and vim.api.nvim_win_is_valid(state[component].win) then @@ -407,20 +406,16 @@ function M._setup_window(current_layout, desired_layout, state) -- there is no current layout, so just do a botright or equivalent if config["panel"].orientation == "left" then vim.cmd("topleft vsplit") - vim.cmd("vertical resize " .. - config["panel"].panel_size) + vim.cmd("vertical resize " .. config["panel"].panel_size) elseif config["panel"].orientation == "right" then vim.cmd("botright vsplit") - vim.cmd("vertical resize " .. - config["panel"].panel_size) + vim.cmd("vertical resize " .. config["panel"].panel_size) elseif config["panel"].orientation == "top" then vim.cmd("topleft split") - vim.cmd("resize " .. - config["panel"].panel_size) + vim.cmd("resize " .. config["panel"].panel_size) elseif config["panel"].orientation == "bottom" then vim.cmd("botright split") - vim.cmd("resize " .. - config["panel"].panel_size) + vim.cmd("resize " .. config["panel"].panel_size) end goto set end @@ -441,12 +436,8 @@ function M._setup_window(current_layout, desired_layout, state) state[component].win = cur_win vim.api.nvim_win_set_buf(state[component].win, buffer_to_set) M._set_win_opts(state[component].win) - if - dimensions_to_set ~= nil and - dimensions_to_set.width ~= nil and - dimensions_to_set.height ~= nil - then - if (config["panel"].orientation == "left" or config["panel"].orientation == "right") then + if dimensions_to_set ~= nil and dimensions_to_set.width ~= nil and dimensions_to_set.height ~= nil then + if config["panel"].orientation == "left" or config["panel"].orientation == "right" then vim.api.nvim_win_set_width(cur_win, dimensions_to_set.width) else vim.api.nvim_win_set_height(cur_win, dimensions_to_set.height) @@ -454,7 +445,7 @@ function M._setup_window(current_layout, desired_layout, state) else dimensions_to_set = {} dimensions_to_set.height = vim.api.nvim_win_get_height(cur_win) - dimensions_to_set.wdith = vim.api.nvim_win_get_width(cur_win) + dimensions_to_set.wdith = vim.api.nvim_win_get_width(cur_win) state[component].dimensions = dimensions_to_set end @@ -469,14 +460,14 @@ end -- panel window. -- @param win (int) Window ID of panel window function M._set_win_opts(win) - vim.api.nvim_win_set_option(win, 'number', false) - vim.api.nvim_win_set_option(win, 'cursorline', true) - vim.api.nvim_win_set_option(win, 'relativenumber', false) - vim.api.nvim_win_set_option(win, 'signcolumn', 'no') - vim.api.nvim_win_set_option(win, 'wrap', false) - vim.api.nvim_win_set_option(win, 'winfixwidth', true) - vim.api.nvim_win_set_option(win, 'winfixheight', true) - vim.api.nvim_win_set_option(win, 'winhighlight', 'Normal:NormalSB') + vim.api.nvim_win_set_option(win, "number", false) + vim.api.nvim_win_set_option(win, "cursorline", true) + vim.api.nvim_win_set_option(win, "relativenumber", false) + vim.api.nvim_win_set_option(win, "signcolumn", "no") + vim.api.nvim_win_set_option(win, "wrap", false) + vim.api.nvim_win_set_option(win, "winfixwidth", true) + vim.api.nvim_win_set_option(win, "winfixheight", true) + vim.api.nvim_win_set_option(win, "winhighlight", "Normal:NormalSB") end return M diff --git a/lua/litee/lib/state/autocmds.lua b/lua/litee/lib/state/autocmds.lua index 7d8d7b8..7ec526f 100644 --- a/lua/litee/lib/state/autocmds.lua +++ b/lua/litee/lib/state/autocmds.lua @@ -1,5 +1,5 @@ -local lib_tree = require('litee.lib.tree') -local lib_state = require('litee.lib.state') +local lib_tree = require("litee.lib.tree") +local lib_state = require("litee.lib.state") local M = {} diff --git a/lua/litee/lib/state/init.lua b/lua/litee/lib/state/init.lua index 8f8905e..da1e78c 100644 --- a/lua/litee/lib/state/init.lua +++ b/lua/litee/lib/state/init.lua @@ -35,8 +35,8 @@ end -- get_state_ctx is similiar to get_state but obtains -- the tab ID from the current Neovim context. function M.get_state_ctx() - local win = vim.api.nvim_get_current_win() - local tab = vim.api.nvim_win_get_tabpage(win) + local win = vim.api.nvim_get_current_win() + local tab = vim.api.nvim_win_get_tabpage(win) local state = M.registry[tab] return state end @@ -49,7 +49,9 @@ end -- storing its state. function M.get_component_state(tab, component) local s = M.registry[tab] - if s == nil then return nil end + if s == nil then + return nil + end return s[component] end @@ -69,7 +71,6 @@ function M.put_state(tab, state) return M.registry[tab] end - -- put_component_state will store the component state for -- later retrieval. -- diff --git a/lua/litee/lib/term/init.lua b/lua/litee/lib/term/init.lua index b563476..e211995 100644 --- a/lua/litee/lib/term/init.lua +++ b/lua/litee/lib/term/init.lua @@ -1,25 +1,25 @@ -local lib_panel = require('litee.lib.panel') -local lib_state = require('litee.lib.state') -local lib_util_buf = require('litee.lib.util.buffer') -local config = require('litee.lib.config').config["term"] +local lib_panel = require("litee.lib.panel") +local lib_state = require("litee.lib.state") +local lib_util_buf = require("litee.lib.util.buffer") +local config = require("litee.lib.config").config["term"] local M = {} -local opts = {noremap = true, silent=true} +local opts = { noremap = true, silent = true } local function terminal_buf_setup(buf) - vim.api.nvim_buf_set_keymap(buf, 't', "v", "lua require('configs.terminal').terminal_vsplit()", opts) - vim.api.nvim_buf_set_keymap(buf, 't', "n", "", opts) - vim.api.nvim_buf_set_keymap(buf, 't', "h", "h", opts) - vim.api.nvim_buf_set_keymap(buf, 't', "j", "j", opts) - vim.api.nvim_buf_set_keymap(buf, 't', "k", "k", opts) - vim.api.nvim_buf_set_keymap(buf, 't', "l", "l", opts) - vim.api.nvim_buf_set_option(buf, 'bufhidden', 'hide') - if config.map_resize_keys then - lib_util_buf.map_resize_keys(config.position, buf, opts) + vim.api.nvim_buf_set_keymap(buf, "t", "v", "lua require('configs.terminal').terminal_vsplit()", opts) + vim.api.nvim_buf_set_keymap(buf, "t", "n", "", opts) + vim.api.nvim_buf_set_keymap(buf, "t", "h", "h", opts) + vim.api.nvim_buf_set_keymap(buf, "t", "j", "j", opts) + vim.api.nvim_buf_set_keymap(buf, "t", "k", "k", opts) + vim.api.nvim_buf_set_keymap(buf, "t", "l", "l", opts) + vim.api.nvim_set_option_value("bufhidden", "hide", { buf = buf }) + if config.map_resize_keys then + lib_util_buf.map_resize_keys(config.position, buf, opts) end end local function terminal_win_setup(win) - vim.api.nvim_win_set_option(win, 'winfixheight', true) + vim.api.nvim_set_option_value("winfixheight", true, { win = win }) end -- terminal opens a native Neovim terminal instance that @@ -39,7 +39,7 @@ end -- the $SHELL environment variable must be set correctly -- to open the appropriate shell. function M.terminal() - local shell = vim.fn.getenv('SHELL') + local shell = vim.fn.getenv("SHELL") if shell == nil or shell == "" then return end @@ -52,9 +52,9 @@ function M.terminal() terminal_buf_setup(buf) if config.position == "top" then - vim.cmd('topleft split') + vim.cmd("topleft split") else - vim.cmd('botright split') + vim.cmd("botright split") end vim.cmd("resize " .. config.term_size) terminal_win_setup(vim.api.nvim_get_current_win()) @@ -72,7 +72,7 @@ function M.terminal() end function M.terminal_vsplit() - local shell = vim.fn.getenv('SHELL') + local shell = vim.fn.getenv("SHELL") if shell == nil or shell == "" then return end @@ -81,7 +81,7 @@ function M.terminal_vsplit() vim.api.nvim_err_writeln("failed to create terminal buffer") return end - vim.cmd('vsplit') + vim.cmd("vsplit") local cur_win = vim.api.nvim_get_current_win() terminal_win_setup(cur_win) vim.api.nvim_win_set_buf(cur_win, buf) @@ -94,47 +94,43 @@ function M.list_terminals() for _, b in ipairs(vim.api.nvim_list_bufs()) do local buf_name = vim.api.nvim_buf_get_name(b) if vim.fn.match(buf_name, "term://") == 0 then - table.insert(terms, {name = buf_name, buf = b}) + table.insert(terms, { name = buf_name, buf = b }) end end if #terms == 0 then return end - vim.ui.select( - terms, - { - prompt = "select a terminal to display", - format_item = function(item) - return item["name"] .. " " .. item["buf"] - end - }, - function (choice) - -- first see if there's a window that's opened with this term - for _, w in ipairs(vim.api.nvim_list_wins()) do - if vim.api.nvim_win_get_buf(w) == choice["buf"] then - vim.api.nvim_set_current_win(w) - return - end + vim.ui.select(terms, { + prompt = "select a terminal to display", + format_item = function(item) + return item["name"] .. " " .. item["buf"] + end, + }, function(choice) + -- first see if there's a window that's opened with this term + for _, w in ipairs(vim.api.nvim_list_wins()) do + if vim.api.nvim_win_get_buf(w) == choice["buf"] then + vim.api.nvim_set_current_win(w) + return end + end - if config.position == "top" then - vim.cmd('topleft split') - else - vim.cmd('botright split') - end - vim.cmd("resize " .. config.term_size) - local cur_win = vim.api.nvim_get_current_win() - local cur_tab = vim.api.nvim_get_current_tabpage() - local state = lib_state.get_state(cur_tab) - vim.api.nvim_win_set_buf(cur_win, choice["buf"]) - if state ~= nil then - if lib_panel.is_panel_open(state) then - lib_panel.toggle_panel_ctx(true, true) - end + if config.position == "top" then + vim.cmd("topleft split") + else + vim.cmd("botright split") + end + vim.cmd("resize " .. config.term_size) + local cur_win = vim.api.nvim_get_current_win() + local cur_tab = vim.api.nvim_get_current_tabpage() + local state = lib_state.get_state(cur_tab) + vim.api.nvim_win_set_buf(cur_win, choice["buf"]) + if state ~= nil then + if lib_panel.is_panel_open(state) then + lib_panel.toggle_panel_ctx(true, true) end - vim.api.nvim_set_current_win(cur_win) end - ) + vim.api.nvim_set_current_win(cur_win) + end) end return M diff --git a/lua/litee/lib/tree/init.lua b/lua/litee/lib/tree/init.lua index 2f2df9c..c4051a0 100644 --- a/lua/litee/lib/tree/init.lua +++ b/lua/litee/lib/tree/init.lua @@ -1,4 +1,4 @@ -local lib_marshal = require('litee.lib.tree.marshal') +local lib_marshal = require("litee.lib.tree.marshal") local M = {} @@ -27,8 +27,8 @@ local registry = {} -- @returns tree_handle (int) A handle representing -- the created tree. function M.new_tree(kind) - local handle = #registry+1 - registry[handle] = {root = {}, depth_table = {}, kind = kind} + local handle = #registry + 1 + registry[handle] = { root = {}, depth_table = {}, kind = kind } return handle end @@ -183,7 +183,7 @@ function M.add_node(handle, parent, children, external) pNode.children = {} local child_depth = parent.depth + 1 - for _, child in ipairs(children) do + for _, child in ipairs(children) do child.depth = child_depth table.insert(pNode.children, child) end @@ -259,9 +259,9 @@ function M.reparent_node(handle, depth, node) end -- recurse to leafs for _, child in ipairs(node.children) do - M.reparent_node(handle, depth+1, child) + M.reparent_node(handle, depth + 1, child) -- recursion done, update your depth - child.depth = depth+1 + child.depth = depth + 1 end if depth == 0 then -- we are the root node, refresh depth_table with @@ -295,9 +295,9 @@ end -- @param tree (int) The tree handle to marshal into the provided buffer -- @param marshal_func (function(node)) A function -- when given a node returns the following strings - -- name: the display name for the node - -- detail: details to display about the node - -- icon: any icon associated with the node +-- name: the display name for the node +-- detail: details to display about the node +-- icon: any icon associated with the node function M.write_tree(buf, tree, marshal_func, no_guide_leaf) local root = registry[tree].root if root == nil then diff --git a/lua/litee/lib/tree/marshal/init.lua b/lua/litee/lib/tree/marshal/init.lua index 3a77d3a..7ea6aab 100644 --- a/lua/litee/lib/tree/marshal/init.lua +++ b/lua/litee/lib/tree/marshal/init.lua @@ -1,7 +1,7 @@ -local lib_util = require('litee.lib.util') -local lib_hi = require('litee.lib.highlights') -local lib_tree_config = require('litee.lib.config').config["tree"] -local icon_set = require('litee.lib').icon_set +local lib_util = require("litee.lib.util") +local lib_hi = require("litee.lib.highlights") +local lib_tree_config = require("litee.lib.config").config["tree"] +local icon_set = require("litee.lib").icon_set local M = {} @@ -65,10 +65,7 @@ function M.marshal_node(node, marshal_func, no_guide_leaf) else expand_guide = icon_set["Collapsed"] end - if no_guide_leaf - and #node.children == 0 - and node.expanded == true - then + if no_guide_leaf and #node.children == 0 and node.expanded == true then expand_guide = icon_set["Space"] end @@ -81,7 +78,7 @@ function M.marshal_node(node, marshal_func, no_guide_leaf) end if lib_tree_config.indent_guides then - for i=1, node.depth do + for i = 1, node.depth do if i == 1 then str = str .. icon_set["Space"] else @@ -89,7 +86,7 @@ function M.marshal_node(node, marshal_func, no_guide_leaf) end end else - for _=1, node.depth do + for _ = 1, node.depth do str = str .. icon_set["Space"] end end @@ -100,9 +97,39 @@ function M.marshal_node(node, marshal_func, no_guide_leaf) -- ▶ Func1 str = str .. expand_guide .. icon_set["Space"] - str = str .. icon .. icon_set["Space"] .. icon_set["Space"] .. name - -- return detail as virtual text chunk. - return str, {{detail, lib_hi.hls.SymbolDetailHL}} + str = str .. icon + + local colors = { + lib_hi.hls.SymbolNameColor0, + lib_hi.hls.SymbolNameColor1, + lib_hi.hls.SymbolNameColor2, + lib_hi.hls.SymbolNameColor3, + lib_hi.hls.SymbolNameColor4, + lib_hi.hls.SymbolNameColor5, + } + local color_idx = (node.depth - 1) % #colors + 1 + local name_hl = colors[color_idx] + + local virt_text = {} + if name ~= "" then + table.insert(virt_text, { name .. " ", name_hl }) + end + if detail ~= "" then + local formatted_detail = detail + local parts = vim.split(vim.trim(detail), "%s+") + if #parts >= 2 then + local path = parts[1] + local line = parts[2] + local filename = vim.fn.fnamemodify(path, ":t") + formatted_detail = "[" .. filename .. ":" .. line .. "]" + end + table.insert(virt_text, { formatted_detail, "Comment" }) + end + if #virt_text == 0 then + virt_text = { { "", "" } } + end + + return str, virt_text end -- marshal_line takes a UI buffer line and @@ -139,9 +166,9 @@ end -- virtual text lines. Start this function with an empty table. -- @param marshal_func (function(node)) A function -- when given a node returns the following strings - -- name: the display name for the node - -- detail: details to display about the node - -- icon: any icon associated with the node +-- name: the display name for the node +-- detail: details to display about the node +-- icon: any icon associated with the node function M._marshal_tree(buf, lines, node, tree, virtual_text_lines, marshal_func, no_guide_leaf) if node.depth == 0 then virtual_text_lines = {} @@ -159,15 +186,15 @@ function M._marshal_tree(buf, lines, node, tree, virtual_text_lines, marshal_fun -- exists in the source code file. if node.location ~= nil and not vim.tbl_isempty(node.location) then local start_line = node.location["range"]["start"].line - M.source_line_map[tree][start_line+1] = { + M.source_line_map[tree][start_line + 1] = { uri = lib_util.absolute_path_from_uri(node.location.uri), - line = #lines + line = #lines, } end -- if we are an expanded node or we are the root (always expand) -- recurse - if node.expanded or node.depth == 0 then + if node.expanded or node.depth == 0 then for _, child in ipairs(node.children) do M._marshal_tree(buf, lines, child, tree, virtual_text_lines, marshal_func, no_guide_leaf) end @@ -176,20 +203,20 @@ function M._marshal_tree(buf, lines, node, tree, virtual_text_lines, marshal_fun -- we are back at the root, all lines are inserted, lets write it out -- to the buffer if node.depth == 0 then - vim.api.nvim_buf_set_option(buf, 'modifiable', true) + vim.api.nvim_set_option_value("modifiable", true, { buf = buf }) vim.api.nvim_buf_set_lines(buf, 0, -1, true, {}) vim.api.nvim_buf_set_lines(buf, 0, #lines, false, lines) - vim.api.nvim_buf_set_option(buf, 'modifiable', false) + vim.api.nvim_set_option_value("modifiable", false, { buf = buf }) for i, vt in ipairs(virtual_text_lines) do if vt[1][1] == "" then goto continue end local opts = { virt_text = vt, - virt_text_pos = 'eol', - hl_mode = 'combine' + virt_text_pos = "eol", + hl_mode = "combine", } - vim.api.nvim_buf_set_extmark(buf, 1, i-1, 0, opts) + vim.api.nvim_buf_set_extmark(buf, 1, i - 1, 0, opts) ::continue:: end end diff --git a/lua/litee/lib/tree/node.lua b/lua/litee/lib/tree/node.lua index 00e4b77..4870a4a 100644 --- a/lua/litee/lib/tree/node.lua +++ b/lua/litee/lib/tree/node.lua @@ -47,7 +47,7 @@ function M.new_node(name, key, depth) -- whether this node is expanded in its containing -- tree. expanded = false, - offset_encoding = "utf-8" + offset_encoding = "utf-8", } end diff --git a/lua/litee/lib/util/buffer.lua b/lua/litee/lib/util/buffer.lua index 2710a3b..a1563f6 100644 --- a/lua/litee/lib/util/buffer.lua +++ b/lua/litee/lib/util/buffer.lua @@ -1,6 +1,5 @@ local M = {} - local original_guicursor = "" -- hide_cursor will dynamically create the LTCursorHide hi and -- set the guicursor option to this hi group. @@ -16,20 +15,45 @@ local original_guicursor = "" function M.hide_cursor(hide) if original_guicursor == "" then for _, section in ipairs(vim.opt.guicursor:get()) do - original_guicursor = original_guicursor .. section .. ',' + original_guicursor = original_guicursor .. section .. "," end end if not hide then - vim.cmd('set guicursor=' .. original_guicursor) + vim.cmd("set guicursor=" .. original_guicursor) return end local colors_rgb = vim.api.nvim_get_hl_by_name("CursorLine", true) local colors_256 = vim.api.nvim_get_hl_by_name("CursorLine", false) - local hi = string.format("hi LTCursorHide cterm=None ctermbg=%s ctermfg=%s gui=None guibg=%s guifg=%s", - (function() if colors_256.background ~= nil then return colors_256.background else return "None" end end)(), - (function() if colors_256.foreground ~= nil then return colors_256.foreground else return "None" end end)(), - (function() if colors_rgb.background ~= nil then return string.format("#%x", colors_rgb.background) else return "None" end end)(), - (function() if colors_rgb.foreground ~= nil then return string.format("#%x", colors_rgb.foreground) else return "None" end end)() + local hi = string.format( + "hi LTCursorHide cterm=None ctermbg=%s ctermfg=%s gui=None guibg=%s guifg=%s", + (function() + if colors_256.background ~= nil then + return colors_256.background + else + return "None" + end + end)(), + (function() + if colors_256.foreground ~= nil then + return colors_256.foreground + else + return "None" + end + end)(), + (function() + if colors_rgb.background ~= nil then + return string.format("#%x", colors_rgb.background) + else + return "None" + end + end)(), + (function() + if colors_rgb.foreground ~= nil then + return string.format("#%x", colors_rgb.foreground) + else + return "None" + end + end)() ) vim.cmd(hi) local cursorgui = "set guicursor=n:LTCursorHide" @@ -76,8 +100,8 @@ end -- a convenience method which will close any popups -- generated by the litee library (not notifications). function M.close_all_popups() - require('litee.lib.lsp.hover').close_hover_popup() - require('litee.lib.details').close_details_popup() + require("litee.lib.lsp.hover").close_hover_popup() + require("litee.lib.details").close_details_popup() end return M diff --git a/lua/litee/lib/util/init.lua b/lua/litee/lib/util/init.lua index 50d2bb1..9bf4c63 100644 --- a/lua/litee/lib/util/init.lua +++ b/lua/litee/lib/util/init.lua @@ -11,11 +11,7 @@ end -- safely be placed at the lowest available -- buffer line. function M.safe_cursor_reset(win, linenr) - if - win == nil - or not vim.api.nvim_win_is_valid(win) - or linenr == nil - then + if win == nil or not vim.api.nvim_win_is_valid(win) or linenr == nil then return end local lc = vim.api.nvim_buf_line_count(vim.api.nvim_win_get_buf(win)) @@ -44,20 +40,20 @@ function M.resolve_location(node) elseif node.call_hierarchy_item ~= nil then location = { uri = node.call_hierarchy_item.uri, - range = node.call_hierarchy_item.range + range = node.call_hierarchy_item.range, } elseif node.document_symbol ~= nil then location = { uri = node.uri, - range = node.document_symbol.selectionRange + range = node.document_symbol.selectionRange, } elseif node.filetree_item ~= nil then local range = {} - range["start"] = { line = 0, character = 0} - range["end"] = { line = 0, character = 0} + range["start"] = { line = 0, character = 0 } + range["end"] = { line = 0, character = 0 } location = { uri = "file://" .. node.filetree_item.uri, - range = range + range = range, } end return location @@ -82,27 +78,27 @@ function M.resolve_hover_params(node) local params = {} if node.symbol ~= nil then params.textDocument = { - uri = node.symbol.location.uri + uri = node.symbol.location.uri, } params.position = { line = node.symbol.location.range.start.line, - character = node.symbol.location.range.start.character + character = node.symbol.location.range.start.character, } elseif node.call_hierarchy_item ~= nil then params.textDocument = { - uri = node.call_hierarchy_item.uri + uri = node.call_hierarchy_item.uri, } params.position = { line = node.call_hierarchy_item.range.start.line, - character = node.call_hierarchy_item.range.start.character + character = node.call_hierarchy_item.range.start.character, } elseif node.document_symbol ~= nil then params.textDocument = { - uri = node.uri + uri = node.uri, } params.position = { line = node.document_symbol.selectionRange.start.line, - character = node.document_symbol.selectionRange.start.character + character = node.document_symbol.selectionRange.start.character, } else return nil diff --git a/lua/litee/lib/util/path.lua b/lua/litee/lib/util/path.lua index a6e99d1..b402d68 100644 --- a/lua/litee/lib/util/path.lua +++ b/lua/litee/lib/util/path.lua @@ -10,18 +10,18 @@ local M = {} -- -- @param str (string) The string to encode. function M.safe_encode(str) - str, _ = string.gsub(str, '/', '%%2F') - str, _ = string.gsub(str, ' ', '%%20') - str, _ = string.gsub(str, ':', '%%3A') + str, _ = string.gsub(str, "/", "%%2F") + str, _ = string.gsub(str, " ", "%%20") + str, _ = string.gsub(str, ":", "%%3A") return str end -- decodes a string encoded by safe_encode. -- see safe_encode for details. function M.safe_decode(str) - str, _ = string.gsub(str, '%%2F', '/') - str, _ = string.gsub(str, '%%20', ' ') - str, _ = string.gsub(str, '%%3A', ':') + str, _ = string.gsub(str, "%%2F", "/") + str, _ = string.gsub(str, "%%20", " ") + str, _ = string.gsub(str, "%%3A", ":") return str end @@ -39,43 +39,31 @@ function M.file_exists(path) return true end -function M.relative_path_from_uri(uri) - local cwd = vim.fn.getcwd() - local uri_path = vim.fn.substitute(uri, "file://", "", "") - local idx = vim.fn.stridx(uri_path, cwd) - if idx == -1 then - -- we can't resolve a relative path, just give the - -- full path to the file. - return uri_path, false - end - return vim.fn.substitute(uri_path, cwd .. "/", "", ""), true -end - -- provides the filename with no path details for -- the provided uri. function M.basename(uri) local final_sep = vim.fn.strridx(uri, "/") - local uri_len = vim.fn.strlen(uri) + local uri_len = vim.fn.strlen(uri) -- if its a dir, remove final "/" - if final_sep+1 == uri_len then - uri = vim.fn.strpart(uri, 0, uri_len-1) + if final_sep + 1 == uri_len then + uri = vim.fn.strpart(uri, 0, uri_len - 1) final_sep = vim.fn.strridx(uri, "/") end - local dir = vim.fn.strpart(uri, final_sep+1, vim.fn.strlen(uri)) + local dir = vim.fn.strpart(uri, final_sep + 1, vim.fn.strlen(uri)) return dir end function M.parent_dir(path) - local base = M.basename(path) - local diff = vim.fn.strlen(path) - (vim.fn.strlen(base)+1) - local res = vim.fn.strpart(path, 0, diff) - if vim.fn.strridx(path, "/") == #path-1 then - return res - else - return res .. "/" - end + local base = M.basename(path) + local diff = vim.fn.strlen(path) - (vim.fn.strlen(base) + 1) + local res = vim.fn.strpart(path, 0, diff) + if vim.fn.strridx(path, "/") == #path - 1 then + return res + else + return res .. "/" + end end function M.path_prefix_match(prefix, path) @@ -101,8 +89,8 @@ function M.add_file_prefix(path) end function M.strip_trailing_slash(path) - if vim.fn.strridx(path, "/") == (vim.fn.strlen(path)-1) then - return vim.fn.strpart(path, 0, vim.fn.strlen(path)-1) + if vim.fn.strridx(path, "/") == (vim.fn.strlen(path) - 1) then + return vim.fn.strpart(path, 0, vim.fn.strlen(path) - 1) end return path end @@ -111,8 +99,8 @@ end -- relative path, and ensure leading '/' function M.strip_path_prefix(prefix, path) local new = vim.fn.substitute(path, prefix, "", "") - if vim.fn.strridx(new, '/') == -1 then - new = '/' .. new + if vim.fn.strridx(new, "/") == -1 then + new = "/" .. new end return new end diff --git a/lua/litee/lib/util/window.lua b/lua/litee/lib/util/window.lua index dbf1d39..b098b74 100644 --- a/lua/litee/lib/util/window.lua +++ b/lua/litee/lib/util/window.lua @@ -1,7 +1,7 @@ -local lib_state = require('litee.lib.state') -local lib_tree_config = require('litee.lib.config').config["tree"] -local lib_icons = require('litee.lib.icons') -local lib_hi = require('litee.lib.highlights') +local lib_state = require("litee.lib.state") +local lib_tree_config = require("litee.lib.config").config["tree"] +local lib_icons = require("litee.lib.icons") +local lib_hi = require("litee.lib.highlights") local M = {} diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..a10ab56 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,2 @@ +indent_type = "Spaces" +indent_width = 4