From 5ede0c906ab174678e39237fe55f24bc5ae99348 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Sun, 29 Aug 2021 14:25:27 -0400 Subject: feat: darker doc highlights --- lua/lsp/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 9c948803..1e1ff22e 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -19,9 +19,9 @@ local function lsp_highlight_document(client) if client.resolved_capabilities.document_highlight then vim.api.nvim_exec( [[ - hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646 - hi LspReferenceText cterm=bold ctermbg=red guibg=#464646 - hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646 + hi LspReferenceRead cterm=bold ctermbg=red guibg=#353d46 + hi LspReferenceText cterm=bold ctermbg=red guibg=#353d46 + hi LspReferenceWrite cterm=bold ctermbg=red guibg=#353d46 augroup lsp_document_highlight autocmd! * autocmd CursorHold lua vim.lsp.buf.document_highlight() -- cgit v1.2.3 From 0f458a04688d71d194fc104351f8cda5aff936af Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Mon, 30 Aug 2021 00:59:23 -0400 Subject: onedarker colorscheme --- lua/config/defaults.lua | 2 +- lua/lualine/themes/onedarker.lua | 35 +++++++++++++ lua/onedarker/Git.lua | 10 ++++ lua/onedarker/LSP.lua | 104 +++++++++++++++++++++++++++++++++++++++ lua/onedarker/Treesitter.lua | 66 +++++++++++++++++++++++++ lua/onedarker/Whichkey.lua | 9 ++++ lua/onedarker/config.lua | 23 +++++++++ lua/onedarker/highlights.lua | 99 +++++++++++++++++++++++++++++++++++++ lua/onedarker/init.lua | 30 +++++++++++ lua/onedarker/markdown.lua | 27 ++++++++++ lua/onedarker/palette.lua | 39 +++++++++++++++ lua/onedarker/util.lua | 25 ++++++++++ lua/spacegray/Git.lua | 10 ---- lua/spacegray/LSP.lua | 99 ------------------------------------- lua/spacegray/Treesitter.lua | 56 --------------------- lua/spacegray/Whichkey.lua | 9 ---- lua/spacegray/config.lua | 23 --------- lua/spacegray/highlights.lua | 99 ------------------------------------- lua/spacegray/init.lua | 43 ---------------- lua/spacegray/markdown.lua | 27 ---------- lua/spacegray/palette.lua | 40 --------------- lua/spacegray/util.lua | 25 ---------- 22 files changed, 468 insertions(+), 432 deletions(-) create mode 100644 lua/lualine/themes/onedarker.lua create mode 100644 lua/onedarker/Git.lua create mode 100644 lua/onedarker/LSP.lua create mode 100644 lua/onedarker/Treesitter.lua create mode 100644 lua/onedarker/Whichkey.lua create mode 100644 lua/onedarker/config.lua create mode 100644 lua/onedarker/highlights.lua create mode 100644 lua/onedarker/init.lua create mode 100644 lua/onedarker/markdown.lua create mode 100644 lua/onedarker/palette.lua create mode 100644 lua/onedarker/util.lua delete mode 100644 lua/spacegray/Git.lua delete mode 100644 lua/spacegray/LSP.lua delete mode 100644 lua/spacegray/Treesitter.lua delete mode 100644 lua/spacegray/Whichkey.lua delete mode 100644 lua/spacegray/config.lua delete mode 100644 lua/spacegray/highlights.lua delete mode 100644 lua/spacegray/init.lua delete mode 100644 lua/spacegray/markdown.lua delete mode 100644 lua/spacegray/palette.lua delete mode 100644 lua/spacegray/util.lua (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 9bd1bdd8..4f538dbb 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -8,7 +8,7 @@ vim.cmd [[ set spellfile=~/.config/lvim/spell/en.utf-8.add ]] lvim = { leader = "space", - colorscheme = "spacegray", + colorscheme = "onedarker", line_wrap_cursor_movement = true, transparent_window = false, format_on_save = true, diff --git a/lua/lualine/themes/onedarker.lua b/lua/lualine/themes/onedarker.lua new file mode 100644 index 00000000..396657bb --- /dev/null +++ b/lua/lualine/themes/onedarker.lua @@ -0,0 +1,35 @@ +-- Copyright (c) 2020-2021 shadmansaleh +-- MIT license, see LICENSE for more details. +-- Credit: Zoltan Dalmadi(lightline) +-- LuaFormatter off +local colors = { + blue = "#61afef", + green = "#98c379", + purple = "#c678dd", + red1 = "#e06c75", + red2 = "#be5046", + yellow = "#e5c07b", + orange = "#D19A66", + fg = "#abb2bf", + bg = "#282c34", + gray1 = "#5c6370", + gray2 = "#2c323d", + gray3 = "#3e4452", +} +-- LuaFormatter on +return { + normal = { + a = { fg = colors.fg, bg = colors.blue, gui = "bold" }, + b = { fg = colors.fg, bg = colors.bg }, + c = { fg = colors.fg, bg = colors.bg }, + }, + insert = { a = { fg = colors.fg, bg = colors.green, gui = "bold" } }, + visual = { a = { fg = colors.fg, bg = colors.purple, gui = "bold" } }, + command = { a = { fg = colors.fg, bg = colors.yellow, gui = "bold" } }, + replace = { a = { fg = colors.fg, bg = colors.red1, gui = "bold" } }, + inactive = { + a = { fg = colors.gray1, bg = colors.bg, gui = "bold" }, + b = { fg = colors.gray1, bg = colors.bg }, + c = { fg = colors.gray1, bg = colors.bg }, + }, +} diff --git a/lua/onedarker/Git.lua b/lua/onedarker/Git.lua new file mode 100644 index 00000000..b47ccf23 --- /dev/null +++ b/lua/onedarker/Git.lua @@ -0,0 +1,10 @@ +local Git = { + SignAdd = { fg = C.sign_add }, + SignChange = { fg = C.sign_change }, + SignDelete = { fg = C.sign_delete }, + GitSignsAdd = { fg = C.sign_add }, + GitSignsChange = { fg = C.sign_change }, + GitSignsDelete = { fg = C.sign_delete }, +} + +return Git diff --git a/lua/onedarker/LSP.lua b/lua/onedarker/LSP.lua new file mode 100644 index 00000000..1ba7056b --- /dev/null +++ b/lua/onedarker/LSP.lua @@ -0,0 +1,104 @@ +local LSP = { + LspDiagnosticsDefaultError = { fg = C.error_red }, + LspDiagnosticsDefaultWarning = { fg = C.warning_orange }, + LspDiagnosticsDefaultInformation = { fg = C.info_yellow }, + LspDiagnosticsDefaultHint = { fg = C.hint_blue }, + LspDiagnosticsVirtualTextError = { fg = C.error_red }, + LspDiagnosticsVirtualTextWarning = { fg = C.warning_orange }, + LspDiagnosticsVirtualTextInformation = { fg = C.info_yellow }, + LspDiagnosticsVirtualTextHint = { fg = C.hint_blue }, + LspDiagnosticsFloatingError = { fg = C.error_red }, + LspDiagnosticsFloatingWarning = { fg = C.warning_orange }, + LspDiagnosticsFloatingInformation = { fg = C.info_yellow }, + LspDiagnosticsFloatingHint = { fg = C.hint_blue }, + LspDiagnosticsSignError = { fg = C.error_red }, + LspDiagnosticsSignWarning = { fg = C.warning_orange }, + LspDiagnosticsSignInformation = { fg = C.info_yellow }, + LspDiagnosticsSignHint = { fg = C.hint_blue }, + LspDiagnosticsError = { fg = C.error_red }, + LspDiagnosticsWarning = { fg = C.warning_orange }, + LspDiagnosticsInformation = { fg = C.info_yellow }, + LspDiagnosticsHint = { fg = C.hint_blue }, + LspDiagnosticsUnderlineError = { style = "underline" }, + LspDiagnosticsUnderlineWarning = { style = "underline" }, + LspDiagnosticsUnderlineInformation = { style = "underline" }, + LspDiagnosticsUnderlineHint = { style = "underline" }, + QuickScopePrimary = { fg = C.purple_test, style = "underline" }, + QuickScopeSecondary = { fg = C.cyan_test, style = "underline" }, + TelescopeSelection = { fg = C.hint_blue }, + TelescopeMatching = { fg = C.info_yellow, style = "bold" }, + TelescopeBorder = { fg = C.cyan, bg = Config.transparent_background and "NONE" or C.bg }, + NvimTreeFolderIcon = { fg = C.blue }, + NvimTreeIndentMarker = { fg = C.gray }, + NvimTreeNormal = { fg = C.light_gray, bg = C.alt_bg }, + NvimTreeVertSplit = { fg = C.alt_bg, bg = C.alt_bg }, + NvimTreeFolderName = { fg = C.blue }, + NvimTreeOpenedFolderName = { fg = C.cyan, style = "italic" }, + NvimTreeImageFile = { fg = C.purple }, + NvimTreeSpecialFile = { fg = C.orange }, + NvimTreeGitStaged = { fg = C.sign_add }, + NvimTreeGitNew = { fg = C.sign_add }, + NvimTreeGitDirty = { fg = C.sign_add }, + NvimTreeGitDeleted = { fg = C.sign_delete }, + NvimTreeGitMerge = { fg = C.sign_change }, + NvimTreeGitRenamed = { fg = C.sign_change }, + NvimTreeSymlink = { fg = C.cyan }, + NvimTreeRootFolder = { fg = C.fg, style = "bold" }, + NvimTreeExecFile = { fg = C.green }, + LirFloatNormal = { fg = C.light_gray, bg = C.alt_bg }, + LirDir = { fg = C.blue }, + LirSymLink = { fg = C.cyan }, + LirEmptyDirText = { fg = C.blue }, + BufferCurrent = { fg = C.fg, bg = C.bg }, + BufferCurrentIndex = { fg = C.fg, bg = C.bg }, + BufferCurrentMod = { fg = C.info_yellow, bg = C.bg }, + BufferCurrentSign = { fg = C.hint_blue, bg = C.bg }, + BufferCurrentTarget = { fg = C.red, bg = C.bg, style = "bold" }, + BufferVisible = { fg = C.fg, bg = C.bg }, + BufferVisibleIndex = { fg = C.fg, bg = C.bg }, + BufferVisibleMod = { fg = C.info_yellow, bg = C.bg }, + BufferVisibleSign = { fg = C.gray, bg = C.bg }, + BufferVisibleTarget = { fg = C.red, bg = C.bg, style = "bold" }, + BufferInactive = { fg = C.gray, bg = C.alt_bg }, + BufferInactiveIndex = { fg = C.gray, bg = C.alt_bg }, + BufferInactiveMod = { fg = C.info_yellow, bg = C.alt_bg }, + BufferInactiveSign = { fg = C.gray, bg = C.alt_bg }, + BufferInactiveTarget = { fg = C.red, bg = C.alt_bg, style = "bold" }, + StatusLine = { fg = C.alt_bg }, + StatusLineNC = { fg = C.alt_bg }, + StatusLineSeparator = { fg = C.alt_bg }, + StatusLineTerm = { fg = C.alt_bg }, + StatusLineTermNC = { fg = C.alt_bg }, + CodiVirtualText = { fg = C.hint_blue }, + IndentBlanklineContextChar = { fg = C.context }, + IndentBlanklineChar = { fg = C.dark_gray }, + IndentBlanklineSpaceChar = { fg = C.cyan_test }, + IndentBlanklineSpaceCharBlankline = { fg = C.info_yellow }, + DashboardHeader = { fg = C.blue }, + DashboardCenter = { fg = C.purple }, + DashboardFooter = { fg = C.cyan }, + xmlTag = { fg = C.blue }, + xmlTagName = { fg = C.blue }, + xmlEndTag = { fg = C.blue }, + CompeDocumentation = { bg = C.alt_bg }, + DiffViewNormal = { fg = C.gray, bg = C.alt_bg }, + DiffviewStatusAdded = { fg = C.sign_add }, + DiffviewStatusModified = { fg = C.sign_change }, + DiffviewStatusRenamed = { fg = C.sign_change }, + DiffviewStatusDeleted = { fg = C.sign_delete }, + DiffviewFilePanelInsertion = { fg = C.sign_add }, + DiffviewFilePanelDeletion = { fg = C.sign_delete }, + DiffviewVertSplit = { bg = C.bg }, + diffAdded = { fg = C.sign_add }, + diffRemoved = { fg = C.sign_delete }, + diffFileId = { fg = C.blue, style = "bold,reverse" }, + diffFile = { fg = C.alt_bg }, + diffNewFile = { fg = C.green }, + diffOldFile = { fg = C.red }, + debugPc = { bg = C.cyan }, + debugBreakpoint = { fg = C.red, style = "reverse" }, + FocusedSymbol = { fg = C.purple, style = "bold" }, + SymbolsOutlineConnector = { fg = C.context }, +} + +return LSP diff --git a/lua/onedarker/Treesitter.lua b/lua/onedarker/Treesitter.lua new file mode 100644 index 00000000..c8607ce5 --- /dev/null +++ b/lua/onedarker/Treesitter.lua @@ -0,0 +1,66 @@ +local Treesitter = { + TSComment = { fg = C.gray }, + TSAnnotation = { fg = C.blue }, + TSAttribute = { fg = C.cyan }, + TSConstructor = { fg = C.yellow }, + TSType = { fg = C.yellow }, + TSTypeBuiltin = { fg = C.yellow }, + TSConditional = { fg = C.purple }, + TSException = { fg = C.purple }, + TSInclude = { fg = C.purple }, + TSKeyword = { fg = C.purple }, + TSKeywordReturn = { fg = C.purple }, + TSKeywordFunction = { fg = C.purple }, + TSLabel = { fg = C.red }, + TSNone = { fg = C.fg }, + TSNamespace = { fg = C.purple }, + TSRepeat = { fg = C.purple }, + TSConstant = { fg = C.orange }, + TSConstBuiltin = { fg = C.orange }, + TSFloat = { fg = C.orange }, + TSNumber = { fg = C.orange }, + TSBoolean = { fg = C.orange }, + TSCharacter = { fg = C.green }, + TSError = { fg = C.error_red }, + TSFunction = { fg = C.blue }, + TSFuncBuiltin = { fg = C.blue }, + TSMethod = { fg = C.blue }, + TSConstMacro = { fg = C.cyan }, + TSFuncMacro = { fg = C.blue }, + TSProperty = { fg = C.cyan }, + TSOperator = { fg = C.purple }, + TSField = { fg = C.blue }, + TSParameter = { fg = C.red }, + TSParameterReference = { fg = C.red }, + TSVariable = { fg = C.fg }, + TSVariableBuiltin = { fg = C.red }, + TSSymbol = { fg = C.cyan }, + TSText = { fg = C.fg }, + TSTextReference = { fg = C.red }, + TSPunctDelimiter = { fg = C.fg }, + TSTagDelimiter = { fg = C.gray }, + TSTagAttribute = { fg = C.orange }, + TSPunctBracket = { fg = C.fg }, + TSPunctSpecial = { fg = C.fg }, + TSString = { fg = C.green }, + TSStringRegex = { fg = C.orange }, + TSStringEscape = { fg = C.orange }, + TSTag = { fg = C.blue }, + TSEmphasis = { style = "italic" }, + TSUnderline = { style = "underline" }, + TSWarning = { fg = C.warning_orange }, + TSDanger = { fg = C.error_red }, + TSTitle = { fg = C.blue, style = "bold" }, + TSLiteral = { fg = C.green }, + TSURI = { fg = C.blue, style = "underline" }, + TSMath = { fg = C.fg }, + TSKeywordOperator = { fg = C.purple }, + TSStructure = { fg = C.fg }, + TSStrong = { fg = C.yellow_orange }, + TSQueryLinterError = { fg = C.warning_orange }, + TSEnvironment = { fg = C.fg }, + TSEnvironmentName = { fg = C.fg }, + TSNote = { fg = C.blue }, +} + +return Treesitter diff --git a/lua/onedarker/Whichkey.lua b/lua/onedarker/Whichkey.lua new file mode 100644 index 00000000..86b42bd6 --- /dev/null +++ b/lua/onedarker/Whichkey.lua @@ -0,0 +1,9 @@ +local Whichkey = { + WhichKey = { fg = C.purple }, + WhichKeySeperator = { fg = C.green }, + WhichKeyGroup = { fg = C.cyan }, + WhichKeyDesc = { fg = C.blue }, + WhichKeyFloat = { bg = C.dark }, +} + +return Whichkey diff --git a/lua/onedarker/config.lua b/lua/onedarker/config.lua new file mode 100644 index 00000000..ebac7109 --- /dev/null +++ b/lua/onedarker/config.lua @@ -0,0 +1,23 @@ +local config + +vim = vim or { g = {}, o = {} } + +local function opt(key, default) + if vim.g[key] == nil then + return default + end + if vim.g[key] == 0 then + return false + end + return vim.g[key] +end + +config = { + transparent_background = opt("transparent_background", false), + italic_comments = opt("italic_keywords", true) and "italic" or "NONE", + italic_keywords = opt("italic_keywords", true) and "italic" or "NONE", + italic_functions = opt("italic_function", false) and "italic" or "NONE", + italic_variables = opt("italic_variables", true) and "italic" or "NONE", +} + +return config diff --git a/lua/onedarker/highlights.lua b/lua/onedarker/highlights.lua new file mode 100644 index 00000000..e4b9eeac --- /dev/null +++ b/lua/onedarker/highlights.lua @@ -0,0 +1,99 @@ +local highlights = { + Normal = { fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg }, + SignColumn = { bg = C.bg }, + MsgArea = { fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg }, + ModeMsg = { fg = C.fg, bg = C.bg }, + MsgSeparator = { fg = C.fg, bg = C.bg }, + SpellBad = { fg = C.error_red, style = "underline" }, + SpellCap = { fg = C.yellow, style = "underline" }, + SpellLocal = { fg = C.green, style = "underline" }, + SpellRare = { fg = C.purple, style = "underline" }, + NormalNC = { fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg }, + Pmenu = { fg = C.light_gray, bg = C.popup_back }, + PmenuSel = { fg = C.alt_bg, bg = C.blue }, + WildMenu = { fg = C.alt_bg, bg = C.blue }, + CursorLineNr = { fg = C.light_gray, style = "bold" }, + Comment = { fg = C.green, style = "italic" }, + Folded = { fg = C.accent, bg = C.alt_bg }, + FoldColumn = { fg = C.accent, bg = C.alt_bg }, + LineNr = { fg = C.context }, + FloatBoder = { fg = C.gray, bg = C.alt_bg }, + Whitespace = { fg = C.bg }, + VertSplit = { fg = C.bg, bg = C.fg }, + CursorLine = { bg = C.dark }, + CursorColumn = { bg = C.dark }, + ColorColumn = { bg = C.dark }, + NormalFloat = { bg = C.dark }, + Visual = { bg = C.ui_blue }, + VisualNOS = { bg = C.alt_bg }, + WarningMsg = { fg = C.error_red, bg = C.bg }, + DiffAdd = { fg = C.alt_bg, bg = C.sign_add }, + DiffChange = { fg = C.alt_bg, bg = C.sign_change, style = "underline" }, + DiffDelete = { fg = C.alt_bg, bg = C.sign_delete }, + QuickFixLine = { bg = C.dark_gray }, + PmenuSbar = { bg = C.alt_bg }, + PmenuThumb = { bg = C.gray }, + MatchWord = { style = "underline" }, + MatchParen = { fg = C.hint_blue, bg = C.bg, style = "underline" }, + MatchWordCur = { style = "underline" }, + MatchParenCur = { style = "underline" }, + Cursor = { fg = C.cursor_fg, bg = C.cursor_bg }, + lCursor = { fg = C.cursor_fg, bg = C.cursor_bg }, + CursorIM = { fg = C.cursor_fg, bg = C.cursor_bg }, + TermCursor = { fg = C.cursor_fg, bg = C.cursor_bg }, + TermCursorNC = { fg = C.cursor_fg, bg = C.cursor_bg }, + Conceal = { fg = C.accent }, + Directory = { fg = C.blue }, + SpecialKey = { fg = C.blue, style = "bold" }, + Title = { fg = C.blue, style = "bold" }, + ErrorMsg = { fg = C.error_red, bg = C.bg, style = "bold" }, + Search = { fg = C.light_gray, bg = C.search_blue }, + IncSearch = { fg = C.light_gray, bg = C.search_blue }, + Substitute = { fg = C.light_gray, bg = C.search_orange }, + MoreMsg = { fg = C.orange }, + Question = { fg = C.orange }, + EndOfBuffer = { fg = C.bg }, + NonText = { fg = C.bg }, + Variable = { fg = C.cyan }, + String = { fg = C.green }, + Character = { fg = C.green }, + Constant = { fg = C.orange }, + Number = { fg = C.orange }, + Boolean = { fg = C.orange }, + Float = { fg = C.orange }, + Identifier = { fg = C.fg }, + Function = { fg = C.blue }, + Operator = { fg = C.purple }, + Type = { fg = C.cyan }, + StorageClass = { fg = C.cyan }, + Structure = { fg = C.purple }, + Typedef = { fg = C.purple }, + Keyword = { fg = C.purple }, + Statement = { fg = C.purple }, + Conditional = { fg = C.purple }, + Repeat = { fg = C.purple }, + Label = { fg = C.cyan }, + Exception = { fg = C.purple }, + Include = { fg = C.purple }, + PreProc = { fg = C.purple }, + Define = { fg = C.purple }, + Macro = { fg = C.purple }, + PreCondit = { fg = C.purple }, + Special = { fg = C.purple }, + SpecialChar = { fg = C.fg }, + Tag = { fg = C.blue }, + Debug = { fg = C.red }, + Delimiter = { fg = C.fg }, + SpecialComment = { fg = C.gray }, + Underlined = { style = "underline" }, + Bold = { style = "bold" }, + Italic = { style = "italic" }, + Ignore = { fg = C.cyan, bg = C.bg, style = "bold" }, + Todo = { fg = C.red, bg = C.bg, style = "bold" }, + Error = { fg = C.error_red, bg = C.bg, style = "bold" }, + TabLine = { fg = C.light_gray, bg = C.alt_bg }, + TabLineSel = { fg = C.fg, bg = C.alt_bg }, + TabLineFill = { fg = C.fg, bg = C.alt_bg }, +} + +return highlights diff --git a/lua/onedarker/init.lua b/lua/onedarker/init.lua new file mode 100644 index 00000000..852e0103 --- /dev/null +++ b/lua/onedarker/init.lua @@ -0,0 +1,30 @@ +vim.api.nvim_command "hi clear" +if vim.fn.exists "syntax_on" then + vim.api.nvim_command "syntax reset" +end +vim.o.background = "dark" +vim.o.termguicolors = true +vim.g.colors_name = "onedarker" + +local util = require "onedarker.util" +Config = require "onedarker.config" +C = require "onedarker.palette" +local highlights = require "onedarker.highlights" +local Treesitter = require "onedarker.Treesitter" +local markdown = require "onedarker.markdown" +local Whichkey = require "onedarker.Whichkey" +local Git = require "onedarker.Git" +local LSP = require "onedarker.LSP" + +local skeletons = { + highlights, + Treesitter, + markdown, + Whichkey, + Git, + LSP, +} + +for _, skeleton in ipairs(skeletons) do + util.initialise(skeleton) +end diff --git a/lua/onedarker/markdown.lua b/lua/onedarker/markdown.lua new file mode 100644 index 00000000..2b83e056 --- /dev/null +++ b/lua/onedarker/markdown.lua @@ -0,0 +1,27 @@ +local markdown = { + markdownBlockquote = { fg = C.accent }, + markdownBold = { fg = C.yellow, style = "bold" }, + markdownCode = { fg = C.green }, + markdownCodeBlock = { fg = C.green }, + markdownCodeDelimiter = { fg = C.green }, + markdownH1 = { fg = C.blue }, + markdownH2 = { fg = C.blue }, + markdownH3 = { fg = C.blue }, + markdownH4 = { fg = C.blue }, + markdownH5 = { fg = C.blue }, + markdownH6 = { fg = C.blue }, + markdownHeadingDelimiter = { fg = C.red }, + markdownHeadingRule = { fg = C.accent }, + markdownId = { fg = C.purple }, + markdownIdDeclaration = { fg = C.blue }, + markdownIdDelimiter = { fg = C.light_gray }, + markdownLinkDelimiter = { fg = C.light_gray }, + markdownItalic = { style = "italic" }, + markdownLinkText = { fg = C.blue }, + markdownListMarker = { fg = C.red }, + markdownOrderedListMarker = { fg = C.red }, + markdownRule = { fg = C.accent }, + markdownUrl = { fg = C.cyan, style = "underline" }, +} + +return markdown diff --git a/lua/onedarker/palette.lua b/lua/onedarker/palette.lua new file mode 100644 index 00000000..c3116b1e --- /dev/null +++ b/lua/onedarker/palette.lua @@ -0,0 +1,39 @@ +local colors = { + fg = "#abb2bf", + bg = "#1f2227", + alt_bg = "#282c34", + dark = "#282c34", + accent = "#BBBBBB", + dark_gray = "#2a2f3e", + context = "#4b5263", + popup_back = "#282c34", + search_orange = "#613214", + search_blue = "#5e81ac", + gray = "#5c6370", + light_gray = "#abb2bf", + blue = "#61AFEF", + dark_blue = "#223E55", + green = "#98C379", + cyan = "#56B6C2", + red = "#e06c75", + orange = "#D19A66", + light_red = "#be5046", + yellow = "#E5C07B", + yellow_orange = "#D7BA7D", + purple = "#C678DD", + magenta = "#D16D9E", + cursor_fg = "#515052", + cursor_bg = "#AEAFAD", + sign_add = "#587c0c", + sign_change = "#0c7d9d", + sign_delete = "#94151b", + error_red = "#F44747", + warning_orange = "#ff8800", + info_yellow = "#FFCC66", + hint_blue = "#4FC1FF", + purple_test = "#ff007c", + cyan_test = "#00dfff", + ui_blue = "#264F78", +} + +return colors diff --git a/lua/onedarker/util.lua b/lua/onedarker/util.lua new file mode 100644 index 00000000..dbac18a2 --- /dev/null +++ b/lua/onedarker/util.lua @@ -0,0 +1,25 @@ +local M = {} + +local function highlight(group, properties) + local bg = properties.bg == nil and "" or "guibg=" .. properties.bg + local fg = properties.fg == nil and "" or "guifg=" .. properties.fg + local style = properties.style == nil and "" or "gui=" .. properties.style + + local cmd = table.concat({ + "highlight", + group, + bg, + fg, + style, + }, " ") + + vim.api.nvim_command(cmd) +end + +function M.initialise(skeleton) + for group, properties in pairs(skeleton) do + highlight(group, properties) + end +end + +return M diff --git a/lua/spacegray/Git.lua b/lua/spacegray/Git.lua deleted file mode 100644 index b47ccf23..00000000 --- a/lua/spacegray/Git.lua +++ /dev/null @@ -1,10 +0,0 @@ -local Git = { - SignAdd = { fg = C.sign_add }, - SignChange = { fg = C.sign_change }, - SignDelete = { fg = C.sign_delete }, - GitSignsAdd = { fg = C.sign_add }, - GitSignsChange = { fg = C.sign_change }, - GitSignsDelete = { fg = C.sign_delete }, -} - -return Git diff --git a/lua/spacegray/LSP.lua b/lua/spacegray/LSP.lua deleted file mode 100644 index dd3d77ac..00000000 --- a/lua/spacegray/LSP.lua +++ /dev/null @@ -1,99 +0,0 @@ -local LSP = { - LspDiagnosticsDefaultError = { fg = C.error_red }, - LspDiagnosticsDefaultWarning = { fg = C.warning_orange }, - LspDiagnosticsDefaultInformation = { fg = C.info_yellow }, - LspDiagnosticsDefaultHint = { fg = C.hint_blue }, - LspDiagnosticsVirtualTextError = { fg = C.error_red }, - LspDiagnosticsVirtualTextWarning = { fg = C.warning_orange }, - LspDiagnosticsVirtualTextInformation = { fg = C.info_yellow }, - LspDiagnosticsVirtualTextHint = { fg = C.hint_blue }, - LspDiagnosticsFloatingError = { fg = C.error_red }, - LspDiagnosticsFloatingWarning = { fg = C.warning_orange }, - LspDiagnosticsFloatingInformation = { fg = C.info_yellow }, - LspDiagnosticsFloatingHint = { fg = C.hint_blue }, - LspDiagnosticsSignError = { fg = C.error_red }, - LspDiagnosticsSignWarning = { fg = C.warning_orange }, - LspDiagnosticsSignInformation = { fg = C.info_yellow }, - LspDiagnosticsSignHint = { fg = C.hint_blue }, - LspDiagnosticsError = { fg = C.error_red }, - LspDiagnosticsWarning = { fg = C.warning_orange }, - LspDiagnosticsInformation = { fg = C.info_yellow }, - LspDiagnosticsHint = { fg = C.hint_blue }, - LspDiagnosticsUnderlineError = { style = "underline" }, - LspDiagnosticsUnderlineWarning = { style = "underline" }, - LspDiagnosticsUnderlineInformation = { style = "underline" }, - LspDiagnosticsUnderlineHint = { style = "underline" }, - QuickScopePrimary = { fg = C.purple_test, style = "underline" }, - QuickScopeSecondary = { fg = C.cyan_test, style = "underline" }, - TelescopeSelection = { fg = C.hint_blue }, - TelescopeMatching = { fg = C.info_yellow, style = "bold" }, - TelescopeBorder = { fg = C.cyan, bg = Config.transparent_background and "NONE" or C.bg }, - NvimTreeFolderIcon = { fg = C.blue }, - NvimTreeIndentMarker = { fg = C.gray }, - NvimTreeNormal = { fg = C.light_gray, bg = C.alt_bg }, - NvimTreeVertSplit = { fg = C.alt_bg, bg = C.alt_bg }, - NvimTreeFolderName = { fg = C.blue }, - NvimTreeOpenedFolderName = { fg = C.cyan, style = "italic" }, - NvimTreeImageFile = { fg = C.purple }, - NvimTreeSpecialFile = { fg = C.orange }, - NvimTreeGitStaged = { fg = C.sign_add }, - NvimTreeGitNew = { fg = C.sign_add }, - NvimTreeGitDirty = { fg = C.sign_add }, - NvimTreeGitDeleted = { fg = C.sign_delete }, - NvimTreeGitMerge = { fg = C.sign_change }, - NvimTreeGitRenamed = { fg = C.sign_change }, - NvimTreeSymlink = { fg = C.cyan }, - NvimTreeRootFolder = { fg = C.fg, style = "bold" }, - NvimTreeExecFile = { fg = C.green }, - LirFloatNormal = { fg = C.light_gray, bg = C.alt_bg }, - LirDir = { fg = C.blue }, - LirSymLink = { fg = C.cyan }, - LirEmptyDirText = { fg = C.blue }, - BufferCurrent = { fg = C.fg, bg = C.bg }, - BufferCurrentIndex = { fg = C.fg, bg = C.bg }, - BufferCurrentMod = { fg = C.info_yellow, bg = C.bg }, - BufferCurrentSign = { fg = C.hint_blue, bg = C.bg }, - BufferCurrentTarget = { fg = C.red, bg = C.bg, style = "bold" }, - BufferVisible = { fg = C.fg, bg = C.bg }, - BufferVisibleIndex = { fg = C.fg, bg = C.bg }, - BufferVisibleMod = { fg = C.info_yellow, bg = C.bg }, - BufferVisibleSign = { fg = C.gray, bg = C.bg }, - BufferVisibleTarget = { fg = C.red, bg = C.bg, style = "bold" }, - BufferInactive = { fg = C.gray, bg = C.alt_bg }, - BufferInactiveIndex = { fg = C.gray, bg = C.alt_bg }, - BufferInactiveMod = { fg = C.info_yellow, bg = C.alt_bg }, - BufferInactiveSign = { fg = C.gray, bg = C.alt_bg }, - BufferInactiveTarget = { fg = C.red, bg = C.alt_bg, style = "bold" }, - StatusLine = { fg = C.alt_bg }, - StatusLineNC = { fg = C.alt_bg }, - StatusLineSeparator = { fg = C.alt_bg }, - StatusLineTerm = { fg = C.alt_bg }, - StatusLineTermNC = { fg = C.alt_bg }, - CodiVirtualText = { fg = C.hint_blue }, - IndentBlanklineContextChar = { fg = C.accent }, - DashboardHeader = { fg = C.blue }, - DashboardCenter = { fg = C.purple }, - DashboardFooter = { fg = C.cyan }, - xmlTag = { fg = C.cyan }, - xmlTagName = { fg = C.cyan }, - xmlEndTag = { fg = C.cyan }, - CompeDocumentation = { bg = C.alt_bg }, - DiffViewNormal = { fg = C.gray, bg = C.alt_bg }, - DiffviewStatusAdded = { fg = C.sign_add }, - DiffviewStatusModified = { fg = C.sign_change }, - DiffviewStatusRenamed = { fg = C.sign_change }, - DiffviewStatusDeleted = { fg = C.sign_delete }, - DiffviewFilePanelInsertion = { fg = C.sign_add }, - DiffviewFilePanelDeletion = { fg = C.sign_delete }, - DiffviewVertSplit = { bg = C.bg }, - diffAdded = { fg = C.sign_add }, - diffRemoved = { fg = C.sign_delete }, - diffFileId = { fg = C.blue, style = "bold,reverse" }, - diffFile = { fg = C.alt_bg }, - diffNewFile = { fg = C.green }, - diffOldFile = { fg = C.red }, - debugPc = { bg = C.cyan }, - debugBreakpoint = { fg = C.red, style = "reverse" }, -} - -return LSP diff --git a/lua/spacegray/Treesitter.lua b/lua/spacegray/Treesitter.lua deleted file mode 100644 index 4e5ce16e..00000000 --- a/lua/spacegray/Treesitter.lua +++ /dev/null @@ -1,56 +0,0 @@ -local Treesitter = { - TSComment = { fg = C.gray }, - TSAnnotation = { fg = C.purple }, - TSAttribute = { fg = C.cyan }, - TSConstructor = { fg = C.purple }, - TSType = { fg = C.purple }, - TSTypeBuiltin = { fg = C.purple }, - TSConditional = { fg = C.blue }, - TSException = { fg = C.blue }, - TSInclude = { fg = C.blue }, - TSKeyword = { fg = C.blue }, - TSKeywordFunction = { fg = C.blue }, - TSLabel = { fg = C.blue }, - TSNamespace = { fg = C.blue }, - TSRepeat = { fg = C.blue }, - TSConstant = { fg = C.orange }, - TSConstBuiltin = { fg = C.red }, - TSFloat = { fg = C.red }, - TSNumber = { fg = C.red }, - TSBoolean = { fg = C.red }, - TSCharacter = { fg = C.light_green }, - TSError = { fg = C.error_red }, - TSFunction = { fg = C.yellow }, - TSFuncBuiltin = { fg = C.yellow }, - TSMethod = { fg = C.yellow }, - TSConstMacro = { fg = C.cyan }, - TSFuncMacro = { fg = C.yellow }, - TSVariable = { fg = C.light_blue }, - TSVariableBuiltin = { fg = C.light_blue }, - TSProperty = { fg = C.light_blue }, - TSOperator = { fg = C.gray }, - TSField = { fg = C.light_blue }, - TSParameter = { fg = C.light_blue }, - TSParameterReference = { fg = C.light_blue }, - TSSymbol = { fg = C.light_blue }, - TSText = { fg = C.fg }, - TSPunctDelimiter = { fg = C.gray }, - TSTagDelimiter = { fg = C.gray }, - TSPunctBracket = { fg = C.gray }, - TSPunctSpecial = { fg = C.gray }, - TSString = { fg = C.green }, - TSStringRegex = { fg = C.yellow_orange }, - TSStringEscape = { fg = C.yellow_orange }, - TSTag = { fg = C.blue }, - TSEmphasis = { style = "italic" }, - TSUnderline = { style = "underline" }, - TSTitle = { fg = C.blue, style = "bold" }, - TSLiteral = { fg = C.yellow_orange }, - TSURI = { fg = C.yellow_orange, style = "underline" }, - TSKeywordOperator = { fg = C.blue }, - TSStructure = { fg = C.light_blue }, - TSStrong = { fg = C.yellow_orange }, - TSQueryLinterError = { fg = C.warning_orange }, -} - -return Treesitter diff --git a/lua/spacegray/Whichkey.lua b/lua/spacegray/Whichkey.lua deleted file mode 100644 index 5d1ae7ce..00000000 --- a/lua/spacegray/Whichkey.lua +++ /dev/null @@ -1,9 +0,0 @@ -local Whichkey = { - WhichKey = { fg = C.purple }, - WhichKeySeperator = { fg = C.green }, - WhichKeyGroup = { fg = C.blue }, - WhichKeyDesc = { fg = C.light_blue }, - WhichKeyFloat = { bg = C.dark }, -} - -return Whichkey diff --git a/lua/spacegray/config.lua b/lua/spacegray/config.lua deleted file mode 100644 index ebac7109..00000000 --- a/lua/spacegray/config.lua +++ /dev/null @@ -1,23 +0,0 @@ -local config - -vim = vim or { g = {}, o = {} } - -local function opt(key, default) - if vim.g[key] == nil then - return default - end - if vim.g[key] == 0 then - return false - end - return vim.g[key] -end - -config = { - transparent_background = opt("transparent_background", false), - italic_comments = opt("italic_keywords", true) and "italic" or "NONE", - italic_keywords = opt("italic_keywords", true) and "italic" or "NONE", - italic_functions = opt("italic_function", false) and "italic" or "NONE", - italic_variables = opt("italic_variables", true) and "italic" or "NONE", -} - -return config diff --git a/lua/spacegray/highlights.lua b/lua/spacegray/highlights.lua deleted file mode 100644 index 208c2c62..00000000 --- a/lua/spacegray/highlights.lua +++ /dev/null @@ -1,99 +0,0 @@ -local highlights = { - Normal = { fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg }, - SignColumn = { bg = C.bg }, - MsgArea = { fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg }, - ModeMsg = { fg = C.fg, bg = C.bg }, - MsgSeparator = { fg = C.fg, bg = C.bg }, - SpellBad = { fg = C.error_red, style = "underline" }, - SpellCap = { fg = C.yellow, style = "underline" }, - SpellLocal = { fg = C.green, style = "underline" }, - SpellRare = { fg = C.purple, style = "underline" }, - NormalNC = { fg = C.fg, bg = Config.transparent_background and "NONE" or C.bg }, - Pmenu = { fg = C.light_gray, bg = C.popup_back }, - PmenuSel = { fg = C.alt_bg, bg = C.blue }, - WildMenu = { fg = C.alt_bg, bg = C.blue }, - CursorLineNr = { fg = C.light_gray, style = "bold" }, - Comment = { fg = C.gray, style = "italic" }, - Folded = { fg = C.accent, bg = C.alt_bg }, - FoldColumn = { fg = C.accent, bg = C.alt_bg }, - LineNr = { fg = C.gray }, - FloatBoder = { fg = C.gray, bg = C.alt_bg }, - Whitespace = { fg = C.bg }, - VertSplit = { fg = C.bg, bg = C.fg }, - CursorLine = { bg = C.dark }, - CursorColumn = { bg = C.dark }, - ColorColumn = { bg = C.dark }, - NormalFloat = { bg = C.dark }, - Visual = { bg = C.ui_blue }, - VisualNOS = { bg = C.alt_bg }, - WarningMsg = { fg = C.error_red, bg = C.bg }, - DiffAdd = { fg = C.alt_bg, bg = C.sign_add }, - DiffChange = { fg = C.alt_bg, bg = C.sign_change, style = "underline" }, - DiffDelete = { fg = C.alt_bg, bg = C.sign_delete }, - QuickFixLine = { bg = C.accent }, - PmenuSbar = { bg = C.alt_bg }, - PmenuThumb = { bg = C.gray }, - MatchWord = { style = "underline" }, - MatchParen = { fg = C.hint_blue, bg = C.bg, style = "underline" }, - MatchWordCur = { style = "underline" }, - MatchParenCur = { style = "underline" }, - Cursor = { fg = C.cursor_fg, bg = C.cursor_bg }, - lCursor = { fg = C.cursor_fg, bg = C.cursor_bg }, - CursorIM = { fg = C.cursor_fg, bg = C.cursor_bg }, - TermCursor = { fg = C.cursor_fg, bg = C.cursor_bg }, - TermCursorNC = { fg = C.cursor_fg, bg = C.cursor_bg }, - Conceal = { fg = C.accent }, - Directory = { fg = C.blue }, - SpecialKey = { fg = C.blue, style = "bold" }, - Title = { fg = C.blue, style = "bold" }, - ErrorMsg = { fg = C.error_red, bg = C.bg, style = "bold" }, - Search = { fg = C.light_gray, bg = C.search_blue }, - IncSearch = { fg = C.light_gray, bg = C.search_blue }, - Substitute = { fg = C.light_gray, bg = C.search_orange }, - MoreMsg = { fg = C.orange }, - Question = { fg = C.orange }, - EndOfBuffer = { fg = C.bg }, - NonText = { fg = C.bg }, - Variable = { fg = C.light_blue }, - String = { fg = C.green }, - Character = { fg = C.light_green }, - Constant = { fg = C.blue }, - Number = { fg = C.red }, - Boolean = { fg = C.red }, - Float = { fg = C.red }, - Identifier = { fg = C.light_blue }, - Function = { fg = C.yellow }, - Operator = { fg = C.gray }, - Type = { fg = C.purple }, - StorageClass = { fg = C.purple }, - Structure = { fg = C.purple }, - Typedef = { fg = C.purple }, - Keyword = { fg = C.blue }, - Statement = { fg = C.blue }, - Conditional = { fg = C.blue }, - Repeat = { fg = C.blue }, - Label = { fg = C.blue }, - Exception = { fg = C.blue }, - Include = { fg = C.blue }, - PreProc = { fg = C.purple }, - Define = { fg = C.purple }, - Macro = { fg = C.purple }, - PreCondit = { fg = C.purple }, - Special = { fg = C.orange }, - SpecialChar = { fg = C.white }, - Tag = { fg = C.blue }, - Debug = { fg = C.red }, - Delimiter = { fg = C.gray }, - SpecialComment = { fg = C.gray }, - Underlined = { style = "underline" }, - Bold = { style = "bold" }, - Italic = { style = "italic" }, - Ignore = { fg = C.cyan, bg = C.bg, style = "bold" }, - Todo = { fg = C.red, bg = C.bg, style = "bold" }, - Error = { fg = C.error_red, bg = C.bg, style = "bold" }, - TabLine = { fg = C.light_gray, bg = C.alt_bg }, - TabLineSel = { fg = C.white, bg = C.alt_bg }, - TabLineFill = { fg = C.white, bg = C.alt_bg }, -} - -return highlights diff --git a/lua/spacegray/init.lua b/lua/spacegray/init.lua deleted file mode 100644 index 9ae24dbb..00000000 --- a/lua/spacegray/init.lua +++ /dev/null @@ -1,43 +0,0 @@ -vim.api.nvim_command "hi clear" -if vim.fn.exists "syntax_on" then - vim.api.nvim_command "syntax reset" -end -vim.o.background = "dark" -vim.o.termguicolors = true -vim.g.colors_name = "spacegray" - -local util = require "spacegray.util" -Config = require "spacegray.config" -C = require "spacegray.palette" - -local async -async = vim.loop.new_async(vim.schedule_wrap(function() - local skeletons = {} - for _, skeleton in ipairs(skeletons) do - util.initialise(skeleton) - end - - async:close() -end)) - -local highlights = require "spacegray.highlights" -local Treesitter = require "spacegray.Treesitter" -local markdown = require "spacegray.markdown" -local Whichkey = require "spacegray.Whichkey" -local Git = require "spacegray.Git" -local LSP = require "spacegray.LSP" - -local skeletons = { - highlights, - Treesitter, - markdown, - Whichkey, - Git, - LSP, -} - -for _, skeleton in ipairs(skeletons) do - util.initialise(skeleton) -end - -async:send() diff --git a/lua/spacegray/markdown.lua b/lua/spacegray/markdown.lua deleted file mode 100644 index 2b83e056..00000000 --- a/lua/spacegray/markdown.lua +++ /dev/null @@ -1,27 +0,0 @@ -local markdown = { - markdownBlockquote = { fg = C.accent }, - markdownBold = { fg = C.yellow, style = "bold" }, - markdownCode = { fg = C.green }, - markdownCodeBlock = { fg = C.green }, - markdownCodeDelimiter = { fg = C.green }, - markdownH1 = { fg = C.blue }, - markdownH2 = { fg = C.blue }, - markdownH3 = { fg = C.blue }, - markdownH4 = { fg = C.blue }, - markdownH5 = { fg = C.blue }, - markdownH6 = { fg = C.blue }, - markdownHeadingDelimiter = { fg = C.red }, - markdownHeadingRule = { fg = C.accent }, - markdownId = { fg = C.purple }, - markdownIdDeclaration = { fg = C.blue }, - markdownIdDelimiter = { fg = C.light_gray }, - markdownLinkDelimiter = { fg = C.light_gray }, - markdownItalic = { style = "italic" }, - markdownLinkText = { fg = C.blue }, - markdownListMarker = { fg = C.red }, - markdownOrderedListMarker = { fg = C.red }, - markdownRule = { fg = C.accent }, - markdownUrl = { fg = C.cyan, style = "underline" }, -} - -return markdown diff --git a/lua/spacegray/palette.lua b/lua/spacegray/palette.lua deleted file mode 100644 index 924482fd..00000000 --- a/lua/spacegray/palette.lua +++ /dev/null @@ -1,40 +0,0 @@ -local colors = { - fg = "#ABB2BF", - bg = "#202020", - alt_bg = "#262626", - dark = "#222222", - accent = "#AAAAAA", - popup_back = "#2D2D30", - search_orange = "#613214", - search_blue = "#5e81ac", - white = "#D8DEE9", - gray = "#9BA1AB", - light_gray = "#c8c9c1", - blue = "#5f8ccd", - dark_blue = "#223E55", - light_blue = "#8dc0d5", - green = "#83ba8b", - cyan = "#4EC9B0", - light_green = "#B5CEA8", - red = "#D16969", - orange = "#D1866B", - light_red = "#CA535F", - yellow = "#ECCC8E", - yellow_orange = "#D7BA7D", - purple = "#BF82B4", - magenta = "#D16D9E", - cursor_fg = "#515052", - cursor_bg = "#AEAFAD", - sign_add = "#587c0c", - sign_change = "#0c7d9d", - sign_delete = "#94151b", - error_red = "#F44747", - warning_orange = "#ff8800", - info_yellow = "#FFCC66", - hint_blue = "#4FC1FF", - purple_test = "#ff007c", - cyan_test = "#00dfff", - ui_blue = "#264F78", -} - -return colors diff --git a/lua/spacegray/util.lua b/lua/spacegray/util.lua deleted file mode 100644 index dbac18a2..00000000 --- a/lua/spacegray/util.lua +++ /dev/null @@ -1,25 +0,0 @@ -local M = {} - -local function highlight(group, properties) - local bg = properties.bg == nil and "" or "guibg=" .. properties.bg - local fg = properties.fg == nil and "" or "guifg=" .. properties.fg - local style = properties.style == nil and "" or "gui=" .. properties.style - - local cmd = table.concat({ - "highlight", - group, - bg, - fg, - style, - }, " ") - - vim.api.nvim_command(cmd) -end - -function M.initialise(skeleton) - for group, properties in pairs(skeleton) do - highlight(group, properties) - end -end - -return M -- cgit v1.2.3 From bc5b315e534ac4c15af50edc5890fe328b8825d3 Mon Sep 17 00:00:00 2001 From: "hui.liu" Date: Mon, 30 Aug 2021 20:48:17 +0800 Subject: Setup tailwindcss language server (#1376) --- lua/config/defaults.lua | 18 +++++++++--------- lua/lsp/init.lua | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 4f538dbb..eb8726fa 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -948,15 +948,15 @@ lvim.lang = { }, }, tailwindcss = { - active = false, - filetypes = { - "html", - "css", - "scss", - "javascript", - "javascriptreact", - "typescript", - "typescriptreact", + lsp = { + active = false, + provider = "tailwindcss", + setup = { + cmd = { + DATA_PATH .. "/lspinstall/tailwindcss/tailwindcss-intellisense.sh", + "--stdio", + }, + }, }, }, terraform = { diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 1e1ff22e..b43bd419 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -125,7 +125,7 @@ end function M.setup(lang) local lsp_utils = require "lsp.utils" local lsp = lvim.lang[lang].lsp - if lsp_utils.is_client_active(lsp.provider) then + if (lsp.active ~= nil and not lsp.active) or lsp_utils.is_client_active(lsp.provider) then return end -- cgit v1.2.3 From 758ea6d07b2060a2802efc25da4b6937150edf61 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 30 Aug 2021 17:20:02 +0430 Subject: use `gd` to see git diff with previous head (#1426) --- lua/core/which-key.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lua') diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 71c0b695..8f2f2a5a 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -130,6 +130,10 @@ M.config = function() "Telescope git_bcommits", "Checkout commit(for current file)", }, + d = { + "Gitsigns diffthis HEAD", + "Git Diff", + }, }, l = { -- cgit v1.2.3 From 34301ead61bebc8228d7212bb38389fbe02fb534 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 30 Aug 2021 18:44:34 +0430 Subject: Set correct cursor in the peek preview window (#1424) --- lua/lsp/peek.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua') diff --git a/lua/lsp/peek.lua b/lua/lsp/peek.lua index cc8e57a9..dbc67417 100644 --- a/lua/lsp/peek.lua +++ b/lua/lsp/peek.lua @@ -42,6 +42,7 @@ local function create_floating_file(location, opts) local winnr = vim.api.nvim_open_win(bufnr, false, opts) vim.api.nvim_win_set_option(winnr, "winblend", 0) + vim.api.nvim_win_set_cursor(winnr, { range.start.line + 1, range.start.character }) vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr) -- Set some autocmds to close the window -- cgit v1.2.3 From ce7522095d1f9c3730db2d9793ed055bdde92bef Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 30 Aug 2021 19:04:04 +0430 Subject: update tailwindcss to match lspinstall (#1427) --- lua/config/defaults.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index eb8726fa..4f93f924 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -953,7 +953,7 @@ lvim.lang = { provider = "tailwindcss", setup = { cmd = { - DATA_PATH .. "/lspinstall/tailwindcss/tailwindcss-intellisense.sh", + DATA_PATH .. "/lspinstall/tailwindcss/node_modules/.bin/tailwindcss-language-server", "--stdio", }, }, -- cgit v1.2.3 From dc1151a90aa68f4f8d5350e40daa67034241c0e9 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Mon, 30 Aug 2021 14:19:59 -0400 Subject: fix: colorscheme tweaks --- lua/onedarker/Treesitter.lua | 8 ++++---- lua/onedarker/highlights.lua | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lua') diff --git a/lua/onedarker/Treesitter.lua b/lua/onedarker/Treesitter.lua index c8607ce5..0718b852 100644 --- a/lua/onedarker/Treesitter.lua +++ b/lua/onedarker/Treesitter.lua @@ -11,7 +11,7 @@ local Treesitter = { TSKeyword = { fg = C.purple }, TSKeywordReturn = { fg = C.purple }, TSKeywordFunction = { fg = C.purple }, - TSLabel = { fg = C.red }, + TSLabel = { fg = C.blue }, TSNone = { fg = C.fg }, TSNamespace = { fg = C.purple }, TSRepeat = { fg = C.purple }, @@ -48,8 +48,9 @@ local Treesitter = { TSTag = { fg = C.blue }, TSEmphasis = { style = "italic" }, TSUnderline = { style = "underline" }, - TSWarning = { fg = C.warning_orange }, - TSDanger = { fg = C.error_red }, + TSNote = { fg = C.info_yellow, style = "bold" }, + TSWarning = { fg = C.warning_orange, style = "bold" }, + TSDanger = { fg = C.error_red, style = "bold" }, TSTitle = { fg = C.blue, style = "bold" }, TSLiteral = { fg = C.green }, TSURI = { fg = C.blue, style = "underline" }, @@ -60,7 +61,6 @@ local Treesitter = { TSQueryLinterError = { fg = C.warning_orange }, TSEnvironment = { fg = C.fg }, TSEnvironmentName = { fg = C.fg }, - TSNote = { fg = C.blue }, } return Treesitter diff --git a/lua/onedarker/highlights.lua b/lua/onedarker/highlights.lua index e4b9eeac..d8facdd3 100644 --- a/lua/onedarker/highlights.lua +++ b/lua/onedarker/highlights.lua @@ -13,7 +13,7 @@ local highlights = { PmenuSel = { fg = C.alt_bg, bg = C.blue }, WildMenu = { fg = C.alt_bg, bg = C.blue }, CursorLineNr = { fg = C.light_gray, style = "bold" }, - Comment = { fg = C.green, style = "italic" }, + Comment = { fg = C.gray, style = "italic" }, Folded = { fg = C.accent, bg = C.alt_bg }, FoldColumn = { fg = C.accent, bg = C.alt_bg }, LineNr = { fg = C.context }, @@ -54,7 +54,7 @@ local highlights = { Question = { fg = C.orange }, EndOfBuffer = { fg = C.bg }, NonText = { fg = C.bg }, - Variable = { fg = C.cyan }, + Variable = { fg = C.fg }, String = { fg = C.green }, Character = { fg = C.green }, Constant = { fg = C.orange }, @@ -64,15 +64,15 @@ local highlights = { Identifier = { fg = C.fg }, Function = { fg = C.blue }, Operator = { fg = C.purple }, - Type = { fg = C.cyan }, - StorageClass = { fg = C.cyan }, + Type = { fg = C.yellow }, + StorageClass = { fg = C.yellow }, Structure = { fg = C.purple }, Typedef = { fg = C.purple }, Keyword = { fg = C.purple }, Statement = { fg = C.purple }, Conditional = { fg = C.purple }, Repeat = { fg = C.purple }, - Label = { fg = C.cyan }, + Label = { fg = C.blue }, Exception = { fg = C.purple }, Include = { fg = C.purple }, PreProc = { fg = C.purple }, -- cgit v1.2.3 From b6a0d5a921edb9fea506c18a354fde86bc2e6bbc Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Mon, 30 Aug 2021 18:23:39 -0400 Subject: fix: colorscheme Nontext = context closes #1416 --- lua/onedarker/highlights.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/onedarker/highlights.lua b/lua/onedarker/highlights.lua index d8facdd3..f8b3bd20 100644 --- a/lua/onedarker/highlights.lua +++ b/lua/onedarker/highlights.lua @@ -53,7 +53,7 @@ local highlights = { MoreMsg = { fg = C.orange }, Question = { fg = C.orange }, EndOfBuffer = { fg = C.bg }, - NonText = { fg = C.bg }, + NonText = { fg = C.context }, Variable = { fg = C.fg }, String = { fg = C.green }, Character = { fg = C.green }, -- cgit v1.2.3 From afa0efd5ddd0733656641eed6b714e7eee5d01cc Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Mon, 30 Aug 2021 18:24:58 -0400 Subject: fix: colorschem updates --- lua/onedarker/LSP.lua | 3 ++- lua/onedarker/highlights.lua | 2 +- lua/onedarker/markdown.lua | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/onedarker/LSP.lua b/lua/onedarker/LSP.lua index 1ba7056b..f2df59bd 100644 --- a/lua/onedarker/LSP.lua +++ b/lua/onedarker/LSP.lua @@ -27,7 +27,8 @@ local LSP = { QuickScopeSecondary = { fg = C.cyan_test, style = "underline" }, TelescopeSelection = { fg = C.hint_blue }, TelescopeMatching = { fg = C.info_yellow, style = "bold" }, - TelescopeBorder = { fg = C.cyan, bg = Config.transparent_background and "NONE" or C.bg }, + TelescopeBorder = { fg = C.blue, bg = Config.transparent_background and "NONE" or C.bg }, + TelescopePromptPrefix = { fg = C.purple }, NvimTreeFolderIcon = { fg = C.blue }, NvimTreeIndentMarker = { fg = C.gray }, NvimTreeNormal = { fg = C.light_gray, bg = C.alt_bg }, diff --git a/lua/onedarker/highlights.lua b/lua/onedarker/highlights.lua index f8b3bd20..a178bc52 100644 --- a/lua/onedarker/highlights.lua +++ b/lua/onedarker/highlights.lua @@ -54,7 +54,7 @@ local highlights = { Question = { fg = C.orange }, EndOfBuffer = { fg = C.bg }, NonText = { fg = C.context }, - Variable = { fg = C.fg }, + Variable = { fg = C.cyan }, String = { fg = C.green }, Character = { fg = C.green }, Constant = { fg = C.orange }, diff --git a/lua/onedarker/markdown.lua b/lua/onedarker/markdown.lua index 2b83e056..d3a5d485 100644 --- a/lua/onedarker/markdown.lua +++ b/lua/onedarker/markdown.lua @@ -10,7 +10,7 @@ local markdown = { markdownH4 = { fg = C.blue }, markdownH5 = { fg = C.blue }, markdownH6 = { fg = C.blue }, - markdownHeadingDelimiter = { fg = C.red }, + markdownHeadingDelimiter = { fg = C.blue }, markdownHeadingRule = { fg = C.accent }, markdownId = { fg = C.purple }, markdownIdDeclaration = { fg = C.blue }, -- cgit v1.2.3 From b22a3ccae6a23b69559401b790d7ca16d0c8e166 Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Mon, 30 Aug 2021 18:26:25 -0400 Subject: fix: blue -> cyan for telescope border --- lua/onedarker/LSP.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/onedarker/LSP.lua b/lua/onedarker/LSP.lua index f2df59bd..d2d3a870 100644 --- a/lua/onedarker/LSP.lua +++ b/lua/onedarker/LSP.lua @@ -27,7 +27,7 @@ local LSP = { QuickScopeSecondary = { fg = C.cyan_test, style = "underline" }, TelescopeSelection = { fg = C.hint_blue }, TelescopeMatching = { fg = C.info_yellow, style = "bold" }, - TelescopeBorder = { fg = C.blue, bg = Config.transparent_background and "NONE" or C.bg }, + TelescopeBorder = { fg = C.cyan, bg = Config.transparent_background and "NONE" or C.bg }, TelescopePromptPrefix = { fg = C.purple }, NvimTreeFolderIcon = { fg = C.blue }, NvimTreeIndentMarker = { fg = C.gray }, -- cgit v1.2.3 From 92ee9552e90bef282218069f4d74dd87d77b4fcd Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Tue, 31 Aug 2021 22:18:01 +0430 Subject: better vue support (#1438) --- lua/config/defaults.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 4f93f924..9aa60e9a 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -1077,6 +1077,27 @@ lvim.lang = { cmd = { DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", }, + root_dir = function(fname) + local util = require "lspconfig/util" + return util.root_pattern "package.json"(fname) or util.root_pattern "vue.config.js"(fname) or vim.fn.getcwd() + end, + init_options = { + config = { + vetur = { + completion = { + autoImport = true, + tagCasing = "kebab", + useScaffoldSnippets = true, + }, + useWorkspaceDependencies = true, + validation = { + script = true, + style = true, + template = true, + }, + }, + }, + }, }, }, }, -- cgit v1.2.3 From e9d8d8cd2ed24740ad881f74632feaafae83fe1d Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 1 Sep 2021 13:19:20 +0430 Subject: fix the string concat in logging (#1441) --- lua/lsp/null-ls/formatters.lua | 6 +++--- lua/lsp/null-ls/linters.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lua') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 26be00da..2c2a4f06 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -45,15 +45,15 @@ function M.list_configured(formatter_configs) local formatter = null_ls.builtins.formatting[fmt_config.exe] if not formatter then - Log:error("Not a valid formatter:", fmt_config.exe) + Log:error("Not a valid formatter: " .. fmt_config.exe) errors[fmt_config.exe] = {} -- Add data here when necessary else local formatter_cmd = services.find_command(formatter._opts.command) if not formatter_cmd then - Log:warn("Not found:", formatter._opts.command) + Log:warn("Not found: " .. formatter._opts.command) errors[fmt_config.exe] = {} -- Add data here when necessary else - Log:debug("Using formatter:", formatter_cmd) + Log:debug("Using formatter: " .. formatter_cmd) formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args } end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index bc191d7e..d88a8b83 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -45,15 +45,15 @@ function M.list_configured(linter_configs) local linter = null_ls.builtins.diagnostics[lnt_config.exe] if not linter then - Log:error("Not a valid linter:", lnt_config.exe) + Log:error("Not a valid linter: " .. lnt_config.exe) errors[lnt_config.exe] = {} -- Add data here when necessary else local linter_cmd = services.find_command(linter._opts.command) if not linter_cmd then - Log:warn("Not found:", linter._opts.command) + Log:warn("Not found: " .. linter._opts.command) errors[lnt_config.exe] = {} -- Add data here when necessary else - Log:debug("Using linter:", linter_cmd) + Log:debug("Using linter: " .. linter_cmd) linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } end end -- cgit v1.2.3 From d5d47d4d7a0b7c396f1bddffe8c5eddc355ce60a Mon Sep 17 00:00:00 2001 From: #!/bin/genesis Date: Fri, 3 Sep 2021 19:44:03 +0300 Subject: [Feature]: Add new which-key command for switching to the last buffer (#1440) * Add new which-key command for switching to last buffer * chore(whichkey) Rework buffer descriptions Co-authored-by: Luc Sinet --- lua/core/which-key.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lua') diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 8f2f2a5a..5ceffb57 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -72,25 +72,26 @@ M.config = function() ["h"] = { "nohlsearch", "No Highlight" }, b = { name = "Buffers", - j = { "BufferPick", "jump to buffer" }, - f = { "Telescope buffers", "Find buffer" }, - w = { "BufferWipeout", "wipeout buffer" }, + j = { "BufferPick", "Jump" }, + f = { "Telescope buffers", "Find" }, + b = { "b#", "Previous" }, + w = { "BufferWipeout", "Wipeout" }, e = { "BufferCloseAllButCurrent", - "close all but current buffer", + "Close all but current", }, - h = { "BufferCloseBuffersLeft", "close all buffers to the left" }, - l = { + l = { "BufferCloseBuffersLeft", "Close all - left" }, + r = { "BufferCloseBuffersRight", - "close all BufferLines to the right", + "Close all - right", }, D = { "BufferOrderByDirectory", - "sort BufferLines automatically by directory", + "Sort by directory", }, L = { "BufferOrderByLanguage", - "sort BufferLines automatically by language", + "Sort by language", }, }, p = { -- cgit v1.2.3 From 8a168ed8773d8e46b9912a57fdd7ef10303872f1 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Fri, 3 Sep 2021 22:10:48 +0200 Subject: Revert back buffer bindings (#1458) --- lua/core/which-key.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 5ceffb57..458e1634 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -80,10 +80,10 @@ M.config = function() "BufferCloseAllButCurrent", "Close all but current", }, - l = { "BufferCloseBuffersLeft", "Close all - left" }, - r = { + h = { "BufferCloseBuffersLeft", "Close all to the left" }, + l = { "BufferCloseBuffersRight", - "Close all - right", + "Close all to the right", }, D = { "BufferOrderByDirectory", -- cgit v1.2.3 From f82ffdca1fbd7733b42e07b3d68daac4f041985e Mon Sep 17 00:00:00 2001 From: Craig Anderson <1877372+CDA0@users.noreply.github.com> Date: Fri, 3 Sep 2021 21:11:14 +0100 Subject: Add support for bicep (#1451) --- lua/config/defaults.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 9aa60e9a..d60938b8 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -134,6 +134,20 @@ lvim.lang = { }, }, }, + bicep = { + formatters = {}, + linters = {}, + lsp = { + provider = "bicep", + setup = { + cmd = { + "dotnet", + DATA_PATH .. "/lspinstall/bicep/Bicep.LangServer.dll", + }, + filetypes = { "bicep" }, + }, + }, + }, c = { formatters = { -- { -- cgit v1.2.3 From 2fa5c64cd08889a21c677e7bef25260fa2b3b878 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 4 Sep 2021 12:23:00 +0430 Subject: use a separate func instead of replacing the diagnostics messages (#1462) * use a separate func instead of replacing the diagnostics messages * fix the styling, also return if no diagnostic is available --- lua/lsp/handlers.lua | 80 +++++++++++++++++++++++++++++++++++++++++----------- lua/lsp/init.lua | 2 +- 2 files changed, 64 insertions(+), 18 deletions(-) (limited to 'lua') diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index 2322e76a..6d813bd7 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -26,28 +26,11 @@ function M.setup() local diagnostics = params.diagnostics - for i, v in ipairs(diagnostics) do - local source = v.source - if source then - if string.find(source, "/") then - source = string.sub(v.source, string.find(v.source, "([%w-_]+)$")) - end - diagnostics[i].message = string.format("%s: %s", source, v.message) - else - diagnostics[i].message = string.format("%s", v.message) - end - - if vim.tbl_contains(vim.tbl_keys(v), "code") then - diagnostics[i].message = diagnostics[i].message .. string.format(" [%s]", v.code) - end - end - vim.lsp.diagnostic.save(diagnostics, bufnr, client_id) if not vim.api.nvim_buf_is_loaded(bufnr) then return end - vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config) end @@ -60,4 +43,67 @@ function M.setup() }) end +function M.show_line_diagnostics() + local diagnostics = vim.lsp.diagnostic.get_line_diagnostics() + local diags = vim.deepcopy(diagnostics) + local height = #diagnostics + local width = 0 + local opts = {} + local close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" } + local diagnostic_severities = { + "Error", + "Warning", + "Information", + "Hint", + } + if height == 0 then + return + end + local bufnr = vim.api.nvim_create_buf(false, true) + + for i, diagnostic in ipairs(diagnostics) do + local source = diagnostic.source + if source then + if string.find(source, "/") then + source = string.sub(diagnostic.source, string.find(diagnostic.source, "([%w-_]+)$")) + end + diags[i].message = string.format("%s: %s", source, diagnostic.message) + else + diags[i].message = string.format("%s", diagnostic.message) + end + + if diagnostic.code then + diags[i].message = string.format("%s [%s]", diags[i].message, diagnostic.code) + end + if diags[i].message:len() > width then + width = string.len(diags[i].message) + end + end + + opts = vim.lsp.util.make_floating_popup_options(width, height, opts) + opts["style"] = "minimal" + opts["border"] = "rounded" + + vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe") + local winnr = vim.api.nvim_open_win(bufnr, false, opts) + vim.api.nvim_win_set_option(winnr, "winblend", 0) + vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr) + for i, diag in ipairs(diags) do + vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { diag.message }) + vim.api.nvim_buf_add_highlight( + bufnr, + -1, + "LspDiagnosticsFloating" .. diagnostic_severities[diag.severity], + i - 1, + 0, + diag.message:len() + ) + end + + vim.api.nvim_command( + "autocmd QuitPre ++nested ++once lua pcall(vim.api.nvim_win_close, " .. winnr .. ", true)" + ) + vim.lsp.util.close_preview_autocmd(close_events, winnr) +end + return M diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index b43bd419..a734293a 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -48,7 +48,7 @@ local function add_lsp_buffer_keybindings(bufnr) ["gs"] = { "lua vim.lsp.buf.signature_help()", "show signature help" }, ["gp"] = { "lua require'lsp.peek'.Peek('definition')", "Peek definition" }, ["gl"] = { - "lua vim.lsp.diagnostic.show_line_diagnostics({ show_header = false, border = 'single' })", + "lua require'lsp.handlers'.show_line_diagnostics()", "Show line diagnostics", }, } -- cgit v1.2.3 From f7260c6bec370f40144d2a9e6b7464be4e14f9e2 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Sun, 5 Sep 2021 00:01:02 -0400 Subject: fix: storageclass yellow -> cyan --- lua/onedarker/highlights.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/onedarker/highlights.lua b/lua/onedarker/highlights.lua index a178bc52..ef4f2759 100644 --- a/lua/onedarker/highlights.lua +++ b/lua/onedarker/highlights.lua @@ -65,7 +65,7 @@ local highlights = { Function = { fg = C.blue }, Operator = { fg = C.purple }, Type = { fg = C.yellow }, - StorageClass = { fg = C.yellow }, + StorageClass = { fg = C.cyan }, Structure = { fg = C.purple }, Typedef = { fg = C.purple }, Keyword = { fg = C.purple }, -- cgit v1.2.3 From e40182919396dc100630975d68ed879473ec7da4 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 5 Sep 2021 18:33:58 +0430 Subject: [BUGFIX] don't show table address in lualine (#1477) --- lua/core/lualine/components.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index 894d9e9b..3d3ac9af 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -81,9 +81,12 @@ return { }, lsp = { function(msg) - msg = msg or "LSP Inactive" + msg = msg or "LS Inactive" local buf_clients = vim.lsp.buf_get_clients() if next(buf_clients) == nil then + if #msg == 0 then + return "LS Inactive" + end return msg end local buf_ft = vim.bo.filetype -- cgit v1.2.3 From 4371ddbbc7d40734a69c3ba81636cb362fdd391e Mon Sep 17 00:00:00 2001 From: Jakpat Mingmongkolmitr Date: Mon, 6 Sep 2021 00:17:17 +0700 Subject: fix: load nvim_comment setup from core module (#1476) --- lua/plugins.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index 8a0692f2..98721c6c 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -116,7 +116,7 @@ return { "terrortylor/nvim-comment", event = "BufRead", config = function() - require("nvim_comment").setup() + require("core.comment").setup() end, disable = not lvim.builtin.comment.active, }, -- cgit v1.2.3 From cc6685e397a2effa6ea8346a58919d2c38c46293 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Sun, 5 Sep 2021 18:13:23 -0400 Subject: feat: solidity language support with solang --- lua/config/defaults.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index d60938b8..17712e06 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -698,6 +698,16 @@ lvim.lang = { setup = {}, }, }, + solidity = { + formatters = {}, + linters = {}, + lsp = { + provider = "solang", + setup = { + cmd = { "solang", "--language-server" }, + }, + }, + }, sql = { formatters = { -- { -- cgit v1.2.3 From 2ccae0a74657e831c19c13039e7d4bcd201bc78b Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 6 Sep 2021 12:49:00 +0430 Subject: fix `string cannot contain newlines` error while showing diagnostics (#1487) --- lua/lsp/handlers.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index 6d813bd7..ae06116e 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -89,7 +89,8 @@ function M.show_line_diagnostics() vim.api.nvim_win_set_option(winnr, "winblend", 0) vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr) for i, diag in ipairs(diags) do - vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { diag.message }) + local message = diag.message:gsub("[\n\r]", " ") + vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { message }) vim.api.nvim_buf_add_highlight( bufnr, -1, -- cgit v1.2.3 From 129768da1d5903dfe05d4f530548b5e6919a9eb3 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 6 Sep 2021 18:35:12 +0430 Subject: nvim-toggleterm has been renamed to toggleterm Fix #1489 --- lua/plugins.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index 98721c6c..d3f9b3c9 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -183,7 +183,7 @@ return { -- Terminal { - "akinsho/nvim-toggleterm.lua", + "akinsho/toggleterm.lua", event = "BufWinEnter", config = function() require("core.terminal").setup() -- cgit v1.2.3 From a5bd420cb719995b4d46d603ef976065dfb5a772 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 6 Sep 2021 18:36:28 +0430 Subject: toggleterm.nvim not toggleterm.lua :facepalm: --- lua/plugins.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index d3f9b3c9..ef9ae041 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -183,7 +183,7 @@ return { -- Terminal { - "akinsho/toggleterm.lua", + "akinsho/toggleterm.nvim", event = "BufWinEnter", config = function() require("core.terminal").setup() -- cgit v1.2.3 From 5cdd742354c9339a24076d81c33c2620eb5e84ee Mon Sep 17 00:00:00 2001 From: Luong Vo Date: Tue, 7 Sep 2021 00:11:54 +0700 Subject: fix not being able to add linters and formatters to docker (#1486) --- lua/config/defaults.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 17712e06..0f70a281 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -348,7 +348,7 @@ lvim.lang = { }, }, }, - docker = { + dockerfile = { formatters = {}, linters = {}, lsp = { -- cgit v1.2.3 From 151684bba11b702907e58d2acdd41ebc69c27809 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 6 Sep 2021 22:53:41 +0430 Subject: there was a weird situation that caused lualine msg to turn boolean instead of table (#1492) --- lua/core/lualine/components.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index 3d3ac9af..5d240f46 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -84,7 +84,8 @@ return { msg = msg or "LS Inactive" local buf_clients = vim.lsp.buf_get_clients() if next(buf_clients) == nil then - if #msg == 0 then + -- TODO: clean up this if statement + if type(msg) == "boolean" or #msg == 0 then return "LS Inactive" end return msg -- cgit v1.2.3 From 9ece2e5369de46962422837be3dce3b8e889805d Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Tue, 7 Sep 2021 19:23:14 -0400 Subject: feat: compe -> cmp (#1496) --- lua/config/defaults.lua | 16 +++--- lua/core/autopairs.lua | 52 ++++++++++-------- lua/core/builtins/init.lua | 2 +- lua/core/cmp.lua | 123 +++++++++++++++++++++++++++++++++++++++++ lua/core/compe.lua | 133 --------------------------------------------- lua/lsp/init.lua | 6 ++ lua/lsp/kind.lua | 31 +++++++++++ lua/plugins.lua | 44 ++++++--------- 8 files changed, 215 insertions(+), 192 deletions(-) create mode 100644 lua/core/cmp.lua delete mode 100644 lua/core/compe.lua create mode 100644 lua/lsp/kind.lua (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 0f70a281..24455819 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -37,30 +37,30 @@ lvim = { lsp = { completion = { item_kind = { - "  (Text) ", + "  (Text) ", "  (Method)", "  (Function)", "  (Constructor)", - " ﴲ (Field)", - "[] (Variable)", + "  (Field)", + "  (Variable)", "  (Class)", " ﰮ (Interface)", "  (Module)", - " 襁 (Property)", - "  (Unit)", + "  (Property)", + " 塞 (Unit)", "  (Value)", " 練 (Enum)", "  (Keyword)", "  (Snippet)", "  (Color)", - "  (File)", + "  (File)", "  (Reference)", "  (Folder)", "  (EnumMember)", " ﲀ (Constant)", - " ﳤ (Struct)", + "  (Struct)", "  (Event)", - "  (Operator)", + "  (Operator)", "  (TypeParameter)", }, }, diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index 24aa1875..b728cbc1 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -20,36 +20,44 @@ function M.config() end M.setup = function() - -- skip it, if you use another global object - _G.MUtils = {} local autopairs = require "nvim-autopairs" local Rule = require "nvim-autopairs.rule" - - vim.g.completion_confirm_key = "" - MUtils.completion_confirm = function() - if vim.fn.pumvisible() ~= 0 then - if vim.fn.complete_info()["selected"] ~= -1 then - return vim.fn["compe#confirm"](autopairs.esc "") - else - return autopairs.esc "" - end - else - return autopairs.autopairs_cr() - end - end - - if package.loaded["compe"] then - require("nvim-autopairs.completion.compe").setup { - map_cr = lvim.builtin.autopairs.map_cr, - map_complete = lvim.builtin.autopairs.map_complete, - } - end + local cond = require "nvim-autopairs.conds" autopairs.setup { check_ts = lvim.builtin.autopairs.check_ts, ts_config = lvim.builtin.autopairs.ts_config, } + -- vim.g.completion_confirm_key = "" + + autopairs.add_rule(Rule("$$", "$$", "tex")) + autopairs.add_rules { + Rule("$", "$", { "tex", "latex" }) -- don't add a pair if the next character is % + :with_pair(cond.not_after_regex_check "%%") -- don't add a pair if the previous character is xxx + :with_pair(cond.not_before_regex_check("xxx", 3)) -- don't move right when repeat character + :with_move(cond.none()) -- don't delete if the next character is xx + :with_del(cond.not_after_regex_check "xx") -- disable add newline when press + :with_cr(cond.none()), + } + autopairs.add_rules { + Rule("$$", "$$", "tex"):with_pair(function(opts) + print(vim.inspect(opts)) + if opts.line == "aa $$" then + -- don't add pair on that line + return false + end + end), + } + + if package.loaded["cmp"] then + require("nvim-autopairs.completion.cmp").setup { + map_cr = true, -- map on insert mode + map_complete = true, -- it will auto insert `(` after select function or method item + auto_select = true, -- automatically select the first item + } + end + require("nvim-treesitter.configs").setup { autopairs = { enable = true } } local ts_conds = require "nvim-autopairs.ts-conds" diff --git a/lua/core/builtins/init.lua b/lua/core/builtins/init.lua index 32f96af5..dc9b5ff5 100644 --- a/lua/core/builtins/init.lua +++ b/lua/core/builtins/init.lua @@ -4,7 +4,7 @@ local builtins = { "keymappings", "core.which-key", "core.gitsigns", - "core.compe", + "core.cmp", "core.dashboard", "core.dap", "core.terminal", diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua new file mode 100644 index 00000000..7f912544 --- /dev/null +++ b/lua/core/cmp.lua @@ -0,0 +1,123 @@ +local M = {} + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +local function T(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) +end + +local is_emmet_active = function() + local clients = vim.lsp.buf_get_clients() + + for _, client in pairs(clients) do + if client.name == "emmet_ls" then + return true + end + end + return false +end + +M.config = function() + local status_cmp_ok, cmp = pcall(require, "cmp") + if not status_cmp_ok then + return + end + local status_luasnip_ok, luasnip = pcall(require, "luasnip") + if not status_luasnip_ok then + return + end + lvim.builtin.cmp = { + formatting = { + format = function(entry, vim_item) + local icons = require("lsp.kind").icons + vim_item.kind = icons[vim_item.kind] + vim_item.menu = ({ + nvim_lsp = "(LSP)", + emoji = "(Emoji)", + path = "(Path)", + calc = "(Calc)", + cmp_tabnine = "(Tabnine)", + vsnip = "(Snippet)", + luasnip = "(Snippet)", + buffer = "(Buffer)", + })[entry.source.name] + vim_item.dup = ({ + buffer = 1, + path = 1, + nvim_lsp = 0, + })[entry.source.name] or 0 + return vim_item + end, + }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + sources = { + { name = "nvim_lsp" }, + { name = "path" }, + { name = "luasnip" }, + { name = "cmp_tabnine" }, + { name = "nvim_lua" }, + { name = "buffer" }, + { name = "calc" }, + { name = "emoji" }, + { name = "treesitter" }, + { name = "crates" }, + }, + mapping = { + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + -- TODO: potentially fix emmet nonsense + [""] = cmp.mapping(function() + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(T "", "n") + elseif luasnip.expand_or_jumpable() then + vim.fn.feedkeys(T "luasnip-expand-or-jump", "") + elseif check_backspace() then + vim.fn.feedkeys(T "", "n") + elseif is_emmet_active() then + return vim.fn["cmp#complete"]() + else + vim.fn.feedkeys(T "", "n") + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if vim.fn.pumvisible() == 1 then + vim.fn.feedkeys(T "", "n") + elseif luasnip.jumpable(-1) then + vim.fn.feedkeys(T "luasnip-jump-prev", "") + else + fallback() + end + end, { + "i", + "s", + }), + + [""] = cmp.mapping.complete(), + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, + }, + } + + M.setup = function() + require("luasnip/loaders/from_vscode").lazy_load() + require("cmp").setup(lvim.builtin.cmp) + end +end + +return M diff --git a/lua/core/compe.lua b/lua/core/compe.lua deleted file mode 100644 index 9eb3dcfa..00000000 --- a/lua/core/compe.lua +++ /dev/null @@ -1,133 +0,0 @@ -local M = {} - -M.config = function() - lvim.builtin.compe = { - active = true, - on_config_done = nil, - autocomplete = true, - debug = false, - min_length = 1, - preselect = "enable", - throttle_time = 80, - source_timeout = 200, - incomplete_delay = 400, - max_abbr_width = 100, - max_kind_width = 100, - max_menu_width = 100, - documentation = { - border = "single", - winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder", - max_width = 120, - min_width = 60, - max_height = math.floor(vim.o.lines * 0.3), - min_height = 1, - }, - -- documentation = true, - - source = { - path = { kind = "  (Path)" }, - buffer = { kind = "  (Buffer)" }, - calc = { kind = "  (Calc)" }, - vsnip = { kind = "  (Snippet)" }, - nvim_lsp = { kind = "  (LSP)" }, - nvim_lua = false, - spell = { kind = "  (Spell)" }, - tags = false, - vim_dadbod_completion = false, - snippets_nvim = false, - ultisnips = false, - treesitter = false, - emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } }, - -- for emoji press : (idk if that in compe tho) - }, - - keymap = { - values = { - insert_mode = { - -- [""] = { 'pumvisible() ? "" : ""', { silent = true, noremap = true, expr = true } }, - -- [""] = { 'pumvisible() ? "" : ""', { silent = true, noremap = true, expr = true } }, - [""] = { "compe#complete()", { silent = true, noremap = true, expr = true } }, - [""] = { "compe#close('')", { silent = true, noremap = true, expr = true } }, - [""] = { "compe#scroll({ 'delta': +4 })", { silent = true, noremap = true, expr = true } }, - [""] = { "compe#scroll({ 'delta': -4 })", { silent = true, noremap = true, expr = true } }, - }, - }, - opts = { - insert_mode = { noremap = true, silent = true, expr = true }, - }, - }, - } -end - -M.setup = function() - vim.g.vsnip_snippet_dir = lvim.vsnip_dir - - local compe = require "compe" - - compe.setup(lvim.builtin.compe) - - local t = function(str) - return vim.api.nvim_replace_termcodes(str, true, true, true) - end - - local check_back_space = function() - local col = vim.fn.col "." - 1 - if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then - return true - else - return false - end - end - - local is_emmet_active = function() - local clients = vim.lsp.buf_get_clients() - - for _, client in pairs(clients) do - if client.name == "emmet_ls" then - return true - end - end - return false - end - - -- Use (s-)tab to: - --- move to prev/next item in completion menuone - --- jump to prev/next snippet's placeholder - _G.tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#jumpable", { 1 }) == 1 then - return t "(vsnip-jump-next)" - elseif check_back_space() then - return t "" - elseif is_emmet_active() then - return vim.fn["compe#complete"]() - else - return t "" - end - end - - _G.s_tab_complete = function() - if vim.fn.pumvisible() == 1 then - return t "" - elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then - return t "(vsnip-jump-prev)" - else - return t "" - end - end - - local keymap = require "keymappings" - keymap.load(lvim.builtin.compe.keymap.values, lvim.builtin.compe.keymap.opts) - - vim.api.nvim_set_keymap("i", "", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "", "v:lua.tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("i", "", "v:lua.s_tab_complete()", { expr = true }) - vim.api.nvim_set_keymap("s", "", "v:lua.s_tab_complete()", { expr = true }) - - if lvim.builtin.compe.on_config_done then - lvim.builtin.compe.on_config_done(compe) - end -end - -return M diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index a734293a..edac2245 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -65,6 +65,12 @@ function M.common_capabilities() "additionalTextEdits", }, } + + local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") + if not status_ok then + return + end + capabilities = cmp_nvim_lsp.update_capabilities(capabilities) return capabilities end diff --git a/lua/lsp/kind.lua b/lua/lsp/kind.lua new file mode 100644 index 00000000..b78fd318 --- /dev/null +++ b/lua/lsp/kind.lua @@ -0,0 +1,31 @@ +local M = {} + +M.icons = { + Class = " ", + Color = " ", + Constant = "ﲀ ", + Constructor = " ", + Enum = "練", + EnumMember = " ", + Event = " ", + Field = " ", + File = "", + Folder = " ", + Function = " ", + Interface = "ﰮ ", + Keyword = " ", + Method = " ", + Module = " ", + Operator = "", + Property = " ", + Reference = " ", + Snippet = " ", + Struct = " ", + Text = " ", + TypeParameter = " ", + Unit = "塞", + Value = " ", + Variable = " ", +} + +return M diff --git a/lua/plugins.lua b/lua/plugins.lua index ef9ae041..be614c5f 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -24,49 +24,36 @@ return { end, disable = not lvim.builtin.telescope.active, }, - - -- Completion & Snippets + -- Install nvim-cmp, and buffer source as a dependency { - "hrsh7th/nvim-compe", - event = "InsertEnter", + "hrsh7th/nvim-cmp", config = function() - require("core.compe").setup() + require("core.cmp").setup() end, - disable = not lvim.builtin.compe.active, - -- wants = "vim-vsnip", - -- requires = { - -- { - -- "hrsh7th/vim-vsnip", - -- wants = "friendly-snippets", - -- event = "InsertCharPre", - -- }, - -- { - -- "rafamadriz/friendly-snippets", - -- event = "InsertCharPre", - -- }, - -- }, - }, - { - "hrsh7th/vim-vsnip", - -- wants = "friendly-snippets", - event = "InsertEnter", - disable = not lvim.builtin.compe.active, + requires = { + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lua", + }, }, { "rafamadriz/friendly-snippets", - event = "InsertCharPre", - disable = not lvim.builtin.compe.active, + -- event = "InsertCharPre", + -- disable = not lvim.builtin.compe.active, }, -- Autopairs { "windwp/nvim-autopairs", -- event = "InsertEnter", - after = "nvim-compe", + after = "nvim-cmp", config = function() require("core.autopairs").setup() end, - disable = not lvim.builtin.autopairs.active or not lvim.builtin.compe.active, + disable = not lvim.builtin.autopairs.active, }, -- Treesitter @@ -98,6 +85,7 @@ return { require("core.gitsigns").setup() end, event = "BufRead", + commit = "25d4b182ece5b03cd4b2d8c196f3c38e0df58801", disable = not lvim.builtin.gitsigns.active, }, -- cgit v1.2.3 From 8c83b403ef833101a93b53cc232368424b3dff9b Mon Sep 17 00:00:00 2001 From: christianchiarulli Date: Tue, 7 Sep 2021 19:40:40 -0400 Subject: fix: vim.uri bug in 0.6 --- lua/lsp/handlers.lua | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'lua') diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index ae06116e..2efa8d10 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -9,29 +9,43 @@ function M.setup() underline = lvim.lsp.document_highlight, }) - vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _) - local config = { -- your config - virtual_text = lvim.lsp.diagnostics.virtual_text, - signs = lvim.lsp.diagnostics.signs, - underline = lvim.lsp.diagnostics.underline, - update_in_insert = lvim.lsp.diagnostics.update_in_insert, - severity_sort = lvim.lsp.diagnostics.severity_sort, - } - local uri = params.uri - local bufnr = vim.uri_to_bufnr(uri) + local config = { -- your config + virtual_text = lvim.lsp.diagnostics.virtual_text, + signs = lvim.lsp.diagnostics.signs, + underline = lvim.lsp.diagnostics.underline, + update_in_insert = lvim.lsp.diagnostics.update_in_insert, + severity_sort = lvim.lsp.diagnostics.severity_sort, + } + if vim.fn.has "nvim-0.5.1" > 0 then + vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, result, ctx, _) + local uri = result.uri + local bufnr = ctx.bufnr + if not bufnr then + return + end - if not bufnr then - return + local diagnostics = result.diagnostics + vim.lsp.diagnostic.save(diagnostics, ctx.bufnr, ctx.client_id) + if not vim.api.nvim_buf_is_loaded(bufnr) then + return + end + vim.lsp.diagnostic.display(diagnostics, bufnr, ctx.client_id, config) end + else + vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _) + local uri = params.uri + local bufnr = vim.uri_to_bufnr(uri) + if not bufnr then + return + end - local diagnostics = params.diagnostics - - vim.lsp.diagnostic.save(diagnostics, bufnr, client_id) - - if not vim.api.nvim_buf_is_loaded(bufnr) then - return + local diagnostics = params.diagnostics + vim.lsp.diagnostic.save(diagnostics, bufnr, client_id) + if not vim.api.nvim_buf_is_loaded(bufnr) then + return + end + vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config) end - vim.lsp.diagnostic.display(diagnostics, bufnr, client_id, config) end vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { -- cgit v1.2.3 From f338f3577ce0b842f6592cde544ffac37c17c75d Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 8 Sep 2021 16:38:57 +0430 Subject: show correct inline diagnostics in neovim 0.6 (#1502) --- lua/lsp/handlers.lua | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'lua') diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index 2efa8d10..84811581 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -3,12 +3,6 @@ local M = {} function M.setup() - vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, { - virtual_text = lvim.lsp.diagnostics.virtual_text, - signs = lvim.lsp.diagnostics.signs.active, - underline = lvim.lsp.document_highlight, - }) - local config = { -- your config virtual_text = lvim.lsp.diagnostics.virtual_text, signs = lvim.lsp.diagnostics.signs, @@ -19,13 +13,13 @@ function M.setup() if vim.fn.has "nvim-0.5.1" > 0 then vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, result, ctx, _) local uri = result.uri - local bufnr = ctx.bufnr + local bufnr = vim.uri_to_bufnr(uri) if not bufnr then return end local diagnostics = result.diagnostics - vim.lsp.diagnostic.save(diagnostics, ctx.bufnr, ctx.client_id) + vim.lsp.diagnostic.save(diagnostics, bufnr, ctx.client_id) if not vim.api.nvim_buf_is_loaded(bufnr) then return end -- cgit v1.2.3 From 009f004ce844209bec09efadaf768ac736e53c48 Mon Sep 17 00:00:00 2001 From: Chase Colman <5411+chase@users.noreply.github.com> Date: Thu, 9 Sep 2021 00:29:44 +0800 Subject: [Feature] Add modified version of impatient.nvim for caching (#1488) --- lua/impatient.lua | 349 ++++++++++++++++++++++++++++++++++++++++++++ lua/impatient/cachepack.lua | 0 lua/impatient/profile.lua | 145 ++++++++++++++++++ 3 files changed, 494 insertions(+) create mode 100644 lua/impatient.lua create mode 100644 lua/impatient/cachepack.lua create mode 100644 lua/impatient/profile.lua (limited to 'lua') diff --git a/lua/impatient.lua b/lua/impatient.lua new file mode 100644 index 00000000..85d3cb89 --- /dev/null +++ b/lua/impatient.lua @@ -0,0 +1,349 @@ +-- modified version from https://github.com/lewis6991/impatient.nvim + +local vim = vim +local uv = vim.loop +local impatient_start = uv.hrtime() +local api = vim.api +local ffi = require "ffi" + +local get_option, set_option = api.nvim_get_option, api.nvim_set_option +local get_runtime_file = api.nvim_get_runtime_file +local home_dir = uv.os_homedir() + +local impatient_dur + +local M = { + cache = {}, + profile = nil, + dirty = false, + path = home_dir .. "/.local/share/lunarvim/cache", + log = {}, +} + +_G.__luacache = M + +--{{{ +local cachepack = {} + +-- using double for packing/unpacking numbers has no conversion overhead +local c_double = ffi.typeof "double[1]" +local sizeof_c_double = ffi.sizeof "double" + +local out_buf = {} + +function out_buf.write_number(buf, num) + buf[#buf + 1] = ffi.string(c_double(num), sizeof_c_double) +end + +function out_buf.write_string(buf, str) + out_buf.write_number(buf, #str) + buf[#buf + 1] = str +end + +function out_buf.to_string(buf) + return table.concat(buf) +end + +local in_buf = {} + +function in_buf.read_number(buf) + if buf.size < buf.pos then + error "buffer access violation" + end + local res = ffi.cast("double*", buf.ptr + buf.pos)[0] + buf.pos = buf.pos + sizeof_c_double + return res +end + +function in_buf.read_string(buf) + local len = in_buf.read_number(buf) + local res = ffi.string(buf.ptr + buf.pos, len) + buf.pos = buf.pos + len + + return res +end + +function cachepack.pack(cache) + local total_keys = vim.tbl_count(cache) + local buf = {} + + out_buf.write_number(buf, total_keys) + for k, v in pairs(cache) do + out_buf.write_string(buf, k) + out_buf.write_string(buf, v[1] or "") + out_buf.write_number(buf, v[2] or 0) + out_buf.write_string(buf, v[3] or "") + end + + return out_buf.to_string(buf) +end + +function cachepack.unpack(str, raw_buf_size) + if raw_buf_size == 0 or str == nil or (raw_buf_size == nil and #str == 0) then + return {} + end + + local buf = { + ptr = raw_buf_size and str or ffi.new("const char[?]", #str, str), + pos = 0, + size = raw_buf_size or #str, + } + local cache = {} + + local total_keys = in_buf.read_number(buf) + for _ = 1, total_keys do + local k = in_buf.read_string(buf) + local v = { + in_buf.read_string(buf), + in_buf.read_number(buf), + in_buf.read_string(buf), + } + cache[k] = v + end + + return cache +end +--}}} + +local function log(...) + M.log[#M.log + 1] = table.concat({ string.format(...) }, " ") +end + +function M.print_log() + for _, l in ipairs(M.log) do + print(l) + end +end + +function M.enable_profile() + M.profile = {} + M.print_profile = function() + M.profile["impatient"] = { + resolve = 0, + load = impatient_dur, + loader = "standard", + } + require("impatient.profile").print_profile(M.profile) + end + vim.cmd [[command! LuaCacheProfile lua _G.__luacache.print_profile()]] +end + +local function is_cacheable(path) + -- Don't cache files in /tmp since they are not likely to persist. + -- Note: Appimage versions of Neovim mount $VIMRUNTIME in /tmp in a unique + -- directory on each launch. + return not vim.startswith(path, "/tmp/") +end + +local function hash(modpath) + local stat = uv.fs_stat(modpath) + if stat then + return stat.mtime.sec + end +end + +local function hrtime() + if M.profile then + return uv.hrtime() + end +end + +local function load_package_with_cache(name, loader) + local resolve_start = hrtime() + + local basename = name:gsub("%.", "/") + local paths = { "lua/" .. basename .. ".lua", "lua/" .. basename .. "/init.lua" } + + for _, path in ipairs(paths) do + local modpath = get_runtime_file(path, false)[1] + if modpath then + local load_start = hrtime() + local chunk, err = loadfile(modpath) + + if M.profile then + M.profile[name] = { + resolve = load_start - resolve_start, + load = hrtime() - load_start, + loader = loader or "standard", + } + end + + if chunk == nil then + return err + end + + if is_cacheable(modpath) then + log("Creating cache for module %s", name) + M.cache[name] = { modpath, hash(modpath), string.dump(chunk) } + M.dirty = true + else + log("Unable to cache module %s", name) + end + + return chunk + end + end + return nil +end + +local reduced_rtp + +-- Speed up non-cached loads by reducing the rtp path during requires +function M.update_reduced_rtp() + local luadirs = get_runtime_file("lua/", true) + + for i = 1, #luadirs do + luadirs[i] = luadirs[i]:sub(1, -6) + end + + reduced_rtp = table.concat(luadirs, ",") +end + +local function load_package_with_cache_reduced_rtp(name) + local orig_rtp = get_option "runtimepath" + local orig_ei = get_option "eventignore" + + if not reduced_rtp then + M.update_reduced_rtp() + end + + set_option("eventignore", "all") + set_option("rtp", reduced_rtp) + + local found = load_package_with_cache(name, "reduced") + + set_option("rtp", orig_rtp) + set_option("eventignore", orig_ei) + + return found +end + +local function load_from_cache(name) + local resolve_start = hrtime() + if M.cache[name] == nil then + log("No cache for module %s", name) + return "No cache entry" + end + + local modpath, mhash, codes = unpack(M.cache[name]) + + if mhash ~= hash(modpath) then + log("Stale cache for module %s", name) + M.cache[name] = nil + M.dirty = true + return "Stale cache" + end + + local load_start = hrtime() + local chunk = loadstring(codes) + + if M.profile then + M.profile[name] = { + resolve = load_start - resolve_start, + load = hrtime() - load_start, + loader = "cache", + } + end + + if not chunk then + M.cache[name] = nil + M.dirty = true + log("Error loading cache for module. Invalidating", name) + return "Cache error" + end + + return chunk +end + +function M.save_cache() + if M.dirty then + log("Updating cache file: %s", M.path) + local f = io.open(M.path, "w+b") + f:write(cachepack.pack(M.cache)) + f:flush() + M.dirty = false + end +end + +function M.clear_cache() + M.cache = {} + os.remove(M.path) +end + +local function setup() + local stat = uv.fs_stat(M.path) + if stat then + log("Loading cache file %s", M.path) + local ok + -- Linux/macOS lets us easily mmap the cache file for faster reads without passing to Lua + if jit.os == "Linux" or jit.os == "OSX" then + local size = stat.size + + local C = ffi.C + local O_RDONLY = 0x00 + local PROT_READ = 0x01 + local MAP_PRIVATE = 0x02 + + ffi.cdef [[ + int open(const char *pathname, int flags); + int close(int fd); + void *mmap(void *addr, size_t length, int prot, int flags, int fd, long int offset); + int munmap(void *addr, size_t length); + ]] + local f = C.open(M.path, O_RDONLY) + + local addr = C.mmap(nil, size, PROT_READ, MAP_PRIVATE, f, 0) + ok = ffi.cast("intptr_t", addr) ~= -1 + + if ok then + M.cache = cachepack.unpack(ffi.cast("char *", addr), size) + C.munmap(addr, size) + end + + C.close(f) + else + local f = io.open(M.path, "rb") + ok, M.cache = pcall(function() + return cachepack.unpack(f:read "*a") + end) + end + + if not ok then + log("Corrupted cache file, %s. Invalidating...", M.path) + os.remove(M.path) + M.cache = {} + end + M.dirty = not ok + end + + local insert = table.insert + local package = package + + -- Fix the position of the preloader. This also makes loading modules like 'ffi' + -- and 'bit' quicker + if package.loaders[1] == vim._load_package then + -- Move vim._load_package to the second position + local vim_load = table.remove(package.loaders, 1) + insert(package.loaders, 2, vim_load) + end + + insert(package.loaders, 2, load_from_cache) + insert(package.loaders, 3, load_package_with_cache_reduced_rtp) + insert(package.loaders, 4, load_package_with_cache) + + vim.cmd [[ + augroup impatient + autocmd VimEnter,VimLeave * lua _G.__luacache.save_cache() + autocmd OptionSet runtimepath lua _G.__luacache.update_reduced_rtp(true) + augroup END + + command! LuaCacheClear lua _G.__luacache.clear_cache() + command! LuaCacheLog lua _G.__luacache.print_log() + ]] +end + +setup() + +impatient_dur = uv.hrtime() - impatient_start + +return M diff --git a/lua/impatient/cachepack.lua b/lua/impatient/cachepack.lua new file mode 100644 index 00000000..e69de29b diff --git a/lua/impatient/profile.lua b/lua/impatient/profile.lua new file mode 100644 index 00000000..0f4f8236 --- /dev/null +++ b/lua/impatient/profile.lua @@ -0,0 +1,145 @@ +local M = {} + +local api = vim.api + +function M.print_profile(profile) + if not profile then + print "Error: profiling was not enabled" + return + end + + local total_resolve = 0 + local total_load = 0 + local name_pad = 0 + local modules = {} + local plugins = {} + + for module, p in pairs(profile) do + p.resolve = p.resolve / 1000000 + p.load = p.load / 1000000 + p.total = p.resolve + p.load + p.module = module:gsub("/", ".") + + local plugin = p.module:match "([^.]+)" + if plugin then + if not plugins[plugin] then + plugins[plugin] = { + module = plugin, + resolve = 0, + load = 0, + total = 0, + } + end + local r = plugins[plugin] + + r.resolve = r.resolve + p.resolve + r.load = r.load + p.load + r.total = r.total + p.total + + if not r.loader then + r.loader = p.loader + elseif r.loader ~= p.loader then + r.loader = "mixed" + end + end + + total_resolve = total_resolve + p.resolve + total_load = total_load + p.load + + if #module > name_pad then + name_pad = #module + end + + modules[#modules + 1] = p + end + + table.sort(modules, function(a, b) + return a.module > b.module + end) + + do + local plugins_a = {} + for _, v in pairs(plugins) do + plugins_a[#plugins_a + 1] = v + end + plugins = plugins_a + end + + table.sort(plugins, function(a, b) + return a.total > b.total + end) + + local lines = {} + local function add(...) + lines[#lines + 1] = string.format(...) + end + + local l = string.rep("─", name_pad + 1) + + add( + "%s┬───────────┬────────────┬────────────┬────────────┐", + l + ) + add("%-" .. name_pad .. "s │ Loader │ Resolve │ Load │ Total │", "") + add( + "%s┼───────────┼────────────┼────────────┼────────────┤", + l + ) + add( + "%-" .. name_pad .. "s │ │ %8.4fms │ %8.4fms │ %8.4fms │", + "Total", + total_resolve, + total_load, + total_resolve + total_load + ) + add( + "%s┴───────────┴────────────┴────────────┴────────────┤", + l + ) + add("%-" .. name_pad .. "s │", "By Plugin") + add( + "%s┬───────────┬────────────┬────────────┬────────────┤", + l + ) + for _, p in ipairs(plugins) do + add( + "%-" .. name_pad .. "s │ %9s │ %8.4fms │ %8.4fms │ %8.4fms │", + p.module, + p.loader, + p.resolve, + p.load, + p.total + ) + end + add( + "%s┴───────────┴────────────┴────────────┴────────────┤", + l + ) + add("%-" .. name_pad .. "s │", "By Module") + add( + "%s┬───────────┬────────────┬────────────┬────────────┤", + l + ) + for _, p in pairs(modules) do + add( + "%-" .. name_pad .. "s │ %9s │ %8.4fms │ %8.4fms │ %8.4fms │", + p.module, + p.loader, + p.resolve, + p.load, + p.total + ) + end + add( + "%s┴───────────┴────────────┴────────────┴────────────┘", + l + ) + + local bufnr = api.nvim_create_buf(false, false) + api.nvim_buf_set_lines(bufnr, 0, 0, false, lines) + api.nvim_buf_set_option(bufnr, "buftype", "nofile") + api.nvim_buf_set_name(bufnr, "Impatient Profile Report") + api.nvim_set_current_buf(bufnr) +end + +return M -- cgit v1.2.3 From 6974e109c67e28284ca7f12614bb16655288bd16 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Thu, 9 Sep 2021 05:12:17 +0430 Subject: feature: unpin gitsigns to use the latest bugfix commits on their repo (#1509) --- lua/plugins.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index be614c5f..ae20fc93 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -85,7 +85,6 @@ return { require("core.gitsigns").setup() end, event = "BufRead", - commit = "25d4b182ece5b03cd4b2d8c196f3c38e0df58801", disable = not lvim.builtin.gitsigns.active, }, -- cgit v1.2.3 From 08345170081b5882535eaf32406a9c0e1b0a6f56 Mon Sep 17 00:00:00 2001 From: luetage Date: Thu, 9 Sep 2021 02:43:30 +0200 Subject: Show treesitter icon only with supported filetype (#1512) --- lua/core/lualine/components.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index 5d240f46..c6800f49 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -71,7 +71,8 @@ return { }, treesitter = { function() - if next(vim.treesitter.highlighter.active) then + local b = vim.api.nvim_get_current_buf() + if next(vim.treesitter.highlighter.active[b]) then return "  " end return "" -- cgit v1.2.3 From ac32f2e64d61291ba4969599827eef515712d5d8 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Thu, 9 Sep 2021 09:25:12 -0400 Subject: fix: move setup function outside of config function --- lua/core/cmp.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua index 7f912544..acfb05ae 100644 --- a/lua/core/cmp.lua +++ b/lua/core/cmp.lua @@ -113,11 +113,11 @@ M.config = function() }, }, } +end - M.setup = function() - require("luasnip/loaders/from_vscode").lazy_load() - require("cmp").setup(lvim.builtin.cmp) - end +M.setup = function() + require("luasnip/loaders/from_vscode").lazy_load() + require("cmp").setup(lvim.builtin.cmp) end return M -- cgit v1.2.3 From 23f535666ee5ce2690f823bb2cb88b843d329763 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Fri, 10 Sep 2021 13:16:23 +0430 Subject: bugfix: remove double quotes from scala config --- lua/config/defaults.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 24455819..75df99c3 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -916,7 +916,7 @@ lvim.lang = { -- args = {}, -- }, }, - linters = { "" }, + linters = {}, lsp = { provider = "metals", setup = {}, -- cgit v1.2.3 From 7a53fc63e083c0c48d8de361d82736f844c3c14a Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 12 Sep 2021 08:06:03 +0200 Subject: refactor: add 32bit support for impatient (#1527) --- lua/impatient.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lua') diff --git a/lua/impatient.lua b/lua/impatient.lua index 85d3cb89..4bb83fb6 100644 --- a/lua/impatient.lua +++ b/lua/impatient.lua @@ -26,13 +26,17 @@ _G.__luacache = M local cachepack = {} -- using double for packing/unpacking numbers has no conversion overhead -local c_double = ffi.typeof "double[1]" -local sizeof_c_double = ffi.sizeof "double" +-- 32-bit ARM causes a bus error when casting to double, so use int there +local number_t = jit.arch ~= "arm" and "double" or "int" +ffi.cdef("typedef " .. number_t .. " number_t;") + +local c_number_t = ffi.typeof "number_t[1]" +local c_sizeof_number_t = ffi.sizeof "number_t" local out_buf = {} function out_buf.write_number(buf, num) - buf[#buf + 1] = ffi.string(c_double(num), sizeof_c_double) + buf[#buf + 1] = ffi.string(c_number_t(num), c_sizeof_number_t) end function out_buf.write_string(buf, str) @@ -50,8 +54,8 @@ function in_buf.read_number(buf) if buf.size < buf.pos then error "buffer access violation" end - local res = ffi.cast("double*", buf.ptr + buf.pos)[0] - buf.pos = buf.pos + sizeof_c_double + local res = ffi.cast("number_t*", buf.ptr + buf.pos)[0] + buf.pos = buf.pos + c_sizeof_number_t return res end -- cgit v1.2.3 From ad86b1920426577ca2d0e6d56c309a190455c14f Mon Sep 17 00:00:00 2001 From: Chase Colman <5411+chase@users.noreply.github.com> Date: Sun, 12 Sep 2021 14:15:29 +0800 Subject: refactor: add explicit setup for impatient (#1529) Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/impatient.lua | 23 +++++++++++++++-------- lua/impatient/cachepack.lua | 0 2 files changed, 15 insertions(+), 8 deletions(-) delete mode 100644 lua/impatient/cachepack.lua (limited to 'lua') diff --git a/lua/impatient.lua b/lua/impatient.lua index 4bb83fb6..ea1369fb 100644 --- a/lua/impatient.lua +++ b/lua/impatient.lua @@ -2,13 +2,12 @@ local vim = vim local uv = vim.loop -local impatient_start = uv.hrtime() +local impatient_load_start = uv.hrtime() local api = vim.api local ffi = require "ffi" local get_option, set_option = api.nvim_get_option, api.nvim_set_option local get_runtime_file = api.nvim_get_runtime_file -local home_dir = uv.os_homedir() local impatient_dur @@ -16,7 +15,7 @@ local M = { cache = {}, profile = nil, dirty = false, - path = home_dir .. "/.local/share/lunarvim/cache", + path = nil, log = {}, } @@ -274,7 +273,17 @@ function M.clear_cache() os.remove(M.path) end -local function setup() +impatient_dur = uv.hrtime() - impatient_load_start + +function M.setup(opts) + opts = opts or {} + M.path = opts.path or vim.fn.stdpath "cache" .. "/luacache" + + if opts.enable_profiling then + M.enable_profile() + end + + local impatient_setup_start = uv.hrtime() local stat = uv.fs_stat(M.path) if stat then log("Loading cache file %s", M.path) @@ -344,10 +353,8 @@ local function setup() command! LuaCacheClear lua _G.__luacache.clear_cache() command! LuaCacheLog lua _G.__luacache.print_log() ]] -end - -setup() -impatient_dur = uv.hrtime() - impatient_start + impatient_dur = impatient_dur + (uv.hrtime() - impatient_setup_start) +end return M diff --git a/lua/impatient/cachepack.lua b/lua/impatient/cachepack.lua deleted file mode 100644 index e69de29b..00000000 -- cgit v1.2.3 From e93c6abab7d9fb3885cb53310d840204ff6ffc01 Mon Sep 17 00:00:00 2001 From: Chase Colman <5411+chase@users.noreply.github.com> Date: Mon, 13 Sep 2021 13:47:25 +0800 Subject: Fix loading cmp config after Packer install (#1524) --- lua/plugins.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index ae20fc93..178fb99e 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -38,6 +38,12 @@ return { "hrsh7th/cmp-path", "hrsh7th/cmp-nvim-lua", }, + run = function() + -- cmp's config requires cmp to be installed to run the first time + if not lvim.builtin.cmp then + require("core.cmp").config() + end + end, }, { "rafamadriz/friendly-snippets", -- cgit v1.2.3 From 38b0c3d860d10515002fdb27db7e1187ce110b1d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:10:22 +0200 Subject: fix: remove unused variables (#1532) --- lua/config/defaults.lua | 2 -- lua/config/settings.lua | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index 75df99c3..d70d78c5 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -2,8 +2,6 @@ local home_dir = vim.loop.os_homedir() CONFIG_PATH = home_dir .. "/.local/share/lunarvim/lvim" DATA_PATH = vim.fn.stdpath "data" CACHE_PATH = vim.fn.stdpath "cache" -TERMINAL = vim.fn.expand "$TERMINAL" -USER = vim.fn.expand "$USER" vim.cmd [[ set spellfile=~/.config/lvim/spell/en.utf-8.add ]] lvim = { diff --git a/lua/config/settings.lua b/lua/config/settings.lua index ba71a922..36e31193 100644 --- a/lua/config/settings.lua +++ b/lua/config/settings.lua @@ -45,7 +45,7 @@ M.load_options = function() spelllang = "en", scrolloff = 8, -- is one of my fav sidescrolloff = 8, - } --- VIM ONLY COMMANDS ---cmd "filetype plugin on"cmd('let &titleold="' .. TERMINAL .. '"')cmd "set inccommand=split"cmd "set iskeyword+=-" + } --- SETTINGS --- -- cgit v1.2.3 From 8eed75d67f9cbcefb91c4cb5aac0ffd013be25cc Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:28:15 +0200 Subject: refactor: use more flexible paths (#1381) --- lua/bootstrap.lua | 82 ++++++++++++++++++++++++++++++++++++++++++ lua/config/defaults.lua | 96 ++++++++++++++++++++++++------------------------- lua/config/init.lua | 21 ++++++----- lua/config/settings.lua | 4 +-- lua/core/dashboard.lua | 13 ++----- lua/core/project.lua | 2 +- lua/core/telescope.lua | 6 ++-- lua/core/terminal.lua | 2 +- lua/core/which-key.lua | 2 +- lua/lsp/init.lua | 35 ++++++++++++------ lua/plugin-loader.lua | 26 +++++++------- lua/utils/init.lua | 8 ++++- 12 files changed, 194 insertions(+), 103 deletions(-) create mode 100644 lua/bootstrap.lua (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua new file mode 100644 index 00000000..a03440d9 --- /dev/null +++ b/lua/bootstrap.lua @@ -0,0 +1,82 @@ +local M = {} +-- It's not safe to require 'utils' without adjusting the runtimepath +function _G.join_paths(...) + local uv = vim.loop + local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/" + local result = table.concat({ ... }, path_sep) + return result +end + +function _G.get_runtime_dir() + local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" + if not lvim_runtime_dir then + -- when nvim is used directly + return vim.fn.stdpath "config" + end + return lvim_runtime_dir +end + +function _G.get_config_dir() + local lvim_config_dir = os.getenv "LUNARVIM_CONFIG_DIR" + if not lvim_config_dir then + return vim.fn.stdpath "config" + end + return lvim_config_dir +end + +function _G.get_cache_dir() + local lvim_cache_dir = os.getenv "LUNARVIM_CACHE_DIR" + if not lvim_cache_dir then + return vim.fn.stdpath "cache" + end + return lvim_cache_dir +end + +function M:init() + self.runtime_dir = get_runtime_dir() + self.config_dir = get_config_dir() + self.cache_path = get_cache_dir() + + self.pack_dir = join_paths(self.runtime_dir, "site", "pack") + + if os.getenv "LUNARVIM_RUNTIME_DIR" then + vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site")) + vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site", "after")) + vim.opt.rtp:prepend(join_paths(self.runtime_dir, "site")) + vim.opt.rtp:append(join_paths(self.runtime_dir, "site", "after")) + + vim.opt.rtp:remove(vim.fn.stdpath "config") + vim.opt.rtp:remove(join_paths(vim.fn.stdpath "config", "after")) + vim.opt.rtp:prepend(self.config_dir) + vim.opt.rtp:append(join_paths(self.config_dir, "after")) + -- TODO: we need something like this: vim.opt.packpath = vim.opt.rtp + + vim.cmd [[let &packpath = &runtimepath]] + vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add")) + end + + -- FIXME: currently unreliable in unit-tests + if not os.getenv "LVIM_TEST_ENV" then + require("impatient").setup { + path = vim.fn.stdpath "cache" .. "/lvim_cache", + enable_profiling = true, + } + end + + local config = require "config" + config:init { + path = join_paths(self.config_dir, "config.lua"), + } + + require("plugin-loader"):init { + cache_path = self.cache_path, + runtime_dir = self.runtime_dir, + config_dir = self.config_dir, + package_root = join_paths(self.runtime_dir, "site", "pack"), + compile_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua"), + } + + return self +end + +return M diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index d70d78c5..a4ef7125 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -1,8 +1,7 @@ local home_dir = vim.loop.os_homedir() -CONFIG_PATH = home_dir .. "/.local/share/lunarvim/lvim" -DATA_PATH = vim.fn.stdpath "data" -CACHE_PATH = vim.fn.stdpath "cache" -vim.cmd [[ set spellfile=~/.config/lvim/spell/en.utf-8.add ]] +local utils = require "utils" +-- FIXME: stop using hard-coded paths for LspInstall +local ls_install_prefix = vim.fn.stdpath "data" .. "/lspinstall" lvim = { leader = "space", @@ -10,8 +9,8 @@ lvim = { line_wrap_cursor_movement = true, transparent_window = false, format_on_save = true, - vsnip_dir = home_dir .. "/.config/snippets", - database = { save_location = "~/.config/lunarvim_db", auto_execute = 1 }, + vsnip_dir = utils.join_paths(home_dir, ".config", "snippets"), + database = { save_location = utils.join_paths(home_dir, ".config", "lunarvim_db"), auto_execute = 1 }, keys = {}, builtin = {}, @@ -140,7 +139,7 @@ lvim.lang = { setup = { cmd = { "dotnet", - DATA_PATH .. "/lspinstall/bicep/Bicep.LangServer.dll", + ls_install_prefix .. "/bicep/Bicep.LangServer.dll", }, filetypes = { "bicep" }, }, @@ -162,7 +161,7 @@ lvim.lang = { provider = "clangd", setup = { cmd = { - DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", + ls_install_prefix .. "/cpp/clangd/bin/clangd", "--background-index", "--header-insertion=never", "--cross-file-rename", @@ -188,7 +187,7 @@ lvim.lang = { provider = "clangd", setup = { cmd = { - DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", + ls_install_prefix .. "/cpp/clangd/bin/clangd", "--background-index", "--header-insertion=never", "--cross-file-rename", @@ -229,7 +228,7 @@ lvim.lang = { provider = "omnisharp", setup = { cmd = { - DATA_PATH .. "/lspinstall/csharp/omnisharp/run", + ls_install_prefix .. "/csharp/omnisharp/run", "--languageserver", "--hostPID", tostring(vim.fn.getpid()), @@ -249,7 +248,7 @@ lvim.lang = { provider = "cmake", setup = { cmd = { - DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server", + ls_install_prefix .. "/cmake/venv/bin/cmake-language-server", }, }, }, @@ -261,7 +260,7 @@ lvim.lang = { provider = "clojure_lsp", setup = { cmd = { - DATA_PATH .. "/lspinstall/clojure/clojure-lsp", + ls_install_prefix .. "/clojure/clojure-lsp", }, }, }, @@ -283,7 +282,7 @@ lvim.lang = { setup = { cmd = { "node", - DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", + ls_install_prefix .. "/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", "--stdio", }, }, @@ -306,7 +305,7 @@ lvim.lang = { setup = { cmd = { "node", - DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", + ls_install_prefix .. "/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", "--stdio", }, }, @@ -353,7 +352,7 @@ lvim.lang = { provider = "dockerls", setup = { cmd = { - DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver", + ls_install_prefix .. "/dockerfile/node_modules/.bin/docker-langserver", "--stdio", }, }, @@ -371,7 +370,7 @@ lvim.lang = { provider = "elixirls", setup = { cmd = { - DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh", + ls_install_prefix .. "/elixir/elixir-ls/language_server.sh", }, }, }, @@ -388,13 +387,13 @@ lvim.lang = { provider = "elmls", setup = { cmd = { - DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-language-server", + ls_install_prefix .. "/elm/node_modules/.bin/elm-language-server", }, -- init_options = { -- elmAnalyseTrigger = "change", - -- elmFormatPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-format", - -- elmPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/", - -- elmTestPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-test", + -- elmFormatPath = ls_install_prefix .. "/elm/node_modules/.bin/elm-format", + -- elmPath = ls_install_prefix .. "/elm/node_modules/.bin/", + -- elmTestPath = ls_install_prefix .. "/elm/node_modules/.bin/elm-test", -- }, }, }, @@ -437,7 +436,7 @@ lvim.lang = { provider = "fortls", setup = { cmd = { - DATA_PATH .. "/lspinstall/fortran/venv/bin/fortls", + ls_install_prefix .. "/fortran/venv/bin/fortls", }, }, }, @@ -462,7 +461,7 @@ lvim.lang = { provider = "gopls", setup = { cmd = { - DATA_PATH .. "/lspinstall/go/gopls", + ls_install_prefix .. "/go/gopls", }, }, }, @@ -488,7 +487,7 @@ lvim.lang = { lsp = { provider = "hls", setup = { - cmd = { DATA_PATH .. "/lspinstall/haskell/hls" }, + cmd = { ls_install_prefix .. "/haskell/hls" }, }, }, }, @@ -509,7 +508,7 @@ lvim.lang = { setup = { cmd = { "node", - DATA_PATH .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js", + ls_install_prefix .. "/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js", "--stdio", }, }, @@ -530,7 +529,7 @@ lvim.lang = { lsp = { provider = "jdtls", setup = { - cmd = { DATA_PATH .. "/lspinstall/java/jdtls.sh" }, + cmd = { ls_install_prefix .. "/java/jdtls.sh" }, }, }, }, @@ -555,7 +554,7 @@ lvim.lang = { setup = { cmd = { "node", - DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", + ls_install_prefix .. "/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", "--stdio", }, settings = { @@ -589,8 +588,7 @@ lvim.lang = { "julia", "--startup-file=no", "--history-file=no", - -- vim.fn.expand "~/.config/nvim/lua/lsp/julia/run.jl", - CONFIG_PATH .. "/utils/julia/run.jl", + -- self.runtime_dir .. "lvim/utils/julia/run.jl", }, }, }, @@ -602,7 +600,7 @@ lvim.lang = { provider = "kotlin_language_server", setup = { cmd = { - DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server", + ls_install_prefix .. "/kotlin/server/bin/kotlin-language-server", }, root_dir = function(fname) local util = require "lspconfig/util" @@ -639,9 +637,9 @@ lvim.lang = { provider = "sumneko_lua", setup = { cmd = { - DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server", + ls_install_prefix .. "/lua/sumneko-lua-language-server", "-E", - DATA_PATH .. "/lspinstall/lua/main.lua", + ls_install_prefix .. "/lua/main.lua", }, settings = { Lua = { @@ -658,7 +656,7 @@ lvim.lang = { workspace = { -- Make the server aware of Neovim runtime files library = { - [vim.fn.expand "~/.local/share/lunarvim/lvim/lua"] = true, + [require("utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true, [vim.fn.expand "$VIMRUNTIME/lua"] = true, [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, }, @@ -733,7 +731,7 @@ lvim.lang = { provider = "intelephense", setup = { cmd = { - DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", + ls_install_prefix .. "/php/node_modules/.bin/intelephense", "--stdio", }, filetypes = { "php", "phtml" }, @@ -754,7 +752,7 @@ lvim.lang = { provider = "puppet", setup = { cmd = { - DATA_PATH .. "/lspinstall/puppet/puppet-editor-services/puppet-languageserver", + ls_install_prefix .. "/puppet/puppet-editor-services/puppet-languageserver", "--stdio", }, }, @@ -782,7 +780,7 @@ lvim.lang = { setup = { cmd = { -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, }, @@ -809,7 +807,7 @@ lvim.lang = { setup = { cmd = { -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, }, @@ -831,7 +829,7 @@ lvim.lang = { provider = "pyright", setup = { cmd = { - DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", + ls_install_prefix .. "/python/node_modules/.bin/pyright-langserver", "--stdio", }, }, @@ -871,7 +869,7 @@ lvim.lang = { provider = "solargraph", setup = { cmd = { - DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", + ls_install_prefix .. "/ruby/solargraph/solargraph", "stdio", }, filetypes = { "ruby" }, @@ -902,7 +900,7 @@ lvim.lang = { provider = "rust_analyzer", setup = { cmd = { - DATA_PATH .. "/lspinstall/rust/rust-analyzer", + ls_install_prefix .. "/rust/rust-analyzer", }, }, }, @@ -932,7 +930,7 @@ lvim.lang = { provider = "bashls", setup = { cmd = { - DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", + ls_install_prefix .. "/bash/node_modules/.bin/bash-language-server", "start", }, }, @@ -945,7 +943,7 @@ lvim.lang = { provider = "svelte", setup = { cmd = { - DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", + ls_install_prefix .. "/svelte/node_modules/.bin/svelteserver", "--stdio", }, }, @@ -975,7 +973,7 @@ lvim.lang = { provider = "tailwindcss", setup = { cmd = { - DATA_PATH .. "/lspinstall/tailwindcss/node_modules/.bin/tailwindcss-language-server", + ls_install_prefix .. "/tailwindcss/node_modules/.bin/tailwindcss-language-server", "--stdio", }, }, @@ -993,7 +991,7 @@ lvim.lang = { provider = "terraformls", setup = { cmd = { - DATA_PATH .. "/lspinstall/terraform/terraform-ls", + ls_install_prefix .. "/terraform/terraform-ls", "serve", }, }, @@ -1005,7 +1003,7 @@ lvim.lang = { lsp = { provider = "texlab", setup = { - cmd = { DATA_PATH .. "/lspinstall/latex/texlab" }, + cmd = { ls_install_prefix .. "/latex/texlab" }, }, }, }, @@ -1030,7 +1028,7 @@ lvim.lang = { setup = { cmd = { -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, }, @@ -1058,7 +1056,7 @@ lvim.lang = { setup = { cmd = { -- TODO: - DATA_PATH .. "/lspinstall/typescript/node_modules/.bin/typescript-language-server", + ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", "--stdio", }, }, @@ -1071,7 +1069,7 @@ lvim.lang = { provider = "vimls", setup = { cmd = { - DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server", + ls_install_prefix .. "/vim/node_modules/.bin/vim-language-server", "--stdio", }, }, @@ -1097,7 +1095,7 @@ lvim.lang = { provider = "vuels", setup = { cmd = { - DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", + ls_install_prefix .. "/vue/node_modules/.bin/vls", }, root_dir = function(fname) local util = require "lspconfig/util" @@ -1139,7 +1137,7 @@ lvim.lang = { provider = "yamlls", setup = { cmd = { - DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server", + ls_install_prefix .. "/yaml/node_modules/.bin/yaml-language-server", "--stdio", }, }, diff --git a/lua/config/init.lua b/lua/config/init.lua index 332460d3..c09617bc 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -1,21 +1,14 @@ -local home_dir = vim.loop.os_homedir() -local M = { - path = string.format("%s/.config/lvim/config.lua", home_dir), -} +local M = {} --- Initialize lvim default configuration -- Define lvim global variable -function M:init() +function M:init(opts) + opts = opts or {} + self.path = opts.path local utils = require "utils" require "config.defaults" - local builtins = require "core.builtins" - builtins.config(self) - - local settings = require "config.settings" - settings.load_options() - -- Fallback config.lua to lv-config.lua if not utils.is_file(self.path) then local lv_config = self.path:gsub("config.lua$", "lv-config.lua") @@ -23,6 +16,12 @@ function M:init() self.path = lv_config end + + local builtins = require "core.builtins" + builtins.config(self) + + local settings = require "config.settings" + settings.load_options() end --- Override the configuration with a user provided one diff --git a/lua/config/settings.lua b/lua/config/settings.lua index 36e31193..90042c4f 100644 --- a/lua/config/settings.lua +++ b/lua/config/settings.lua @@ -1,5 +1,5 @@ local M = {} - +local utils = require "utils" M.load_options = function() local default_options = { backup = false, -- creates a backup file @@ -28,7 +28,7 @@ M.load_options = function() timeoutlen = 100, -- time to wait for a mapped sequence to complete (in milliseconds) title = true, -- set the title of window to the value of the titlestring -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to - undodir = CACHE_PATH .. "/undo", -- set an undo directory + undodir = utils.join_paths(get_cache_dir(), "undo"), -- set an undo directory undofile = true, -- enable persistent undo updatetime = 300, -- faster completion writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index a613921f..aa2a7f35 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -1,5 +1,5 @@ local M = {} -local home_dir = vim.loop.os_homedir() +local utils = require "utils" M.config = function(config) lvim.builtin.dashboard = { @@ -7,7 +7,7 @@ M.config = function(config) on_config_done = nil, search_handler = "telescope", disable_at_vim_enter = 0, - session_directory = home_dir .. "/.cache/lvim/sessions", + session_directory = utils.join_paths(get_cache_dir(), "sessions"), custom_header = { "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", "⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⣾⠿⠿⠟⠛⠛⠛⠛⠿⠿⣿⣷⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", @@ -69,15 +69,6 @@ M.setup = function() vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory - vim.cmd "let packages = len(globpath('~/.local/share/lunarvim/site/pack/packer/start', '*', 0, 1))" - - vim.api.nvim_exec( - [[ - let g:dashboard_custom_footer = ['LunarVim loaded '..packages..' plugins  '] -]], - false - ) - require("core.autocmds").define_augroups { _dashboard = { -- seems to be nobuflisted that makes my stuff disappear will do more testing diff --git a/lua/core/project.lua b/lua/core/project.lua index 7fb04933..e7527440 100644 --- a/lua/core/project.lua +++ b/lua/core/project.lua @@ -35,7 +35,7 @@ function M.config() ---@type string ---@usage path to store the project history for use in telescope - datapath = CACHE_PATH, + datapath = get_cache_dir(), } end diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 4ae56df0..34c1fb92 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -1,5 +1,7 @@ local M = {} +local utils = require "utils" + function M.config() -- Define this minimal config so that it's available if telescope is not yet available. lvim.builtin.telescope = { @@ -96,7 +98,7 @@ function M.find_lunarvim_files(opts) }, prompt = ">> ", prompt_title = "~ LunarVim files ~", - cwd = CONFIG_PATH, + cwd = utils.join_paths(get_runtime_dir(), "lvim"), find_command = { "git", "ls-files" }, } opts = vim.tbl_deep_extend("force", theme_opts, opts) @@ -111,7 +113,7 @@ function M.grep_lunarvim_files(opts) layout_strategy = "bottom_pane", prompt = ">> ", prompt_title = "~ search LunarVim ~", - cwd = CONFIG_PATH, + cwd = utils.join_paths(get_runtime_dir(), "lvim"), } opts = vim.tbl_deep_extend("force", theme_opts, opts) require("telescope.builtin").live_grep(opts) diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index f9be8734..87053412 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -95,7 +95,7 @@ local function get_log_path(name) local logger = require "core.log" local file if name == "nvim" then - file = CACHE_PATH .. "/log" + file = utils.join_paths(get_cache_dir(), "log") else file = logger:new({ plugin = name }):get_path() end diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 458e1634..ef74ee51 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -176,7 +176,7 @@ M.config = function() L = { name = "+LunarVim", c = { - "edit ~/.config/lvim/config.lua", + "edit" .. get_config_dir() .. "/config.lua", "Edit config.lua", }, f = { diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index edac2245..3fa4fb94 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,16 +1,6 @@ local M = {} local Log = require "core.log" -function M.config() - vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind - - for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do - vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) - end - - require("lsp.handlers").setup() -end - local function lsp_highlight_document(client) if lvim.lsp.document_highlight == false then return -- we don't need further @@ -159,4 +149,29 @@ function M.setup(lang) end end +function M.global_setup() + vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind + + for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) + end + + require("lsp.handlers").setup() + + local null_status_ok, null_ls = pcall(require, "null-ls") + if null_status_ok then + null_ls.config() + require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) + end + + local utils = require "utils" + + local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings") + if lsp_settings_status_ok then + lsp_settings.setup { + config_home = utils.join_paths(get_config_dir(), "lsp-settings"), + } + end +end + return M diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua index aa1e888d..5921e9f1 100644 --- a/lua/plugin-loader.lua +++ b/lua/plugin-loader.lua @@ -1,9 +1,13 @@ local plugin_loader = {} -function plugin_loader:init() - local install_path = "~/.local/share/lunarvim/site/pack/packer/start/packer.nvim" - if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - vim.fn.system { "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path } +function plugin_loader:init(opts) + opts = opts or {} + + local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack" + local compile_path = opts.compile_path or vim.fn.stdpath "config" .. "/plugin/packer_compile.lua" + + if vim.fn.empty(vim.fn.glob(package_root)) > 0 then + vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", package_root } vim.cmd "packadd packer.nvim" end @@ -12,15 +16,13 @@ function plugin_loader:init() return end - local util = require "packer.util" - packer.init { - package_root = util.join_paths "~/.local/share/lunarvim/site/pack/", - compile_path = util.join_paths("~/.config/lvim", "plugin", "packer_compiled.lua"), + package_root = package_root, + compile_path = compile_path, git = { clone_timeout = 300 }, display = { open_fn = function() - return util.float { border = "rounded" } + return require("packer.util").float { border = "rounded" } end, }, } @@ -39,8 +41,4 @@ function plugin_loader:load(configurations) end) end -return { - init = function() - return plugin_loader:init() - end, -} +return plugin_loader diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 8ea842ca..095390b1 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -90,7 +90,7 @@ function utils.reload_lv_config() config:load() require("keymappings").setup() -- this should be done before loading the plugins - vim.cmd "source ~/.local/share/lunarvim/lvim/lua/plugins.lua" + vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua")) local plugins = require "plugins" local plugin_loader = require("plugin-loader").init() utils.toggle_autoformat() @@ -127,6 +127,12 @@ function utils.is_file(filename) return stat and stat.type == "file" or false end +function utils.join_paths(...) + local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/" + local result = table.concat(vim.tbl_flatten { ... }, path_sep):gsub(path_sep .. "+", path_sep) + return result +end + return utils -- TODO: find a new home for these autocommands -- cgit v1.2.3 From e10cd48ea2b85158eb830f14629963903be8ad42 Mon Sep 17 00:00:00 2001 From: Luong Vo Date: Mon, 13 Sep 2021 16:30:06 +0700 Subject: fix: common capabilities returning nothing if no cmp_nvim_lsp (#1537) Signed-off-by: Luong Vo --- lua/lsp/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 3fa4fb94..3c921e65 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -57,10 +57,10 @@ function M.common_capabilities() } local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") - if not status_ok then - return + if status_ok then + capabilities = cmp_nvim_lsp.update_capabilities(capabilities) end - capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + return capabilities end -- cgit v1.2.3 From bb130d669b60d0fd4d1a8867387f180d994968c9 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 11:49:53 +0200 Subject: fix: don't re-initalize the plugin-loader --- lua/utils/init.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 095390b1..100ab628 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -92,9 +92,8 @@ function utils.reload_lv_config() require("keymappings").setup() -- this should be done before loading the plugins vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua")) local plugins = require "plugins" - local plugin_loader = require("plugin-loader").init() utils.toggle_autoformat() - plugin_loader:load { plugins, lvim.plugins } + require("plugin-loader"):load { plugins, lvim.plugins } vim.cmd ":PackerCompile" vim.cmd ":PackerInstall" -- vim.cmd ":PackerClean" -- cgit v1.2.3 From 414777077fc8cd76a83fe3b97c80c149f7dd7d0d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 13 Sep 2021 17:22:27 +0200 Subject: fix: use correct install path for packer (#1540) --- lua/bootstrap.lua | 1 + lua/plugin-loader.lua | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index a03440d9..695dacdc 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -72,6 +72,7 @@ function M:init() cache_path = self.cache_path, runtime_dir = self.runtime_dir, config_dir = self.config_dir, + install_path = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim"), package_root = join_paths(self.runtime_dir, "site", "pack"), compile_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua"), } diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua index 5921e9f1..08f0e5a0 100644 --- a/lua/plugin-loader.lua +++ b/lua/plugin-loader.lua @@ -3,11 +3,12 @@ local plugin_loader = {} function plugin_loader:init(opts) opts = opts or {} + local install_path = opts.install_path or vim.fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim" local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack" local compile_path = opts.compile_path or vim.fn.stdpath "config" .. "/plugin/packer_compile.lua" - if vim.fn.empty(vim.fn.glob(package_root)) > 0 then - vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", package_root } + if vim.fn.empty(vim.fn.glob(install_path)) > 0 then + vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path } vim.cmd "packadd packer.nvim" end -- cgit v1.2.3 From f0b30f0a83988e6194970838656f9d4e8250e547 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Tue, 14 Sep 2021 01:33:40 -0400 Subject: fix: no preselect for up/down, c-j/c-k and tab/s-tab --- lua/core/cmp.lua | 4 ++-- lua/keymappings.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua index acfb05ae..928b7e3a 100644 --- a/lua/core/cmp.lua +++ b/lua/core/cmp.lua @@ -78,7 +78,7 @@ M.config = function() -- TODO: potentially fix emmet nonsense [""] = cmp.mapping(function() if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(T "", "n") + vim.fn.feedkeys(T "", "n") elseif luasnip.expand_or_jumpable() then vim.fn.feedkeys(T "luasnip-expand-or-jump", "") elseif check_backspace() then @@ -94,7 +94,7 @@ M.config = function() }), [""] = cmp.mapping(function(fallback) if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(T "", "n") + vim.fn.feedkeys(T "", "n") elseif luasnip.jumpable(-1) then vim.fn.feedkeys(T "luasnip-jump-prev", "") else diff --git a/lua/keymappings.lua b/lua/keymappings.lua index 557e0bde..027ca83f 100644 --- a/lua/keymappings.lua +++ b/lua/keymappings.lua @@ -83,8 +83,8 @@ function M.config() [""] = "l", -- navigate tab completion with and -- runs conditionally - [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, - [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, + [""] = { 'pumvisible() ? "\\" : "\\"', { expr = true, noremap = true } }, }, ---@usage change or add keymappings for normal mode -- cgit v1.2.3 From 0cbc1e9425445401d338e6f68f0c9910b31886cc Mon Sep 17 00:00:00 2001 From: chaesngmin Date: Tue, 14 Sep 2021 09:06:50 -0700 Subject: feat(lualine): pin commit to avoid breaking config (#1546) --- lua/plugins.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index 178fb99e..95c090f3 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -131,6 +131,7 @@ return { -- "hoob3rt/lualine.nvim", "shadmansaleh/lualine.nvim", -- "Lunarvim/lualine.nvim", + commit = "62bfe80fb6e0cd51cec6fc9df9e1768f7d37d299", config = function() require("core.lualine").setup() end, -- cgit v1.2.3 From df0da6fc75c60c8bd2791b7cdb9d05d12a25bb50 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 15 Sep 2021 23:41:21 +0430 Subject: [bugfix] Update lualine according to the breaking changes (#1558) --- lua/core/lualine/components.lua | 44 ++++++++++++++++++++--------------------- lua/core/lualine/styles.lua | 12 +++++------ lua/plugins.lua | 1 - 3 files changed, 28 insertions(+), 29 deletions(-) (limited to 'lua') diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index c6800f49..21e25585 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -17,31 +17,32 @@ return { function() return " " end, - left_padding = 0, - right_padding = 0, + padding = { left = 0, right = 0 }, color = {}, - condition = nil, + cond = nil, }, branch = { "b:gitsigns_head", icon = " ", color = { gui = "bold" }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, filename = { "filename", color = {}, - condition = nil, + cond = nil, }, diff = { "diff", source = diff_source, symbols = { added = "  ", modified = "柳", removed = " " }, - color_added = { fg = colors.green }, - color_modified = { fg = colors.yellow }, - color_removed = { fg = colors.red }, + diff_color = { + added = { fg = colors.green }, + modified = { fg = colors.yellow }, + removed = { fg = colors.red }, + }, color = {}, - condition = nil, + cond = nil, }, python_env = { function() @@ -60,14 +61,14 @@ return { return "" end, color = { fg = colors.green }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, diagnostics = { "diagnostics", sources = { "nvim_lsp" }, symbols = { error = " ", warn = " ", info = " ", hint = " " }, color = {}, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, treesitter = { function() @@ -78,7 +79,7 @@ return { return "" end, color = { fg = colors.green }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, lsp = { function(msg) @@ -118,10 +119,10 @@ return { end, icon = " ", color = { gui = "bold" }, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, - location = { "location", condition = conditions.hide_in_width, color = {} }, - progress = { "progress", condition = conditions.hide_in_width, color = {} }, + location = { "location", cond = conditions.hide_in_width, color = {} }, + progress = { "progress", cond = conditions.hide_in_width, color = {} }, spaces = { function() local label = "Spaces: " @@ -130,16 +131,16 @@ return { end return label .. vim.api.nvim_buf_get_option(0, "shiftwidth") .. " " end, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, color = {}, }, encoding = { "o:encoding", - upper = true, + fmt = string.upper, color = {}, - condition = conditions.hide_in_width, + cond = conditions.hide_in_width, }, - filetype = { "filetype", condition = conditions.hide_in_width, color = {} }, + filetype = { "filetype", cond = conditions.hide_in_width, color = {} }, scrollbar = { function() local current_line = vim.fn.line "." @@ -149,9 +150,8 @@ return { local index = math.ceil(line_ratio * #chars) return chars[index] end, - left_padding = 0, - right_padding = 0, + padding = { left = 0, right = 0 }, color = { fg = colors.yellow, bg = colors.bg }, - condition = nil, + cond = nil, }, } diff --git a/lua/core/lualine/styles.lua b/lua/core/lualine/styles.lua index 3595e5e3..19097424 100644 --- a/lua/core/lualine/styles.lua +++ b/lua/core/lualine/styles.lua @@ -11,8 +11,8 @@ styles.none = { style = "none", options = { icons_enabled = true, - component_separators = "", - section_separators = "", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, disabled_filetypes = {}, }, sections = { @@ -39,8 +39,8 @@ styles.default = { style = "default", options = { icons_enabled = true, - component_separators = { "", "" }, - section_separators = { "", "" }, + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, disabled_filetypes = {}, }, sections = { @@ -67,8 +67,8 @@ styles.lvim = { style = "lvim", options = { icons_enabled = true, - component_separators = "", - section_separators = "", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, disabled_filetypes = { "dashboard", "NvimTree", "Outline" }, }, sections = { diff --git a/lua/plugins.lua b/lua/plugins.lua index 95c090f3..178fb99e 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -131,7 +131,6 @@ return { -- "hoob3rt/lualine.nvim", "shadmansaleh/lualine.nvim", -- "Lunarvim/lualine.nvim", - commit = "62bfe80fb6e0cd51cec6fc9df9e1768f7d37d299", config = function() require("core.lualine").setup() end, -- cgit v1.2.3 From 168eb232d12f86e98f0d90c4e73e0c9968a3cb8e Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 15 Sep 2021 23:42:57 +0430 Subject: feature: make peek function work in neovim head and 0.5 (#1559) --- lua/lsp/peek.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/lsp/peek.lua b/lua/lsp/peek.lua index dbc67417..cb00488e 100644 --- a/lua/lsp/peek.lua +++ b/lua/lsp/peek.lua @@ -54,9 +54,8 @@ local function create_floating_file(location, opts) return bufnr, winnr end -local function preview_location_callback(_, method, result) +local function preview_location_callback(result) if result == nil or vim.tbl_isempty(result) then - print("peek: No location found: " .. method) return nil end @@ -74,6 +73,14 @@ local function preview_location_callback(_, method, result) end end +local function preview_location_callback_old_signature(_, _, result) + return preview_location_callback(result) +end + +local function preview_location_callback_new_signature(_, result) + return preview_location_callback(result) +end + function M.open_file() -- Get the file currently open in the floating window local filepath = vim.fn.expand "%:." @@ -129,7 +136,11 @@ function M.Peek(what) else -- Make a new request and then create the new window in the callback local params = vim.lsp.util.make_position_params() - local success, _ = pcall(vim.lsp.buf_request, 0, "textDocument/" .. what, params, preview_location_callback) + local preview_callback = preview_location_callback_old_signature + if vim.fn.has "nvim-0.5.1" > 0 then + preview_callback = preview_location_callback_new_signature + end + local success, _ = pcall(vim.lsp.buf_request, 0, "textDocument/" .. what, params, preview_callback) if not success then print( 'peek: Error calling LSP method "textDocument/' .. what .. '". The current language lsp might not support it.' -- cgit v1.2.3 From e22f9a21c179901e6dfcbdb68d035e70eae4d9e8 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 16 Sep 2021 09:58:32 +0200 Subject: fix: more robust reloading (#1556) --- lua/bootstrap.lua | 11 +++++------ lua/core/which-key.lua | 1 + lua/plugin-loader.lua | 20 +++++++++++++++++++- lua/utils/init.lua | 26 ++++++++++++++++++++++++-- 4 files changed, 49 insertions(+), 9 deletions(-) (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 695dacdc..85d39d2d 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -38,6 +38,8 @@ function M:init() self.cache_path = get_cache_dir() self.pack_dir = join_paths(self.runtime_dir, "site", "pack") + self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim") + self.packer_cache_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua") if os.getenv "LUNARVIM_RUNTIME_DIR" then vim.opt.rtp:remove(join_paths(vim.fn.stdpath "data", "site")) @@ -57,6 +59,7 @@ function M:init() -- FIXME: currently unreliable in unit-tests if not os.getenv "LVIM_TEST_ENV" then + vim.fn.mkdir(vim.fn.stdpath "cache", "p") require("impatient").setup { path = vim.fn.stdpath "cache" .. "/lvim_cache", enable_profiling = true, @@ -69,12 +72,8 @@ function M:init() } require("plugin-loader"):init { - cache_path = self.cache_path, - runtime_dir = self.runtime_dir, - config_dir = self.config_dir, - install_path = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim"), - package_root = join_paths(self.runtime_dir, "site", "pack"), - compile_path = join_paths(self.config_dir, "plugin", "packer_compiled.lua"), + package_root = self.pack_dir, + install_path = self.packer_install_dir, } return self diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index ef74ee51..3379100d 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -209,6 +209,7 @@ M.config = function() }, P = { "edit ~/.cache/nvim/packer.nvim.log", "Open the Packer logfile" }, }, + r = { "lua require('utils').reload_lv_config()", "Reload configurations" }, }, s = { name = "Search", diff --git a/lua/plugin-loader.lua b/lua/plugin-loader.lua index 08f0e5a0..c20dd21a 100644 --- a/lua/plugin-loader.lua +++ b/lua/plugin-loader.lua @@ -1,11 +1,15 @@ local plugin_loader = {} +local utils = require "utils" +local Log = require "core.log" +-- we need to reuse this outside of init() +local compile_path = get_config_dir() .. "/plugin/packer_compiled.lua" + function plugin_loader:init(opts) opts = opts or {} local install_path = opts.install_path or vim.fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim" local package_root = opts.package_root or vim.fn.stdpath "data" .. "/site/pack" - local compile_path = opts.compile_path or vim.fn.stdpath "config" .. "/plugin/packer_compile.lua" if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path } @@ -32,6 +36,20 @@ function plugin_loader:init(opts) return self end +function plugin_loader:cache_clear() + if vim.fn.delete(compile_path) == 0 then + Log:debug "deleted packer_compiled.lua" + end +end + +function plugin_loader:cache_reset() + self.cache_clear() + require("packer").compile() + if utils.is_file(compile_path) then + Log:debug "generated packer_compiled.lua" + end +end + function plugin_loader:load(configurations) return self.packer.startup(function(use) for _, plugins in ipairs(configurations) do diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 100ab628..5a5e4ba3 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -93,9 +93,11 @@ function utils.reload_lv_config() vim.cmd("source " .. utils.join_paths(get_runtime_dir(), "lvim", "lua", "plugins.lua")) local plugins = require "plugins" utils.toggle_autoformat() - require("plugin-loader"):load { plugins, lvim.plugins } - vim.cmd ":PackerCompile" + local plugin_loader = require "plugin-loader" + plugin_loader:cache_reset() + plugin_loader:load { plugins, lvim.plugins } vim.cmd ":PackerInstall" + vim.cmd ":PackerCompile" -- vim.cmd ":PackerClean" local null_ls = require "lsp.null-ls" null_ls.setup(vim.bo.filetype, { force_reload = true }) @@ -118,6 +120,18 @@ function utils.gsub_args(args) return args end +--- Returns a table with the default values that are missing. +--- either paramter can be empty. +--@param config (table) table containing entries that take priority over defaults +--@param default_config (table) table contatining default values if found +function utils.apply_defaults(config, default_config) + config = config or {} + default_config = default_config or {} + local new_config = vim.tbl_deep_extend("keep", vim.empty_dict(), config) + new_config = vim.tbl_deep_extend("keep", new_config, default_config) + return new_config +end + --- Checks whether a given path exists and is a file. --@param filename (string) path to check --@returns (bool) @@ -132,6 +146,14 @@ function utils.join_paths(...) return result end +function utils.lvim_cache_reset() + _G.__luacache.clear_cache() + _G.__luacache.save_cache() + require("plugin-loader"):cache_reset() +end + +vim.cmd [[ command! LvimCacheReset lua require('utils').lvim_cache_reset() ]] + return utils -- TODO: find a new home for these autocommands -- cgit v1.2.3 From d610502f91ba08c9afc6557d892f93bae2bdab13 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Thu, 16 Sep 2021 10:15:30 -0400 Subject: fix: dashboard footer seems to have disapeared --- lua/core/dashboard.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lua') diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index aa2a7f35..0ade4657 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -69,6 +69,8 @@ M.setup = function() vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory + vim.g.dashboard_custom_footer = lvim.builtin.dashboard.footer + require("core.autocmds").define_augroups { _dashboard = { -- seems to be nobuflisted that makes my stuff disappear will do more testing -- cgit v1.2.3 From 9257e68c05eff293ea15a484d994b83fd7c610d8 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 17 Sep 2021 08:29:35 +0200 Subject: fix: use the correct API for the log-viewer (#1564) --- lua/core/terminal.lua | 9 +++++---- lua/core/which-key.lua | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'lua') diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 87053412..4525ca63 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -1,5 +1,6 @@ local M = {} local utils = require "utils" +local Log = require "core.log" M.config = function() lvim.builtin["terminal"] = { @@ -81,7 +82,6 @@ end M._exec_toggle = function(exec) local binary = M._split(exec)[1] if vim.fn.executable(binary) ~= 1 then - local Log = require "core.log" Log:error("Unable to run executable " .. binary .. ". Please make sure it is installed properly.") return end @@ -92,12 +92,13 @@ end local function get_log_path(name) --handle custom paths not managed by Plenary.log - local logger = require "core.log" local file if name == "nvim" then - file = utils.join_paths(get_cache_dir(), "log") + file = utils.join_paths(vim.fn.stdpath "cache", "log") + elseif name == "packer.nvim" then + file = utils.join_paths(vim.fn.stdpath "cache", "packer.nvim.log") else - file = logger:new({ plugin = name }):get_path() + file = Log:get_path() end if utils.is_file(file) then return file diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 3379100d..36949467 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -198,16 +198,16 @@ M.config = function() "lua require('core.terminal').toggle_log_view('lunarvim')", "view default log", }, - D = { "edit ~/.cache/nvim/lunarvim.log", "Open the default logfile" }, + D = { "exe 'edit '.stdpath('cache').'/lunarvim.log'", "Open the default logfile" }, n = { "lua require('core.terminal').toggle_log_view('lsp')", "view lsp log" }, - N = { "edit ~/.cache/nvim/log", "Open the Neovim logfile" }, + N = { "edit $NVIM_LOG_FILE", "Open the Neovim logfile" }, l = { "lua require('core.terminal').toggle_log_view('nvim')", "view neovim log" }, - L = { "edit ~/.cache/nvim/lsp.log", "Open the LSP logfile" }, + L = { "exe 'edit '.stdpath('cache').'/lsp.log'", "Open the LSP logfile" }, p = { "lua require('core.terminal').toggle_log_view('packer.nvim')", "view packer log", }, - P = { "edit ~/.cache/nvim/packer.nvim.log", "Open the Packer logfile" }, + P = { "exe 'edit '.stdpath('cache').'/packer.nvim.log'", "Open the Packer logfile" }, }, r = { "lua require('utils').reload_lv_config()", "Reload configurations" }, }, -- cgit v1.2.3 From eab0369ae8688b23946a8a9e6dab6061ec0c554a Mon Sep 17 00:00:00 2001 From: Luong Vo Date: Fri, 17 Sep 2021 13:34:03 +0700 Subject: fix: missing default configuration for update_in_insert (#1550) --- lua/config/defaults.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index a4ef7125..e27d8077 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -75,6 +75,7 @@ lvim = { prefix = "", spacing = 0, }, + update_in_insert = false, underline = true, severity_sort = true, }, -- cgit v1.2.3 From 254ab2102b5f8f6187321a545998ead4c3abd27a Mon Sep 17 00:00:00 2001 From: chaesngmin Date: Fri, 17 Sep 2021 04:13:52 -0700 Subject: [Feature] Add lunarvim latest release tag to dashboard (#1436) * feat: add lunarvim latest release tag to dashboard * Add a function to center-align text Rename align to align_left Rename shift_left to shift_right * refactor(dashboard): remove unnecessary comment * refactor(dashboard): use `home_dir` variable for `lv_path` * refactor(dashboard): use $LUNARVIM_RUNTIME_DIR for lv_path * feat(bootstrap): add fn that returns lvim version * refactor(dashboard): use version, lunarvim dir with bootstrap fns * build: add global get_version() from bootstrap Co-authored-by: Luc Sinet --- lua/bootstrap.lua | 9 +++++++++ lua/core/dashboard.lua | 13 ++++++++++++- lua/core/info.lua | 4 ++-- lua/interface/text.lua | 24 ++++++++++++++++++++---- 4 files changed, 43 insertions(+), 7 deletions(-) (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 85d39d2d..5e333d8a 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -32,6 +32,15 @@ function _G.get_cache_dir() return lvim_cache_dir end +function _G.get_version(type) + local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tag") + if type == "short" then + return vim.fn.split(lvim_full_ver, "-")[1] + else + return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1) + end +end + function M:init() self.runtime_dir = get_runtime_dir() self.config_dir = get_config_dir() diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 0ade4657..44c4e38c 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -69,7 +69,18 @@ M.setup = function() vim.g.dashboard_session_directory = lvim.builtin.dashboard.session_directory - vim.g.dashboard_custom_footer = lvim.builtin.dashboard.footer + local lvim_site = "lunarvim.org" + local lvim_version = get_version "short" + local num_plugins_loaded = #vim.fn.globpath(get_runtime_dir() .. "/site/pack/packer/start", "*", 0, 1) + + local text = require "interface.text" + vim.g.dashboard_custom_footer = text.align_center({ width = 0 }, { + "LunarVim loaded " .. num_plugins_loaded .. " plugins ", + "", + "v" .. lvim_version, + "", + lvim_site, + }, 0.49) -- Use 0.49 as  counts for 2 characters require("core.autocmds").define_augroups { _dashboard = { diff --git a/lua/core/info.lua b/lua/core/info.lua index 67e45d1c..b8d51a8c 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -97,7 +97,7 @@ function M.toggle_popup(ft) local caps_text = "* Capabilities list: " local caps_text_len = caps_text:len() local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") - enabled_caps = text.shift_left(enabled_caps, caps_text_len) + enabled_caps = text.shift_right(enabled_caps, caps_text_len) enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) vim.list_extend(lsp_info, enabled_caps) end @@ -155,7 +155,7 @@ function M.toggle_popup(ft) vim.list_extend(content, section) end - return text.align(popup, content, 0.5) + return text.align_left(popup, content, 0.5) end local function set_syntax_hl() diff --git a/lua/interface/text.lua b/lua/interface/text.lua index f68cc491..6bf280e8 100644 --- a/lua/interface/text.lua +++ b/lua/interface/text.lua @@ -13,20 +13,36 @@ local function max_len_line(lines) return max_len end ---- Center align lines relatively to the parent container +--- Left align lines relatively to the parent container -- @param container The container where lines will be displayed -- @param lines The text to align -- @param alignment The alignment value, range: [0-1] -function M.align(container, lines, alignment) +function M.align_left(container, lines, alignment) local max_len = max_len_line(lines) local indent_amount = math.ceil(math.max(container.width - max_len, 0) * alignment) - return M.shift_left(lines, indent_amount) + return M.shift_right(lines, indent_amount) +end + +--- Center align lines relatively to the parent container +-- @param container The container where lines will be displayed +-- @param lines The text to align +-- @param alignment The alignment value, range: [0-1] +function M.align_center(container, lines, alignment) + local output = {} + local max_len = max_len_line(lines) + + for _, line in ipairs(lines) do + local padding = string.rep(" ", (math.max(container.width, max_len) - line:len()) * alignment) + table.insert(output, padding .. line) + end + + return output end --- Shift lines by a given amount -- @params lines The lines the shift -- @param amount The amount of spaces to add -function M.shift_left(lines, amount) +function M.shift_right(lines, amount) local output = {} local padding = string.rep(" ", amount) -- cgit v1.2.3 From 390f277b702fe7877f0d5fabbece230528b58cb1 Mon Sep 17 00:00:00 2001 From: chaesngmin Date: Fri, 17 Sep 2021 05:14:31 -0700 Subject: fix(dashboard): hide version when no tag found (#1572) --- lua/bootstrap.lua | 6 +++++- lua/core/dashboard.lua | 15 ++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 5e333d8a..ff6d9cdf 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -33,7 +33,11 @@ function _G.get_cache_dir() end function _G.get_version(type) - local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tag") + local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tags") + + if string.match(lvim_full_ver, "%d") == nil then + return nil + end if type == "short" then return vim.fn.split(lvim_full_ver, "-")[1] else diff --git a/lua/core/dashboard.lua b/lua/core/dashboard.lua index 44c4e38c..505350cb 100644 --- a/lua/core/dashboard.lua +++ b/lua/core/dashboard.lua @@ -73,14 +73,19 @@ M.setup = function() local lvim_version = get_version "short" local num_plugins_loaded = #vim.fn.globpath(get_runtime_dir() .. "/site/pack/packer/start", "*", 0, 1) - local text = require "interface.text" - vim.g.dashboard_custom_footer = text.align_center({ width = 0 }, { + local footer = { "LunarVim loaded " .. num_plugins_loaded .. " plugins ", "", - "v" .. lvim_version, - "", lvim_site, - }, 0.49) -- Use 0.49 as  counts for 2 characters + } + + if lvim_version then + table.insert(footer, 2, "") + table.insert(footer, 3, "v" .. lvim_version) + end + + local text = require "interface.text" + vim.g.dashboard_custom_footer = text.align_center({ width = 0 }, footer, 0.49) -- Use 0.49 as  counts for 2 characters require("core.autocmds").define_augroups { _dashboard = { -- cgit v1.2.3 From 87d36102919df97ec15af4c916e37888cee279cd Mon Sep 17 00:00:00 2001 From: xeluxee <88047141+xeluxee@users.noreply.github.com> Date: Fri, 17 Sep 2021 18:39:26 +0200 Subject: [Bugfix]: latex completion: insert `{` instead of `(` when completing (#1566) --- lua/core/autopairs.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'lua') diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index b728cbc1..a67f3b07 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -7,8 +7,16 @@ function M.config() ---@usage map on insert mode map_cr = true, ---@usage auto insert after select function or method item - -- NOTE: This should be wrapped into a function so that it is re-evaluated when opening new files - map_complete = vim.bo.filetype ~= "tex", + map_complete = true, + ---@usage automatically select the first item + auto_select = true, + ---@usage use insert confirm behavior instead of replace + insert = false, + ---@usage -- modifies the function or method delimiter by filetypes + map_char = { + all = "(", + tex = "{", + }, ---@usage check treesitter check_ts = true, ts_config = { @@ -52,9 +60,11 @@ M.setup = function() if package.loaded["cmp"] then require("nvim-autopairs.completion.cmp").setup { - map_cr = true, -- map on insert mode - map_complete = true, -- it will auto insert `(` after select function or method item - auto_select = true, -- automatically select the first item + map_cr = lvim.builtin.autopairs.map_cr, + map_complete = lvim.builtin.autopairs.map_complete, + auto_select = lvim.builtin.autopairs.auto_select, + insert = lvim.builtin.autopairs.insert, + map_char = lvim.builtin.autopairs.map_char, } end -- cgit v1.2.3 From 65392c553ea6a69053a99fea57c3dee6c48afa75 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 18 Sep 2021 13:23:30 +0430 Subject: feature: vim.api.diagnostics has been moved to vim.diagnostics in neovim head (#1573) --- lua/lsp/handlers.lua | 72 ++++++++++++++++++++++++++++++++++++++------------- lua/onedarker/LSP.lua | 12 +++++++++ 2 files changed, 66 insertions(+), 18 deletions(-) (limited to 'lua') diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index 84811581..d55bd0b2 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -19,11 +19,41 @@ function M.setup() end local diagnostics = result.diagnostics - vim.lsp.diagnostic.save(diagnostics, bufnr, ctx.client_id) - if not vim.api.nvim_buf_is_loaded(bufnr) then - return + local ok, vim_diag = pcall(require, "vim.diagnostic") + if ok then + -- FIX: why can't we just use vim.diagnostic.get(buf_id)? + config.signs = true + for i, diagnostic in ipairs(diagnostics) do + local rng = diagnostic.range + diagnostics[i].lnum = rng["start"].line + diagnostics[i].end_lnum = rng["end"].line + diagnostics[i].col = rng["start"].character + diagnostics[i].end_col = rng["end"].character + end + local namespace = vim.lsp.diagnostic.get_namespace(ctx.client_id) + + vim_diag.set(namespace, bufnr, diagnostics, config) + if not vim.api.nvim_buf_is_loaded(bufnr) then + return + end + + local sign_names = { + "DiagnosticSignError", + "DiagnosticSignWarn", + "DiagnosticSignInfo", + "DiagnosticSignHint", + } + for i, sign in ipairs(lvim.lsp.diagnostics.signs.values) do + vim.fn.sign_define(sign_names[i], { texthl = sign_names[i], text = sign.text, numhl = "" }) + end + vim_diag.show(namespace, bufnr, diagnostics, config) + else + vim.lsp.diagnostic.save(diagnostics, bufnr, ctx.client_id) + if not vim.api.nvim_buf_is_loaded(bufnr) then + return + end + vim.lsp.diagnostic.display(diagnostics, bufnr, ctx.client_id, config) end - vim.lsp.diagnostic.display(diagnostics, bufnr, ctx.client_id, config) end else vim.lsp.handlers["textDocument/publishDiagnostics"] = function(_, _, params, client_id, _) @@ -53,17 +83,30 @@ end function M.show_line_diagnostics() local diagnostics = vim.lsp.diagnostic.get_line_diagnostics() + local severity_highlight = { + "LspDiagnosticsFloatingError", + "LspDiagnosticsFloatingWarning", + "LspDiagnosticsFloatingInformation", + "LspDiagnosticsFloatingHint", + } + local ok, vim_diag = pcall(require, "vim.diagnostic") + if ok then + local buf_id = vim.api.nvim_win_get_buf(0) + local win_id = vim.api.nvim_get_current_win() + local cursor_position = vim.api.nvim_win_get_cursor(win_id) + severity_highlight = { + "DiagnosticFloatingError", + "DiagnosticFloatingWarn", + "DiagnosticFloatingInfo", + "DiagnosticFloatingHint", + } + diagnostics = vim_diag.get(buf_id, { lnum = cursor_position[1] - 1 }) + end local diags = vim.deepcopy(diagnostics) local height = #diagnostics local width = 0 local opts = {} local close_events = { "CursorMoved", "CursorMovedI", "BufHidden", "InsertCharPre" } - local diagnostic_severities = { - "Error", - "Warning", - "Information", - "Hint", - } if height == 0 then return end @@ -99,14 +142,7 @@ function M.show_line_diagnostics() for i, diag in ipairs(diags) do local message = diag.message:gsub("[\n\r]", " ") vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { message }) - vim.api.nvim_buf_add_highlight( - bufnr, - -1, - "LspDiagnosticsFloating" .. diagnostic_severities[diag.severity], - i - 1, - 0, - diag.message:len() - ) + vim.api.nvim_buf_add_highlight(bufnr, -1, severity_highlight[diag.severity], i - 1, 0, diag.message:len()) end vim.api.nvim_command( diff --git a/lua/onedarker/LSP.lua b/lua/onedarker/LSP.lua index d2d3a870..3d88338f 100644 --- a/lua/onedarker/LSP.lua +++ b/lua/onedarker/LSP.lua @@ -11,10 +11,18 @@ local LSP = { LspDiagnosticsFloatingWarning = { fg = C.warning_orange }, LspDiagnosticsFloatingInformation = { fg = C.info_yellow }, LspDiagnosticsFloatingHint = { fg = C.hint_blue }, + DiagnosticFloatingError = { fg = C.error_red }, + DiagnosticFloatingWarn = { fg = C.warning_orange }, + DiagnosticFloatingInfo = { fg = C.info_yellow }, + DiagnosticFloatingHint = { fg = C.hint_blue }, LspDiagnosticsSignError = { fg = C.error_red }, LspDiagnosticsSignWarning = { fg = C.warning_orange }, LspDiagnosticsSignInformation = { fg = C.info_yellow }, LspDiagnosticsSignHint = { fg = C.hint_blue }, + DiagnosticSignError = { fg = C.error_red }, + DiagnosticSignWarn = { fg = C.warning_orange }, + DiagnosticSignInfo = { fg = C.info_yellow }, + DiagnosticSignHint = { fg = C.hint_blue }, LspDiagnosticsError = { fg = C.error_red }, LspDiagnosticsWarning = { fg = C.warning_orange }, LspDiagnosticsInformation = { fg = C.info_yellow }, @@ -23,6 +31,10 @@ local LSP = { LspDiagnosticsUnderlineWarning = { style = "underline" }, LspDiagnosticsUnderlineInformation = { style = "underline" }, LspDiagnosticsUnderlineHint = { style = "underline" }, + DiagnosticUnderlineError = { style = "underline" }, + DiagnosticUnderlineWarn = { style = "underline" }, + DiagnosticUnderlineInfo = { style = "underline" }, + DiagnosticUnderlineHint = { style = "underline" }, QuickScopePrimary = { fg = C.purple_test, style = "underline" }, QuickScopeSecondary = { fg = C.cyan_test, style = "underline" }, TelescopeSelection = { fg = C.hint_blue }, -- cgit v1.2.3 From dbb958289b19f18739bc3d935e41e6c7ce75eab6 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 20 Sep 2021 14:15:22 +0430 Subject: add support for local stylelint (#1586) --- lua/lsp/null-ls/services.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua') diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index a1e3a06c..1e76b40a 100644 --- a/lua/lsp/null-ls/services.lua +++ b/lua/lsp/null-ls/services.lua @@ -28,6 +28,7 @@ local local_providers = { prettier_d_slim = { find = from_node_modules }, eslint_d = { find = from_node_modules }, eslint = { find = from_node_modules }, + stylelint = { find = from_node_modules }, } function M.find_command(command) -- cgit v1.2.3 From fbfd8c1fc3d0df1e2169df64c2264de7e23a9105 Mon Sep 17 00:00:00 2001 From: Chase Colman <5411+chase@users.noreply.github.com> Date: Tue, 21 Sep 2021 14:54:47 +0800 Subject: feature: allow cmp confirm options to be configurable (#1523) --- lua/core/cmp.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua index 928b7e3a..2bc724fb 100644 --- a/lua/core/cmp.lua +++ b/lua/core/cmp.lua @@ -30,6 +30,10 @@ M.config = function() return end lvim.builtin.cmp = { + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = true, + }, formatting = { format = function(entry, vim_item) local icons = require("lsp.kind").icons @@ -107,10 +111,15 @@ M.config = function() [""] = cmp.mapping.complete(), [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm { - behavior = cmp.ConfirmBehavior.Replace, - select = true, - }, + [""] = cmp.mapping(function(fallback) + if not require("cmp").confirm(lvim.builtin.cmp.confirm_opts) then + if luasnip.jumpable() then + vim.fn.feedkeys(T "luasnip-jump-next", "") + else + fallback() + end + end + end), }, } end -- cgit v1.2.3 From 55d9a15a088d688627426b034f4b71aa86a8ce9e Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Tue, 21 Sep 2021 13:29:32 +0430 Subject: [Bugfix] Wrap the `gl` floating window diagnostics (#1588) --- lua/lsp/handlers.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index d55bd0b2..2f06cb8a 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -126,18 +126,20 @@ function M.show_line_diagnostics() if diagnostic.code then diags[i].message = string.format("%s [%s]", diags[i].message, diagnostic.code) end - if diags[i].message:len() > width then - width = string.len(diags[i].message) - end + width = math.max(width, diags[i].message:len()) end + local max_width = vim.fn.winwidth(0) - 10 + width = math.min(width, max_width) opts = vim.lsp.util.make_floating_popup_options(width, height, opts) opts["style"] = "minimal" opts["border"] = "rounded" + opts["focusable"] = true vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe") local winnr = vim.api.nvim_open_win(bufnr, false, opts) vim.api.nvim_win_set_option(winnr, "winblend", 0) + vim.api.nvim_win_set_option(winnr, "wrap", true) vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr) for i, diag in ipairs(diags) do local message = diag.message:gsub("[\n\r]", " ") -- cgit v1.2.3 From 938e0f88bc3c27ce019470e0279233a373df61ef Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Tue, 21 Sep 2021 11:56:24 +0200 Subject: fix: remove outdated cache files on install (#1591) --- lua/impatient.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/impatient.lua b/lua/impatient.lua index ea1369fb..d438851c 100644 --- a/lua/impatient.lua +++ b/lua/impatient.lua @@ -277,7 +277,7 @@ impatient_dur = uv.hrtime() - impatient_load_start function M.setup(opts) opts = opts or {} - M.path = opts.path or vim.fn.stdpath "cache" .. "/luacache" + M.path = opts.path or vim.fn.stdpath "cache" .. "/lvim_cache" if opts.enable_profiling then M.enable_profile() -- cgit v1.2.3 From edeadaf05d98034bc91a22ad50263a7a25c6020a Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 22 Sep 2021 10:56:52 +0330 Subject: [Bugfix] instead of wrapping the `gl` diagnostics, split them (#1595) --- lua/lsp/handlers.lua | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'lua') diff --git a/lua/lsp/handlers.lua b/lua/lsp/handlers.lua index 2f06cb8a..ffb7564a 100644 --- a/lua/lsp/handlers.lua +++ b/lua/lsp/handlers.lua @@ -81,7 +81,16 @@ function M.setup() }) end +local function split_by_chunk(text, chunkSize) + local s = {} + for i = 1, #text, chunkSize do + s[#s + 1] = text:sub(i, i + chunkSize - 1) + end + return s +end + function M.show_line_diagnostics() + -- TODO: replace all this with vim.diagnostic.show_position_diagnostics() local diagnostics = vim.lsp.diagnostic.get_line_diagnostics() local severity_highlight = { "LspDiagnosticsFloatingError", @@ -102,7 +111,8 @@ function M.show_line_diagnostics() } diagnostics = vim_diag.get(buf_id, { lnum = cursor_position[1] - 1 }) end - local diags = vim.deepcopy(diagnostics) + local lines = {} + local max_width = vim.fn.winwidth(0) - 5 local height = #diagnostics local width = 0 local opts = {} @@ -111,26 +121,31 @@ function M.show_line_diagnostics() return end local bufnr = vim.api.nvim_create_buf(false, true) - + local diag_message + table.sort(diagnostics, function(a, b) + return a.severity < b.severity + end) for i, diagnostic in ipairs(diagnostics) do local source = diagnostic.source + diag_message = diagnostic.message:gsub("[\n\r]", " ") if source then if string.find(source, "/") then source = string.sub(diagnostic.source, string.find(diagnostic.source, "([%w-_]+)$")) end - diags[i].message = string.format("%s: %s", source, diagnostic.message) + diag_message = string.format("%d. %s: %s", i, source, diag_message) else - diags[i].message = string.format("%s", diagnostic.message) + diag_message = string.format("%d. %s", i, diag_message) end - if diagnostic.code then - diags[i].message = string.format("%s [%s]", diags[i].message, diagnostic.code) + diag_message = string.format("%s [%s]", diag_message, diagnostic.code) + end + local msgs = split_by_chunk(diag_message, max_width) + for _, diag in ipairs(msgs) do + table.insert(lines, { message = diag, severity = diagnostic.severity }) + width = math.max(diag:len(), width) end - width = math.max(width, diags[i].message:len()) end - local max_width = vim.fn.winwidth(0) - 10 - width = math.min(width, max_width) - + height = #lines opts = vim.lsp.util.make_floating_popup_options(width, height, opts) opts["style"] = "minimal" opts["border"] = "rounded" @@ -139,11 +154,9 @@ function M.show_line_diagnostics() vim.api.nvim_buf_set_option(bufnr, "bufhidden", "wipe") local winnr = vim.api.nvim_open_win(bufnr, false, opts) vim.api.nvim_win_set_option(winnr, "winblend", 0) - vim.api.nvim_win_set_option(winnr, "wrap", true) vim.api.nvim_buf_set_var(bufnr, "lsp_floating_window", winnr) - for i, diag in ipairs(diags) do - local message = diag.message:gsub("[\n\r]", " ") - vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { message }) + for i, diag in ipairs(lines) do + vim.api.nvim_buf_set_lines(bufnr, i - 1, i - 1, 0, { diag.message }) vim.api.nvim_buf_add_highlight(bufnr, -1, severity_highlight[diag.severity], i - 1, 0, diag.message:len()) end -- cgit v1.2.3 From ddd86dd2b95f26ef0477e0c2c3641f49f14e4fba Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Thu, 23 Sep 2021 20:00:20 +0330 Subject: Fix the lua goto definition bug and add better common capabilities (#1604) --- lua/config/defaults.lua | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'lua') diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index e27d8077..a67a9c53 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -644,12 +644,6 @@ lvim.lang = { }, settings = { Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - -- Setup your lua path - path = vim.split(package.path, ";"), - }, diagnostics = { -- Get the language server to recognize the `vim` global globals = { "vim", "lvim" }, @@ -662,7 +656,7 @@ lvim.lang = { [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, }, maxPreload = 100000, - preloadFileSize = 1000, + preloadFileSize = 10000, }, }, }, -- cgit v1.2.3 From 9b76a13512b407f23eb9fc16d0210daccccf4802 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 25 Sep 2021 10:35:08 +0330 Subject: watch_index is deprecated, use watch_gitdir instead (#1614) --- lua/core/gitsigns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/core/gitsigns.lua b/lua/core/gitsigns.lua index bb9d088b..cc6387dc 100644 --- a/lua/core/gitsigns.lua +++ b/lua/core/gitsigns.lua @@ -44,7 +44,7 @@ M.config = function() noremap = true, buffer = true, }, - watch_index = { interval = 1000 }, + watch_gitdir = { interval = 1000 }, sign_priority = 6, update_debounce = 200, status_formatter = nil, -- Use default -- cgit v1.2.3 From 810fc26fdf05504f813f049eb8d5277260e08d21 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 25 Sep 2021 18:39:12 +0200 Subject: fix: adjust layout after a regression in telescope (#1615) --- lua/core/telescope.lua | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lua') diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 34c1fb92..e24a976e 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -89,13 +89,8 @@ function M.find_lunarvim_files(opts) opts = opts or {} local themes = require "telescope.themes" local theme_opts = themes.get_ivy { - previewer = false, sorting_strategy = "ascending", layout_strategy = "bottom_pane", - layout_config = { - height = 5, - width = 0.5, - }, prompt = ">> ", prompt_title = "~ LunarVim files ~", cwd = utils.join_paths(get_runtime_dir(), "lvim"), -- cgit v1.2.3 From 64a5964b545ec7f3f78f725ec96cba553a496d9f Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 25 Sep 2021 20:47:50 +0330 Subject: update nvim-tree based on the refactor (#1617) --- lua/core/nvimtree.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'lua') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 6aa5401d..5007cf7c 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -57,16 +57,12 @@ function M.setup() end local g = vim.g - for opt, val in pairs(lvim.builtin.nvimtree) do - g["nvim_tree_" .. opt] = val - end - -- Implicitly update nvim-tree when project module is active if lvim.builtin.project.active then - vim.g.nvim_tree_update_cwd = 1 - vim.g.nvim_tree_respect_buf_cwd = 1 - vim.g.nvim_tree_disable_netrw = 0 - vim.g.nvim_tree_hijack_netrw = 0 + lvim.builtin.nvimtree.update_cwd = 1 + lvim.builtin.nvimtree.respect_buf_cwd = 1 + lvim.builtin.nvimtree.disable_netrw = 0 + lvim.builtin.nvimtree.hijack_netrw = 0 vim.g.netrw_banner = 0 end @@ -96,6 +92,7 @@ function M.setup() if lvim.builtin.nvimtree.on_config_done then lvim.builtin.nvimtree.on_config_done(nvim_tree_config) end + require("nvim-tree").setup(lvim.builtin.nvimtree) end function M.on_open() -- cgit v1.2.3 From 8009ff4fee6c46f2ea80b084447fe2052740c378 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 26 Sep 2021 09:37:06 +0330 Subject: fix: use the new nvim-tree syntax (#1619) --- lua/core/nvimtree.lua | 24 ++++++++++++++++-------- lua/onedarker/LSP.lua | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'lua') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 5007cf7c..44d3031f 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -6,6 +6,14 @@ function M.config() active = true, on_config_done = nil, side = "left", + setup = { + auto_open = 0, + auto_close = 1, + tab_open = 0, + update_focused_file = { + enable = 1, + }, + }, width = 30, show_icons = { git = 1, @@ -15,14 +23,10 @@ function M.config() tree_width = 30, }, ignore = { ".git", "node_modules", ".cache" }, - auto_open = 0, - auto_close = 1, quit_on_open = 0, - follow = 1, hide_dotfiles = 1, git_hl = 1, root_folder_modifier = ":t", - tab_open = 0, allow_resize = 1, lsp_diagnostics = 1, auto_ignore_ft = { "startify", "dashboard" }, @@ -57,12 +61,16 @@ function M.setup() end local g = vim.g + for opt, val in pairs(lvim.builtin.nvimtree) do + g["nvim_tree_" .. opt] = val + end + -- Implicitly update nvim-tree when project module is active if lvim.builtin.project.active then - lvim.builtin.nvimtree.update_cwd = 1 lvim.builtin.nvimtree.respect_buf_cwd = 1 - lvim.builtin.nvimtree.disable_netrw = 0 - lvim.builtin.nvimtree.hijack_netrw = 0 + lvim.builtin.nvimtree.setup.update_cwd = 1 + lvim.builtin.nvimtree.setup.disable_netrw = 0 + lvim.builtin.nvimtree.setup.hijack_netrw = 0 vim.g.netrw_banner = 0 end @@ -92,7 +100,7 @@ function M.setup() if lvim.builtin.nvimtree.on_config_done then lvim.builtin.nvimtree.on_config_done(nvim_tree_config) end - require("nvim-tree").setup(lvim.builtin.nvimtree) + require("nvim-tree").setup(lvim.builtin.nvimtree.setup) end function M.on_open() diff --git a/lua/onedarker/LSP.lua b/lua/onedarker/LSP.lua index 3d88338f..0ed133fe 100644 --- a/lua/onedarker/LSP.lua +++ b/lua/onedarker/LSP.lua @@ -50,6 +50,7 @@ local LSP = { NvimTreeImageFile = { fg = C.purple }, NvimTreeSpecialFile = { fg = C.orange }, NvimTreeGitStaged = { fg = C.sign_add }, + NvimTreeCursorLine = { bg = C.bg }, NvimTreeGitNew = { fg = C.sign_add }, NvimTreeGitDirty = { fg = C.sign_add }, NvimTreeGitDeleted = { fg = C.sign_delete }, -- cgit v1.2.3 From 464f092ada7b6e54f5ad65aea0ae3c1b55f618f4 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 26 Sep 2021 10:47:42 +0330 Subject: Update highlights.lua --- lua/onedarker/highlights.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/onedarker/highlights.lua b/lua/onedarker/highlights.lua index ef4f2759..dbdd2416 100644 --- a/lua/onedarker/highlights.lua +++ b/lua/onedarker/highlights.lua @@ -17,7 +17,7 @@ local highlights = { Folded = { fg = C.accent, bg = C.alt_bg }, FoldColumn = { fg = C.accent, bg = C.alt_bg }, LineNr = { fg = C.context }, - FloatBoder = { fg = C.gray, bg = C.alt_bg }, + FloatBorder = { fg = C.gray, bg = C.alt_bg }, Whitespace = { fg = C.bg }, VertSplit = { fg = C.bg, bg = C.fg }, CursorLine = { bg = C.dark }, -- cgit v1.2.3 From 61b56a7bb19771247fc2c40b453d0f905581125e Mon Sep 17 00:00:00 2001 From: Subho Banerjee Date: Sun, 26 Sep 2021 02:20:50 -0500 Subject: fix: Adding `Diff*` highlight groups in onedarker (#1594) Fixes #1576 --- lua/onedarker/diff.lua | 12 ++++++++++++ lua/onedarker/init.lua | 2 ++ lua/onedarker/palette.lua | 5 +++++ 3 files changed, 19 insertions(+) create mode 100644 lua/onedarker/diff.lua (limited to 'lua') diff --git a/lua/onedarker/diff.lua b/lua/onedarker/diff.lua new file mode 100644 index 00000000..49463daa --- /dev/null +++ b/lua/onedarker/diff.lua @@ -0,0 +1,12 @@ +local diff = { + DiffAdd = { fg = C.none, bg = C.diff_add }, + DiffDelete = { fg = C.none, bg = C.diff_delete }, + DiffChange = { fg = C.none, bg = C.diff_change, style = "bold" }, + DiffText = { fg = C.none, bg = C.diff_text }, + DiffAdded = { fg = C.green }, + DiffRemoved = { fg = C.red }, + DiffFile = { fg = C.cyan }, + DiffIndexLine = { fg = C.gray }, +} + +return diff diff --git a/lua/onedarker/init.lua b/lua/onedarker/init.lua index 852e0103..73043ac3 100644 --- a/lua/onedarker/init.lua +++ b/lua/onedarker/init.lua @@ -15,6 +15,7 @@ local markdown = require "onedarker.markdown" local Whichkey = require "onedarker.Whichkey" local Git = require "onedarker.Git" local LSP = require "onedarker.LSP" +local diff = require "onedarker.diff" local skeletons = { highlights, @@ -23,6 +24,7 @@ local skeletons = { Whichkey, Git, LSP, + diff, } for _, skeleton in ipairs(skeletons) do diff --git a/lua/onedarker/palette.lua b/lua/onedarker/palette.lua index c3116b1e..ab15d392 100644 --- a/lua/onedarker/palette.lua +++ b/lua/onedarker/palette.lua @@ -1,4 +1,5 @@ local colors = { + none = "NONE", fg = "#abb2bf", bg = "#1f2227", alt_bg = "#282c34", @@ -34,6 +35,10 @@ local colors = { purple_test = "#ff007c", cyan_test = "#00dfff", ui_blue = "#264F78", + diff_add = "#303d27", + diff_delete = "#6e3b40", + diff_change = "#18344c", + diff_text = "#265478", } return colors -- cgit v1.2.3 From 1d96533f17103fc05f2b64921137bba11224e6b0 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 26 Sep 2021 13:33:54 +0330 Subject: lsp_diagnostics is part of the nvim-tree setup now (#1623) --- lua/core/nvimtree.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 44d3031f..dfcbb1fa 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -13,6 +13,7 @@ function M.config() update_focused_file = { enable = 1, }, + lsp_diagnostics = 1, }, width = 30, show_icons = { @@ -28,7 +29,6 @@ function M.config() git_hl = 1, root_folder_modifier = ":t", allow_resize = 1, - lsp_diagnostics = 1, auto_ignore_ft = { "startify", "dashboard" }, icons = { default = "", -- cgit v1.2.3 From 62b805448d1fdb9236ee6b4da41e3d7ef1acc8df Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 26 Sep 2021 20:06:34 +0330 Subject: migrate nvim-tree to setup syntax episode 4 :cry: (#1627) --- lua/core/nvimtree.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index dfcbb1fa..db017fd0 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -5,7 +5,6 @@ function M.config() lvim.builtin.nvimtree = { active = true, on_config_done = nil, - side = "left", setup = { auto_open = 0, auto_close = 1, @@ -14,8 +13,15 @@ function M.config() enable = 1, }, lsp_diagnostics = 1, + view = { + width = 30, + side = "left", + auto_resize = false, + mappings = { + custom_only = false, + }, + }, }, - width = 30, show_icons = { git = 1, folders = 1, @@ -76,8 +82,8 @@ function M.setup() local tree_cb = nvim_tree_config.nvim_tree_callback - if not g.nvim_tree_bindings then - g.nvim_tree_bindings = { + if not lvim.builtin.nvimtree.setup.view.mappings.list then + lvim.builtin.nvimtree.setup.view.mappings.list = { { key = { "l", "", "o" }, cb = tree_cb "edit" }, { key = "h", cb = tree_cb "close_node" }, { key = "v", cb = tree_cb "vsplit" }, -- cgit v1.2.3 From 238bbf18ac4e35152be06736c75e94a81e3382e8 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 26 Sep 2021 21:11:44 +0330 Subject: fix small bugs in nvim-tree (#1629) --- lua/core/nvimtree.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index db017fd0..8d3b1b6a 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -110,8 +110,8 @@ function M.setup() end function M.on_open() - if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.side == "left" then - require("bufferline.state").set_offset(lvim.builtin.nvimtree.width + 1, "") + if package.loaded["bufferline.state"] and lvim.builtin.nvimtree.setup.view.side == "left" then + require("bufferline.state").set_offset(lvim.builtin.nvimtree.setup.view.width + 1, "") end end -- cgit v1.2.3 From 6b79e00cb04bf889fc30b84482d6db6e951ca9e9 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Tue, 28 Sep 2021 23:59:50 +0330 Subject: pin barbar to fix #1636 --- lua/plugins.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index 178fb99e..adebe492 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -139,6 +139,7 @@ return { { "romgrk/barbar.nvim", + commit = "7a19aac3d401c997a6fb7067a7756a4a77184c2e", config = function() require("core.bufferline").setup() end, -- cgit v1.2.3 From 974061729256d2a965cad0f1bc133eb2debc7867 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 29 Sep 2021 09:31:45 +0330 Subject: barbar is fixed upstream --- lua/plugins.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'lua') diff --git a/lua/plugins.lua b/lua/plugins.lua index adebe492..178fb99e 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -139,7 +139,6 @@ return { { "romgrk/barbar.nvim", - commit = "7a19aac3d401c997a6fb7067a7756a4a77184c2e", config = function() require("core.bufferline").setup() end, -- cgit v1.2.3 From 35d5615ecc2366ec5de4ce0fecd75fb426216ea0 Mon Sep 17 00:00:00 2001 From: Xavier Young <45989017+younger-1@users.noreply.github.com> Date: Thu, 30 Sep 2021 13:42:10 +0800 Subject: fix: can't open lvim log file cause by `lvim.log.viewer.cmd` (#1638) --- lua/core/terminal.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 4525ca63..418dc2c4 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -112,8 +112,14 @@ M.toggle_log_view = function(name) if not logfile then return end + + local log_viewer = lvim.log.viewer.cmd + if vim.fn.executable(log_viewer) ~= 1 then + log_viewer = "less +F" + end + log_viewer = log_viewer .. " " .. logfile local term_opts = vim.tbl_deep_extend("force", lvim.builtin.terminal, { - cmd = lvim.log.viewer.cmd .. " " .. logfile, + cmd = log_viewer, open_mapping = lvim.log.viewer.layout_config.open_mapping, direction = lvim.log.viewer.layout_config.direction, -- TODO: this might not be working as expected -- cgit v1.2.3 From 8ec92c0420374097f1a617fe91cd6f6a5503c5b0 Mon Sep 17 00:00:00 2001 From: Subho Banerjee Date: Thu, 30 Sep 2021 02:31:59 -0500 Subject: Feature: Define signs for Dap (#1642) --- lua/core/dap.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lua') diff --git a/lua/core/dap.lua b/lua/core/dap.lua index 5de3b7c4..d9b59641 100644 --- a/lua/core/dap.lua +++ b/lua/core/dap.lua @@ -10,6 +10,18 @@ M.config = function() linehl = "", numhl = "", }, + breakpoint_rejected = { + text = "", + texthl = "LspDiagnosticsSignHint", + linehl = "", + numhl = "", + }, + stopped = { + text = "", + texthl = "LspDiagnosticsSignInformation", + linehl = "DiagnosticUnderlineInfo", + numhl = "LspDiagnosticsSignInformation", + }, } end @@ -17,6 +29,9 @@ M.setup = function() local dap = require "dap" vim.fn.sign_define("DapBreakpoint", lvim.builtin.dap.breakpoint) + vim.fn.sign_define("DapBreakpointRejected", lvim.builtin.dap.breakpoint_rejected) + vim.fn.sign_define("DapStopped", lvim.builtin.dap.stopped) + dap.defaults.fallback.terminal_win_cmd = "50vsplit new" lvim.builtin.which_key.mappings["d"] = { -- cgit v1.2.3 From a273c46eee751de4a61360ae0076ed4dac433e5d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 1 Oct 2021 13:27:06 +0200 Subject: feat: add LvimUpdate command (#1634) * feat: add prelimenary LvimUpdate command * feat: use native process management * feat: add a telescope change-log utility * fix: update readme to include the new command --- lua/bootstrap.lua | 96 +++++++++++++++++++++++++++++++++++++++++++++++++- lua/core/commands.lua | 2 ++ lua/core/telescope.lua | 45 +++++++++++++++++++++++ lua/core/which-key.lua | 5 +++ lua/utils/init.lua | 14 +------- 5 files changed, 148 insertions(+), 14 deletions(-) (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index ff6d9cdf..7f8f97ed 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -1,5 +1,7 @@ local M = {} --- It's not safe to require 'utils' without adjusting the runtimepath + +---Join path segments that were passed as input +---@return string function _G.join_paths(...) local uv = vim.loop local path_sep = uv.os_uname().version:match "Windows" and "\\" or "/" @@ -7,6 +9,8 @@ function _G.join_paths(...) return result end +---Get the full path to `$LUNARVIM_RUNTIME_DIR` +---@return string function _G.get_runtime_dir() local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" if not lvim_runtime_dir then @@ -16,6 +20,8 @@ function _G.get_runtime_dir() return lvim_runtime_dir end +---Get the full path to `$LUNARVIM_CONFIG_DIR` +---@return string function _G.get_config_dir() local lvim_config_dir = os.getenv "LUNARVIM_CONFIG_DIR" if not lvim_config_dir then @@ -24,6 +30,8 @@ function _G.get_config_dir() return lvim_config_dir end +---Get the full path to `$LUNARVIM_CACHE_DIR` +---@return string function _G.get_cache_dir() local lvim_cache_dir = os.getenv "LUNARVIM_CACHE_DIR" if not lvim_cache_dir then @@ -32,7 +40,11 @@ function _G.get_cache_dir() return lvim_cache_dir end +---Get currently installed version of LunarVim +---@param type string can be "short" +---@return string function _G.get_version(type) + type = type or "" local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tags") if string.match(lvim_full_ver, "%d") == nil then @@ -45,10 +57,13 @@ function _G.get_version(type) end end +---Initialize the `&runtimepath` variables and prepare for startup +---@return table function M:init() self.runtime_dir = get_runtime_dir() self.config_dir = get_config_dir() self.cache_path = get_cache_dir() + self.repo_dir = join_paths(self.runtime_dir, "lvim") self.pack_dir = join_paths(self.runtime_dir, "site", "pack") self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim") @@ -92,4 +107,83 @@ function M:init() return self end +---Update LunarVim +---pulls the latest changes from github and, resets the startup cache +function M:update() + M:update_repo() + M:reset_cache() + vim.schedule(function() + -- TODO: add a changelog + vim.notify("Update complete", vim.log.levels.INFO) + end) +end + +local function git_cmd(subcmd) + local Job = require "plenary.job" + local Log = require "core.log" + local repo_dir = join_paths(get_runtime_dir(), "lvim") + local args = { "-C", repo_dir } + vim.list_extend(args, subcmd) + + local stderr = {} + local stdout, ret = Job + :new({ + command = "git", + args = args, + cwd = repo_dir, + on_stderr = function(_, data) + table.insert(stderr, data) + end, + }) + :sync() + + if not vim.tbl_isempty(stderr) then + Log:debug(stderr) + end + + if not vim.tbl_isempty(stdout) then + Log:debug(stdout) + end + + return ret +end + +---pulls the latest changes from github +function M:update_repo() + local Log = require "core.log" + local sub_commands = { + fetch = { "fetch" }, + diff = { "diff", "--quiet", "@{upstream}" }, + merge = { "merge", "--ff-only", "--progress" }, + } + Log:info "Checking for updates" + + local ret = git_cmd(sub_commands.fetch) + if ret ~= 0 then + error "Update failed! Check the log for further information" + end + + ret = git_cmd(sub_commands.diff) + + if ret == 0 then + Log:info "LunarVim is already up-to-date" + return + end + + ret = git_cmd(sub_commands.merge) + + if ret ~= 0 then + error "Error: unable to guarantee data integrity while updating your branch" + error "Please pull the changes manually instead." + end +end + +---Reset any startup cache files used by Packer and Impatient +---Tip: Useful for clearing any outdated settings +function M:reset_cache() + _G.__luacache.clear_cache() + _G.__luacache.save_cache() + require("plugin-loader"):cache_reset() +end + return M diff --git a/lua/core/commands.lua b/lua/core/commands.lua index 22170c85..f732c9a2 100644 --- a/lua/core/commands.lua +++ b/lua/core/commands.lua @@ -12,6 +12,8 @@ M.defaults = { ]], -- :LvimInfo [[command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype)]], + [[ command! LvimCacheReset lua require('bootstrap').reset_cache() ]], + [[ command! LvimUpdate lua require('bootstrap').update() ]], } M.load = function(commands) diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index e24a976e..eba27eec 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -114,6 +114,51 @@ function M.grep_lunarvim_files(opts) require("telescope.builtin").live_grep(opts) end +function M.view_lunarvim_changelog() + local finders = require "telescope.finders" + local make_entry = require "telescope.make_entry" + local pickers = require "telescope.pickers" + local previewers = require "telescope.previewers" + local actions = require "telescope.actions" + local opts = {} + + local conf = require("telescope.config").values + opts.entry_maker = make_entry.gen_from_git_commits(opts) + + pickers.new(opts, { + prompt_title = "LunarVim changelog", + + finder = finders.new_oneshot_job( + vim.tbl_flatten { + "git", + "log", + "--pretty=oneline", + "--abbrev-commit", + "--", + ".", + }, + opts + ), + previewer = { + previewers.git_commit_diff_to_parent.new(opts), + previewers.git_commit_diff_to_head.new(opts), + previewers.git_commit_diff_as_was.new(opts), + previewers.git_commit_message.new(opts), + }, + + --TODO: consider opening a diff view when pressing enter + attach_mappings = function(_, map) + map("i", "", actions._close) + map("n", "", actions._close) + map("i", "", actions._close) + map("n", "", actions._close) + map("n", "q", actions._close) + return true + end, + sorter = conf.file_sorter(opts), + }):find() +end + function M.setup() local telescope = require "telescope" diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 36949467..2e528048 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -192,6 +192,10 @@ M.config = function() "lua require('core.info').toggle_popup(vim.bo.filetype)", "Toggle LunarVim Info", }, + I = { + "lua require('core.telescope').view_lunarvim_changelog()", + "View LunarVim's changelog", + }, l = { name = "+logs", d = { @@ -210,6 +214,7 @@ M.config = function() P = { "exe 'edit '.stdpath('cache').'/packer.nvim.log'", "Open the Packer logfile" }, }, r = { "lua require('utils').reload_lv_config()", "Reload configurations" }, + u = { "LvimUpdate", "Update LunarVim" }, }, s = { name = "Search", diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 5a5e4ba3..7f8e1f77 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -140,19 +140,7 @@ function utils.is_file(filename) return stat and stat.type == "file" or false end -function utils.join_paths(...) - local path_sep = vim.loop.os_uname().version:match "Windows" and "\\" or "/" - local result = table.concat(vim.tbl_flatten { ... }, path_sep):gsub(path_sep .. "+", path_sep) - return result -end - -function utils.lvim_cache_reset() - _G.__luacache.clear_cache() - _G.__luacache.save_cache() - require("plugin-loader"):cache_reset() -end - -vim.cmd [[ command! LvimCacheReset lua require('utils').lvim_cache_reset() ]] +utils.join_paths = _G.join_paths return utils -- cgit v1.2.3 From 1e0d0181d55abe1e4248b3aeaded94cbf3308168 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 2 Oct 2021 18:04:38 +0330 Subject: feat: make lsp highlight color configurable (#1659) --- lua/lsp/init.lua | 3 --- lua/onedarker/LSP.lua | 3 +++ lua/onedarker/palette.lua | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 3c921e65..386be075 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -9,9 +9,6 @@ local function lsp_highlight_document(client) if client.resolved_capabilities.document_highlight then vim.api.nvim_exec( [[ - hi LspReferenceRead cterm=bold ctermbg=red guibg=#353d46 - hi LspReferenceText cterm=bold ctermbg=red guibg=#353d46 - hi LspReferenceWrite cterm=bold ctermbg=red guibg=#353d46 augroup lsp_document_highlight autocmd! * autocmd CursorHold lua vim.lsp.buf.document_highlight() diff --git a/lua/onedarker/LSP.lua b/lua/onedarker/LSP.lua index 0ed133fe..82b9f799 100644 --- a/lua/onedarker/LSP.lua +++ b/lua/onedarker/LSP.lua @@ -35,6 +35,9 @@ local LSP = { DiagnosticUnderlineWarn = { style = "underline" }, DiagnosticUnderlineInfo = { style = "underline" }, DiagnosticUnderlineHint = { style = "underline" }, + LspReferenceRead = { bg = C.fg_gutter, style = "bold" }, + LspReferenceText = { bg = C.fg_gutter, style = "bold" }, + LspReferenceWrite = { bg = C.fg_gutter, style = "bold" }, QuickScopePrimary = { fg = C.purple_test, style = "underline" }, QuickScopeSecondary = { fg = C.cyan_test, style = "underline" }, TelescopeSelection = { fg = C.hint_blue }, diff --git a/lua/onedarker/palette.lua b/lua/onedarker/palette.lua index ab15d392..81ea3af3 100644 --- a/lua/onedarker/palette.lua +++ b/lua/onedarker/palette.lua @@ -6,6 +6,7 @@ local colors = { dark = "#282c34", accent = "#BBBBBB", dark_gray = "#2a2f3e", + fg_gutter = "#353d46", context = "#4b5263", popup_back = "#282c34", search_orange = "#613214", -- cgit v1.2.3 From 3e1cd1ec235404ae96ed2d0756729cf44ae48f3e Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 14:32:09 +0200 Subject: fix: add missing lsp.log entry in log_viewer (#1666) --- lua/core/terminal.lua | 26 ++------------------------ lua/core/which-key.lua | 13 ++++++++----- 2 files changed, 10 insertions(+), 29 deletions(-) (limited to 'lua') diff --git a/lua/core/terminal.lua b/lua/core/terminal.lua index 418dc2c4..3a0c6e46 100644 --- a/lua/core/terminal.lua +++ b/lua/core/terminal.lua @@ -1,5 +1,4 @@ local M = {} -local utils = require "utils" local Log = require "core.log" M.config = function() @@ -90,29 +89,9 @@ M._exec_toggle = function(exec) exec_term:toggle() end -local function get_log_path(name) - --handle custom paths not managed by Plenary.log - local file - if name == "nvim" then - file = utils.join_paths(vim.fn.stdpath "cache", "log") - elseif name == "packer.nvim" then - file = utils.join_paths(vim.fn.stdpath "cache", "packer.nvim.log") - else - file = Log:get_path() - end - if utils.is_file(file) then - return file - end -end - ---Toggles a log viewer according to log.viewer.layout_config ----@param name can be the name of any of the managed logs, e,g. "lunarvim" or the default ones {"nvim", "lsp", "packer.nvim"} -M.toggle_log_view = function(name) - local logfile = get_log_path(name) - if not logfile then - return - end - +---@param logfile string the fullpath to the logfile +M.toggle_log_view = function(logfile) local log_viewer = lvim.log.viewer.cmd if vim.fn.executable(log_viewer) ~= 1 then log_viewer = "less +F" @@ -129,7 +108,6 @@ M.toggle_log_view = function(name) local Terminal = require("toggleterm.terminal").Terminal local log_view = Terminal:new(term_opts) - -- require("core.log"):debug("term", vim.inspect(term_opts)) log_view:toggle() end diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 2e528048..27cec37c 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -199,14 +199,17 @@ M.config = function() l = { name = "+logs", d = { - "lua require('core.terminal').toggle_log_view('lunarvim')", + "lua require('core.terminal').toggle_log_view(require('core.log').get_path())", "view default log", }, - D = { "exe 'edit '.stdpath('cache').'/lunarvim.log'", "Open the default logfile" }, - n = { "lua require('core.terminal').toggle_log_view('lsp')", "view lsp log" }, + D = { "lua vim.fn.execute('edit ' .. require('core.log').get_path())", "Open the default logfile" }, + l = { "lua require('core.terminal').toggle_log_view(vim.lsp.get_log_path())", "view lsp log" }, + L = { "lua vim.fn.execute('edit ' .. vim.lsp.get_log_path())", "Open the LSP logfile" }, + n = { + "lua require('core.terminal').toggle_log_view(os.getenv('NVIM_LOG_FILE'))", + "view neovim log", + }, N = { "edit $NVIM_LOG_FILE", "Open the Neovim logfile" }, - l = { "lua require('core.terminal').toggle_log_view('nvim')", "view neovim log" }, - L = { "exe 'edit '.stdpath('cache').'/lsp.log'", "Open the LSP logfile" }, p = { "lua require('core.terminal').toggle_log_view('packer.nvim')", "view packer log", -- cgit v1.2.3 From d01ba08eaec1640ac2d038893525b3ba0af25813 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 16:13:46 +0200 Subject: refactor: auto-generate language configuration (#1584) Refactor the monolithic `lvim.lang` design into a more modular approach. IMPORTANT: run `:LvimUpdate` in order to generate the new ftplugin template files. --- lua/bootstrap.lua | 4 +- lua/config/defaults.lua | 1164 +------------------------------------ lua/config/init.lua | 100 ++++ lua/core/builtins/init.lua | 1 - lua/core/cmp.lua | 30 +- lua/core/info.lua | 87 ++- lua/core/log.lua | 1 + lua/core/lspinstall.lua | 19 - lua/core/lualine/components.lua | 3 - lua/core/which-key.lua | 2 +- lua/lsp/config.lua | 27 + lua/lsp/init.lua | 102 +--- lua/lsp/kind.lua | 31 - lua/lsp/manager.lua | 82 +++ lua/lsp/null-ls/formatters.lua | 30 +- lua/lsp/null-ls/init.lua | 54 +- lua/lsp/null-ls/linters.lua | 30 +- lua/lsp/null-ls/services.lua | 15 + lua/lsp/providers/jsonls.lua | 30 + lua/lsp/providers/sumneko_lua.lua | 19 + lua/lsp/providers/vuels.lua | 26 + lua/lsp/templates.lua | 98 ++++ lua/lsp/utils.lua | 57 +- lua/plugins.lua | 7 +- lua/utils/init.lua | 100 +++- 25 files changed, 673 insertions(+), 1446 deletions(-) delete mode 100644 lua/core/lspinstall.lua create mode 100644 lua/lsp/config.lua delete mode 100644 lua/lsp/kind.lua create mode 100644 lua/lsp/manager.lua create mode 100644 lua/lsp/providers/jsonls.lua create mode 100644 lua/lsp/providers/sumneko_lua.lua create mode 100644 lua/lsp/providers/vuels.lua create mode 100644 lua/lsp/templates.lua (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 7f8f97ed..fb2099ce 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -85,9 +85,10 @@ function M:init() vim.cmd("set spellfile=" .. join_paths(self.config_dir, "spell", "en.utf-8.add")) end + vim.fn.mkdir(vim.fn.stdpath "cache", "p") + -- FIXME: currently unreliable in unit-tests if not os.getenv "LVIM_TEST_ENV" then - vim.fn.mkdir(vim.fn.stdpath "cache", "p") require("impatient").setup { path = vim.fn.stdpath "cache" .. "/lvim_cache", enable_profiling = true, @@ -112,6 +113,7 @@ end function M:update() M:update_repo() M:reset_cache() + require("lsp.templates").generate_templates() vim.schedule(function() -- TODO: add a changelog vim.notify("Update complete", vim.log.levels.INFO) diff --git a/lua/config/defaults.lua b/lua/config/defaults.lua index a67a9c53..f030234d 100644 --- a/lua/config/defaults.lua +++ b/lua/config/defaults.lua @@ -1,7 +1,5 @@ local home_dir = vim.loop.os_homedir() local utils = require "utils" --- FIXME: stop using hard-coded paths for LspInstall -local ls_install_prefix = vim.fn.stdpath "data" .. "/lspinstall" lvim = { leader = "space", @@ -30,1170 +28,10 @@ lvim = { }, }, }, - - lsp = { - completion = { - item_kind = { - "  (Text) ", - "  (Method)", - "  (Function)", - "  (Constructor)", - "  (Field)", - "  (Variable)", - "  (Class)", - " ﰮ (Interface)", - "  (Module)", - "  (Property)", - " 塞 (Unit)", - "  (Value)", - " 練 (Enum)", - "  (Keyword)", - "  (Snippet)", - "  (Color)", - "  (File)", - "  (Reference)", - "  (Folder)", - "  (EnumMember)", - " ﲀ (Constant)", - "  (Struct)", - "  (Event)", - "  (Operator)", - "  (TypeParameter)", - }, - }, - diagnostics = { - signs = { - active = true, - values = { - { name = "LspDiagnosticsSignError", text = "" }, - { name = "LspDiagnosticsSignWarning", text = "" }, - { name = "LspDiagnosticsSignHint", text = "" }, - { name = "LspDiagnosticsSignInformation", text = "" }, - }, - }, - virtual_text = { - prefix = "", - spacing = 0, - }, - update_in_insert = false, - underline = true, - severity_sort = true, - }, - override = {}, - document_highlight = true, - popup_border = "single", - on_attach_callback = nil, - on_init_callback = nil, - null_ls = { - setup = {}, - }, - }, - plugins = { -- use config.lua for this not put here }, autocommands = {}, -} - -local schemas = nil -local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") -if status_ok then - schemas = jsonls_settings.get_default_schemas() -end - --- TODO move all of this into lang specific files, only require when using -lvim.lang = { - asm = { - formatters = { - -- { - -- exe = "asmfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "", - setup = {}, - }, - }, - beancount = { - formatters = { - -- { - -- exe = "bean_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "beancount", - setup = { - cmd = { "beancount-langserver" }, - }, - }, - }, - bicep = { - formatters = {}, - linters = {}, - lsp = { - provider = "bicep", - setup = { - cmd = { - "dotnet", - ls_install_prefix .. "/bicep/Bicep.LangServer.dll", - }, - filetypes = { "bicep" }, - }, - }, - }, - c = { - formatters = { - -- { - -- exe = "clang_format", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "clangd", - setup = { - cmd = { - ls_install_prefix .. "/cpp/clangd/bin/clangd", - "--background-index", - "--header-insertion=never", - "--cross-file-rename", - "--clang-tidy", - "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", - }, - }, - }, - }, - cpp = { - formatters = { - -- { - -- exe = "clang_format", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "clangd", - setup = { - cmd = { - ls_install_prefix .. "/cpp/clangd/bin/clangd", - "--background-index", - "--header-insertion=never", - "--cross-file-rename", - "--clang-tidy", - "--clang-tidy-checks=-*,llvm-*,clang-analyzer-*", - }, - }, - }, - }, - crystal = { - formatters = { - -- { - -- exe = "crystal_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "crystalline", - setup = { - cmd = { "crystalline" }, - }, - }, - }, - cs = { - formatters = { - -- { - -- exe = "clang_format ", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "omnisharp", - setup = { - cmd = { - ls_install_prefix .. "/csharp/omnisharp/run", - "--languageserver", - "--hostPID", - tostring(vim.fn.getpid()), - }, - }, - }, - }, - cmake = { - formatters = { - -- { - -- exe = "cmake_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "cmake", - setup = { - cmd = { - ls_install_prefix .. "/cmake/venv/bin/cmake-language-server", - }, - }, - }, - }, - clojure = { - formatters = {}, - linters = {}, - lsp = { - provider = "clojure_lsp", - setup = { - cmd = { - ls_install_prefix .. "/clojure/clojure-lsp", - }, - }, - }, - }, - css = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "cssls", - setup = { - cmd = { - "node", - ls_install_prefix .. "/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", - "--stdio", - }, - }, - }, - }, - less = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "cssls", - setup = { - cmd = { - "node", - ls_install_prefix .. "/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js", - "--stdio", - }, - }, - }, - }, - d = { - formatters = { - -- { - -- exe = "dfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "serve_d", - setup = { - cmd = { "serve-d" }, - }, - }, - }, - dart = { - formatters = { - -- { - -- exe = "dart_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "dartls", - setup = { - cmd = { - "dart", - "/usr/lib/dart/bin/snapshots/analysis_server.dart.snapshot", - "--lsp", - }, - }, - }, - }, - dockerfile = { - formatters = {}, - linters = {}, - lsp = { - provider = "dockerls", - setup = { - cmd = { - ls_install_prefix .. "/dockerfile/node_modules/.bin/docker-langserver", - "--stdio", - }, - }, - }, - }, - elixir = { - formatters = { - -- { - -- exe = "mix", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "elixirls", - setup = { - cmd = { - ls_install_prefix .. "/elixir/elixir-ls/language_server.sh", - }, - }, - }, - }, - elm = { - formatters = { - -- { - -- exe = "elm_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "elmls", - setup = { - cmd = { - ls_install_prefix .. "/elm/node_modules/.bin/elm-language-server", - }, - -- init_options = { - -- elmAnalyseTrigger = "change", - -- elmFormatPath = ls_install_prefix .. "/elm/node_modules/.bin/elm-format", - -- elmPath = ls_install_prefix .. "/elm/node_modules/.bin/", - -- elmTestPath = ls_install_prefix .. "/elm/node_modules/.bin/elm-test", - -- }, - }, - }, - }, - erlang = { - formatters = { - -- { - -- exe = "erlfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "erlangls", - setup = { - cmd = { - "erlang_ls", - }, - }, - }, - }, - emmet = { active = false }, - fish = { - formatters = { - -- { - -- exe = "fish_indent", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "", - setup = {}, - }, - }, - fortran = { - formatters = {}, - linters = {}, - lsp = { - provider = "fortls", - setup = { - cmd = { - ls_install_prefix .. "/fortran/venv/bin/fortls", - }, - }, - }, - }, - go = { - formatters = { - -- { - -- exe = "gofmt", - -- args = {}, - -- }, - -- { - -- exe = "goimports", - -- args = {}, - -- }, - -- { - -- exe = "gofumpt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "gopls", - setup = { - cmd = { - ls_install_prefix .. "/go/gopls", - }, - }, - }, - }, - graphql = { - formatters = {}, - linters = {}, - lsp = { - provider = "graphql", - setup = { - cmd = { - "graphql-lsp", - "server", - "-m", - "stream", - }, - }, - }, - }, - haskell = { - formatters = {}, - linters = {}, - lsp = { - provider = "hls", - setup = { - cmd = { ls_install_prefix .. "/haskell/hls" }, - }, - }, - }, - html = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "html", - setup = { - cmd = { - "node", - ls_install_prefix .. "/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js", - "--stdio", - }, - }, - }, - }, - java = { - formatters = { - -- { - -- exe = "clang_format", - -- args = {}, - -- }, - -- { - -- exe = "uncrustify", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "jdtls", - setup = { - cmd = { ls_install_prefix .. "/java/jdtls.sh" }, - }, - }, - }, - json = { - formatters = { - -- { - -- exe = "json_tool", - -- args = {}, - -- }, - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "jsonls", - setup = { - cmd = { - "node", - ls_install_prefix .. "/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js", - "--stdio", - }, - settings = { - json = { - schemas = schemas, - -- = { - -- { - -- fileMatch = { "package.json" }, - -- url = "https://json.schemastore.org/package.json", - -- }, - -- }, - }, - }, - commands = { - Format = { - function() - vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) - end, - }, - }, - }, - }, - }, - julia = { - formatters = {}, - linters = {}, - lsp = { - provider = "julials", - setup = { - { - "julia", - "--startup-file=no", - "--history-file=no", - -- self.runtime_dir .. "lvim/utils/julia/run.jl", - }, - }, - }, - }, - kotlin = { - formatters = {}, - linters = {}, - lsp = { - provider = "kotlin_language_server", - setup = { - cmd = { - ls_install_prefix .. "/kotlin/server/bin/kotlin-language-server", - }, - root_dir = function(fname) - local util = require "lspconfig/util" - - local root_files = { - "settings.gradle", -- Gradle (multi-project) - "settings.gradle.kts", -- Gradle (multi-project) - "build.xml", -- Ant - "pom.xml", -- Maven - } - - local fallback_root_files = { - "build.gradle", -- Gradle - "build.gradle.kts", -- Gradle - } - return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname) - end, - }, - }, - }, - lua = { - formatters = { - -- { - -- exe = "stylua", - -- args = {}, - -- }, - -- { - -- exe = "lua_format", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "sumneko_lua", - setup = { - cmd = { - ls_install_prefix .. "/lua/sumneko-lua-language-server", - "-E", - ls_install_prefix .. "/lua/main.lua", - }, - settings = { - Lua = { - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim", "lvim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = { - [require("utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true, - [vim.fn.expand "$VIMRUNTIME/lua"] = true, - [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, - }, - maxPreload = 100000, - preloadFileSize = 10000, - }, - }, - }, - }, - }, - }, - nginx = { - formatters = { - -- { - -- exe = "nginx_beautifier", - -- args = { - -- provider = "", - -- setup = {}, - -- }, - -- }, - }, - linters = {}, - lsp = {}, - }, - perl = { - formatters = { - -- { - -- exe = "perltidy", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "", - setup = {}, - }, - }, - solidity = { - formatters = {}, - linters = {}, - lsp = { - provider = "solang", - setup = { - cmd = { "solang", "--language-server" }, - }, - }, - }, - sql = { - formatters = { - -- { - -- exe = "sqlformat", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "sqls", - setup = { - cmd = { "sqls" }, - }, - }, - }, - php = { - formatters = { - -- { - -- exe = "phpcbf", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "intelephense", - setup = { - cmd = { - ls_install_prefix .. "/php/node_modules/.bin/intelephense", - "--stdio", - }, - filetypes = { "php", "phtml" }, - settings = { - intelephense = { - environment = { - phpVersion = "7.4", - }, - }, - }, - }, - }, - }, - puppet = { - formatters = {}, - linters = {}, - lsp = { - provider = "puppet", - setup = { - cmd = { - ls_install_prefix .. "/puppet/puppet-editor-services/puppet-languageserver", - "--stdio", - }, - }, - }, - }, - javascript = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - -- @usage can be {"eslint"} or {"eslint_d"} - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - }, - }, - }, - javascriptreact = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - }, - }, - }, - python = { - formatters = { - -- { - -- exe = "yapf", - -- args = {}, - -- }, - -- { - -- exe = "isort", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "pyright", - setup = { - cmd = { - ls_install_prefix .. "/python/node_modules/.bin/pyright-langserver", - "--stdio", - }, - }, - }, - }, - -- R -e 'install.packages("formatR",repos = "http://cran.us.r-project.org")' - -- R -e 'install.packages("readr",repos = "http://cran.us.r-project.org")' - r = { - formatters = { - -- { - -- exe = "format_r", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "r_language_server", - setup = { - cmd = { - "R", - "--slave", - "-e", - "languageserver::run()", - }, - }, - }, - }, - ruby = { - formatters = { - -- { - -- exe = "rufo", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "solargraph", - setup = { - cmd = { - ls_install_prefix .. "/ruby/solargraph/solargraph", - "stdio", - }, - filetypes = { "ruby" }, - init_options = { - formatting = true, - }, - root_dir = function(fname) - local util = require("lspconfig").util - return util.root_pattern("Gemfile", ".git")(fname) - end, - settings = { - solargraph = { - diagnostics = true, - }, - }, - }, - }, - }, - rust = { - formatters = { - -- { - -- exe = "rustfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "rust_analyzer", - setup = { - cmd = { - ls_install_prefix .. "/rust/rust-analyzer", - }, - }, - }, - }, - scala = { - formatters = { - -- { - -- exe = "scalafmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "metals", - setup = {}, - }, - }, - sh = { - formatters = { - -- { - -- exe = "shfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "bashls", - setup = { - cmd = { - ls_install_prefix .. "/bash/node_modules/.bin/bash-language-server", - "start", - }, - }, - }, - }, - svelte = { - formatters = {}, - linters = {}, - lsp = { - provider = "svelte", - setup = { - cmd = { - ls_install_prefix .. "/svelte/node_modules/.bin/svelteserver", - "--stdio", - }, - }, - }, - }, - swift = { - formatters = { - -- { - -- exe = "swiftformat", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "sourcekit", - setup = { - cmd = { - "xcrun", - "sourcekit-lsp", - }, - }, - }, - }, - tailwindcss = { - lsp = { - active = false, - provider = "tailwindcss", - setup = { - cmd = { - ls_install_prefix .. "/tailwindcss/node_modules/.bin/tailwindcss-language-server", - "--stdio", - }, - }, - }, - }, - terraform = { - formatters = { - -- { - -- exe = "terraform_fmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "terraformls", - setup = { - cmd = { - ls_install_prefix .. "/terraform/terraform-ls", - "serve", - }, - }, - }, - }, - tex = { - formatters = {}, - linters = {}, - lsp = { - provider = "texlab", - setup = { - cmd = { ls_install_prefix .. "/latex/texlab" }, - }, - }, - }, - typescript = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - }, - }, - }, - typescriptreact = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - }, - -- @usage can be {"eslint"} or {"eslint_d"} - linters = {}, - lsp = { - provider = "tsserver", - setup = { - cmd = { - -- TODO: - ls_install_prefix .. "/typescript/node_modules/.bin/typescript-language-server", - "--stdio", - }, - }, - }, - }, - vim = { - formatters = {}, - linters = {}, - lsp = { - provider = "vimls", - setup = { - cmd = { - ls_install_prefix .. "/vim/node_modules/.bin/vim-language-server", - "--stdio", - }, - }, - }, - }, - vue = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - -- { - -- exe = "prettier_d_slim", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "vuels", - setup = { - cmd = { - ls_install_prefix .. "/vue/node_modules/.bin/vls", - }, - root_dir = function(fname) - local util = require "lspconfig/util" - return util.root_pattern "package.json"(fname) or util.root_pattern "vue.config.js"(fname) or vim.fn.getcwd() - end, - init_options = { - config = { - vetur = { - completion = { - autoImport = true, - tagCasing = "kebab", - useScaffoldSnippets = true, - }, - useWorkspaceDependencies = true, - validation = { - script = true, - style = true, - template = true, - }, - }, - }, - }, - }, - }, - }, - yaml = { - formatters = { - -- { - -- exe = "prettier", - -- args = {}, - -- }, - -- { - -- exe = "prettierd", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "yamlls", - setup = { - cmd = { - ls_install_prefix .. "/yaml/node_modules/.bin/yaml-language-server", - "--stdio", - }, - }, - }, - }, - zig = { - formatters = {}, - linters = {}, - lsp = { - provider = "zls", - setup = { - cmd = { - "zls", - }, - }, - }, - }, - gdscript = { - formatters = {}, - linters = {}, - lsp = { - provider = "gdscript", - setup = { - cmd = { - "nc", - "localhost", - "6008", - }, - }, - }, - }, - ps1 = { - formatters = {}, - linters = {}, - lsp = { - provider = "powershell_es", - setup = { - bundle_path = "", - }, - }, - }, - nix = { - formatters = { - -- { - -- exe = "nixfmt", - -- args = {}, - -- }, - }, - linters = {}, - lsp = { - provider = "rnix", - setup = { - cmd = { "rnix-lsp" }, - filetypes = { "nix" }, - init_options = {}, - settings = {}, - root_dir = function(fname) - local util = require "lspconfig/util" - return util.root_pattern ".git"(fname) or vim.fn.getcwd() - end, - }, - }, - }, + lang = {}, } diff --git a/lua/config/init.lua b/lua/config/init.lua index c09617bc..f0062560 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -22,6 +22,106 @@ function M:init(opts) local settings = require "config.settings" settings.load_options() + + local lvim_lsp_config = require "lsp.config" + lvim.lsp = vim.deepcopy(lvim_lsp_config) + + local supported_languages = { + "asm", + "bash", + "beancount", + "bibtex", + "bicep", + "c", + "c_sharp", + "clojure", + "cmake", + "comment", + "commonlisp", + "cpp", + "crystal", + "cs", + "css", + "cuda", + "d", + "dart", + "dockerfile", + "dot", + "elixir", + "elm", + "emmet", + "erlang", + "fennel", + "fish", + "fortran", + "gdscript", + "glimmer", + "go", + "gomod", + "graphql", + "haskell", + "hcl", + "heex", + "html", + "java", + "javascript", + "javascriptreact", + "jsdoc", + "json", + "json5", + "jsonc", + "julia", + "kotlin", + "latex", + "ledger", + "less", + "lua", + "markdown", + "nginx", + "nix", + "ocaml", + "ocaml_interface", + "perl", + "php", + "pioasm", + "ps1", + "puppet", + "python", + "ql", + "query", + "r", + "regex", + "rst", + "ruby", + "rust", + "scala", + "scss", + "sh", + "solidity", + "sparql", + "sql", + "supercollider", + "surface", + "svelte", + "swift", + "tailwindcss", + "terraform", + "tex", + "tlaplus", + "toml", + "tsx", + "turtle", + "typescript", + "typescriptreact", + "verilog", + "vim", + "vue", + "yaml", + "yang", + "zig", + } + + require("lsp.manager").init_defaults(supported_languages) end --- Override the configuration with a user provided one diff --git a/lua/core/builtins/init.lua b/lua/core/builtins/init.lua index dc9b5ff5..c3b3618f 100644 --- a/lua/core/builtins/init.lua +++ b/lua/core/builtins/init.lua @@ -15,7 +15,6 @@ local builtins = { "core.bufferline", "core.autopairs", "core.comment", - "core.lspinstall", "core.lualine", } diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua index 2bc724fb..965285c7 100644 --- a/lua/core/cmp.lua +++ b/lua/core/cmp.lua @@ -35,9 +35,35 @@ M.config = function() select = true, }, formatting = { + kind_icons = { + Class = " ", + Color = " ", + Constant = "ﲀ ", + Constructor = " ", + Enum = "練", + EnumMember = " ", + Event = " ", + Field = " ", + File = "", + Folder = " ", + Function = " ", + Interface = "ﰮ ", + Keyword = " ", + Method = " ", + Module = " ", + Operator = "", + Property = " ", + Reference = " ", + Snippet = " ", + Struct = " ", + Text = " ", + TypeParameter = " ", + Unit = "塞", + Value = " ", + Variable = " ", + }, format = function(entry, vim_item) - local icons = require("lsp.kind").icons - vim_item.kind = icons[vim_item.kind] + vim_item.kind = lvim.builtin.cmp.formatting.kind_icons[vim_item.kind] vim_item.menu = ({ nvim_lsp = "(LSP)", emoji = "(Emoji)", diff --git a/lua/core/info.lua b/lua/core/info.lua index b8d51a8c..ff024fa5 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -10,6 +10,7 @@ local M = { } local fmt = string.format +local text = require "interface.text" local function str_list(list) return fmt("[ %s ]", table.concat(list, ", ")) @@ -65,44 +66,55 @@ local function tbl_set_highlight(terms, highlight_group) end end +local function make_client_info(client) + local client_enabled_caps = require("lsp.utils").get_ls_capabilities(client.id) + local name = client.name + local id = client.id + local document_formatting = client.resolved_capabilities.document_formatting + local client_info = { + fmt("* Name: %s", name), + fmt("* Id: %s", tostring(id)), + fmt("* Supports formatting: %s", tostring(document_formatting)), + } + if not vim.tbl_isempty(client_enabled_caps) then + local caps_text = "* Capabilities list: " + local caps_text_len = caps_text:len() + local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") + enabled_caps = text.shift_right(enabled_caps, caps_text_len) + enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) + vim.list_extend(client_info, enabled_caps) + end + + return client_info +end + function M.toggle_popup(ft) local lsp_utils = require "lsp.utils" - local client = lsp_utils.get_active_client_by_ft(ft) - local is_client_active = false - local client_enabled_caps = {} - local client_name = "" - local client_id = 0 - local document_formatting = false - if client ~= nil then - is_client_active = not client.is_stopped() - client_enabled_caps = require("lsp").get_ls_capabilities(client.id) - client_name = client.name - client_id = client.id - document_formatting = client.resolved_capabilities.document_formatting - end + local clients = lsp_utils.get_active_client_by_ft(ft) + local client_names = {} local header = { fmt("Detected filetype: %s", ft), fmt("Treesitter active: %s", tostring(next(vim.treesitter.highlighter.active) ~= nil)), } - local text = require "interface.text" local lsp_info = { "Language Server Protocol (LSP) info", - fmt("* Associated server: %s", client_name), - fmt("* Active: %s (id: %d)", tostring(is_client_active), client_id), - fmt("* Supports formatting: %s", tostring(document_formatting)), + fmt "* Associated server(s):", } - if not vim.tbl_isempty(client_enabled_caps) then - local caps_text = "* Capabilities list: " - local caps_text_len = caps_text:len() - local enabled_caps = text.format_table(client_enabled_caps, 3, " | ") - enabled_caps = text.shift_right(enabled_caps, caps_text_len) - enabled_caps[1] = fmt("%s%s", caps_text, enabled_caps[1]:sub(caps_text_len + 1)) - vim.list_extend(lsp_info, enabled_caps) + + for _, client in pairs(clients) do + vim.list_extend(lsp_info, make_client_info(client)) + table.insert(client_names, client.name) end - local null_ls = require "lsp.null-ls" - local registered_providers = null_ls.list_supported_provider_names(ft) + + local null_formatters = require "lsp.null-ls.formatters" + local null_linters = require "lsp.null-ls.linters" + local registered_formatters = null_formatters.list_supported_names(ft) + local registered_linters = null_linters.list_supported_names(ft) + local registered_providers = {} + vim.list_extend(registered_providers, registered_formatters) + vim.list_extend(registered_providers, registered_linters) local registered_count = vim.tbl_count(registered_providers) local null_ls_info = { "Formatters and linters", @@ -113,24 +125,6 @@ function M.toggle_popup(ft) ), } - local null_formatters = require "lsp.null-ls.formatters" - local missing_formatters = null_formatters.list_unsupported_names(ft) - local missing_formatters_status = {} - if not vim.tbl_isempty(missing_formatters) then - missing_formatters_status = { - fmt("* Missing formatters: %s", table.concat(missing_formatters, "  , ") .. "  "), - } - end - - local null_linters = require "lsp.null-ls.linters" - local missing_linters = null_linters.list_unsupported_names(ft) - local missing_linters_status = {} - if not vim.tbl_isempty(missing_linters) then - missing_linters_status = { - fmt("* Missing linters: %s", table.concat(missing_linters, "  , ") .. "  "), - } - end - local content_provider = function(popup) local content = {} @@ -143,8 +137,6 @@ function M.toggle_popup(ft) lsp_info, { "" }, null_ls_info, - missing_formatters_status, - missing_linters_status, { "" }, { "" }, get_formatter_suggestion_msg(ft), @@ -167,11 +159,8 @@ function M.toggle_popup(ft) vim.cmd 'let m=matchadd("string", "true")' vim.cmd 'let m=matchadd("error", "false")' tbl_set_highlight(registered_providers, "LvimInfoIdentifier") - tbl_set_highlight(missing_formatters, "LvimInfoIdentifier") - tbl_set_highlight(missing_linters, "LvimInfoIdentifier") -- tbl_set_highlight(require("lsp.null-ls.formatters").list_available(ft), "LvimInfoIdentifier") -- tbl_set_highlight(require("lsp.null-ls.linters").list_available(ft), "LvimInfoIdentifier") - vim.cmd('let m=matchadd("LvimInfoIdentifier", "' .. client_name .. '")') end local Popup = require("interface.popup"):new { diff --git a/lua/core/log.lua b/lua/core/log.lua index 1eb786ba..fca1fcb4 100644 --- a/lua/core/log.lua +++ b/lua/core/log.lua @@ -8,6 +8,7 @@ function Log:add_entry(msg, level) if self.__handle then -- plenary uses lower-case log levels self.__handle[level:lower()](msg) + return end local status_ok, plenary = pcall(require, "plenary") if status_ok then diff --git a/lua/core/lspinstall.lua b/lua/core/lspinstall.lua deleted file mode 100644 index 0bb59e0e..00000000 --- a/lua/core/lspinstall.lua +++ /dev/null @@ -1,19 +0,0 @@ -local M = {} - -M.config = function() - lvim.builtin.lspinstall = { - active = true, - on_config_done = nil, - } -end - -M.setup = function() - local lspinstall = require "lspinstall" - lspinstall.setup() - - if lvim.builtin.lspinstall.on_config_done then - lvim.builtin.lspinstall.on_config_done(lspinstall) - end -end - -return M diff --git a/lua/core/lualine/components.lua b/lua/core/lualine/components.lua index 21e25585..3ee2fdf8 100644 --- a/lua/core/lualine/components.lua +++ b/lua/core/lualine/components.lua @@ -96,14 +96,11 @@ return { local buf_client_names = {} -- add client - local utils = require "lsp.utils" - local active_client = utils.get_active_client_by_ft(buf_ft) for _, client in pairs(buf_clients) do if client.name ~= "null-ls" then table.insert(buf_client_names, client.name) end end - vim.list_extend(buf_client_names, active_client or {}) -- add formatter local formatters = require "lsp.null-ls.formatters" diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index 27cec37c..a115bcc5 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -148,9 +148,9 @@ M.config = function() "Telescope lsp_workspace_diagnostics", "Workspace Diagnostics", }, - -- f = { "silent FormatWrite", "Format" }, f = { "lua vim.lsp.buf.formatting()", "Format" }, i = { "LspInfo", "Info" }, + I = { "LspInstallInfo", "Installer Info" }, j = { "lua vim.lsp.diagnostic.goto_next({popup_opts = {border = lvim.lsp.popup_border}})", "Next Diagnostic", diff --git a/lua/lsp/config.lua b/lua/lsp/config.lua new file mode 100644 index 00000000..146301c9 --- /dev/null +++ b/lua/lsp/config.lua @@ -0,0 +1,27 @@ +return { + templates_dir = join_paths(get_runtime_dir(), "site", "after", "ftplugin"), + diagnostics = { + signs = { + active = true, + values = { + { name = "LspDiagnosticsSignError", text = "" }, + { name = "LspDiagnosticsSignWarning", text = "" }, + { name = "LspDiagnosticsSignHint", text = "" }, + { name = "LspDiagnosticsSignInformation", text = "" }, + }, + }, + virtual_text = { + prefix = "", + spacing = 0, + }, + update_in_insert = false, + underline = true, + severity_sort = true, + }, + override = {}, + document_highlight = true, + popup_border = "single", + on_attach_callback = nil, + on_init_callback = nil, + automatic_servers_installation = true, +} diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 386be075..7f20a39d 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,5 +1,6 @@ local M = {} local Log = require "core.log" +local utils = require "utils" local function lsp_highlight_document(client) if lvim.lsp.document_highlight == false then @@ -61,48 +62,12 @@ function M.common_capabilities() return capabilities end -function M.get_ls_capabilities(client_id) - local client - if not client_id then - local buf_clients = vim.lsp.buf_get_clients() - for _, buf_client in ipairs(buf_clients) do - if buf_client.name ~= "null-ls" then - client_id = buf_client.id - break - end - end - end - if not client_id then - error "Unable to determine client_id" - end - - client = vim.lsp.get_client_by_id(tonumber(client_id)) - - local enabled_caps = {} - - for k, v in pairs(client.resolved_capabilities) do - if v == true then - table.insert(enabled_caps, k) - end - end - - return enabled_caps -end - function M.common_on_init(client, bufnr) if lvim.lsp.on_init_callback then lvim.lsp.on_init_callback(client, bufnr) Log:debug "Called lsp.on_init_callback" return end - - local formatters = lvim.lang[vim.bo.filetype].formatters - if not vim.tbl_isempty(formatters) and formatters[1]["exe"] ~= nil and formatters[1].exe ~= "" then - client.resolved_capabilities.document_formatting = false - Log:debug( - string.format("Overriding language server [%s] with format provider [%s]", client.name, formatters[1].exe) - ) - end end function M.common_on_attach(client, bufnr) @@ -112,63 +77,46 @@ function M.common_on_attach(client, bufnr) end lsp_highlight_document(client) add_lsp_buffer_keybindings(bufnr) - require("lsp.null-ls").setup(vim.bo.filetype) end -function M.setup(lang) - local lsp_utils = require "lsp.utils" - local lsp = lvim.lang[lang].lsp - if (lsp.active ~= nil and not lsp.active) or lsp_utils.is_client_active(lsp.provider) then - return - end - - local overrides = lvim.lsp.override - if type(overrides) == "table" then - if vim.tbl_contains(overrides, lang) then - return - end +local function bootstrap_nlsp(opts) + opts = opts or {} + local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings") + if lsp_settings_status_ok then + lsp_settings.setup(opts) end +end - if lsp.provider ~= nil and lsp.provider ~= "" then - local lspconfig = require "lspconfig" +function M.get_common_opts() + return { + on_attach = M.common_on_attach, + on_init = M.common_on_init, + capabilities = M.common_capabilities(), + } +end - if not lsp.setup.on_attach then - lsp.setup.on_attach = M.common_on_attach - end - if not lsp.setup.on_init then - lsp.setup.on_init = M.common_on_init - end - if not lsp.setup.capabilities then - lsp.setup.capabilities = M.common_capabilities() - end +function M.setup() + Log:debug "Setting up LSP support" - lspconfig[lsp.provider].setup(lsp.setup) + local lsp_status_ok, _ = pcall(require, "lspconfig") + if not lsp_status_ok then + return end -end - -function M.global_setup() - vim.lsp.protocol.CompletionItemKind = lvim.lsp.completion.item_kind for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) end - require("lsp.handlers").setup() - local null_status_ok, null_ls = pcall(require, "null-ls") - if null_status_ok then - null_ls.config() - require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) + if not utils.is_directory(lvim.lsp.templates_dir) then + require("lsp.templates").generate_templates() end - local utils = require "utils" + bootstrap_nlsp { config_home = utils.join_paths(get_config_dir(), "lsp-settings") } - local lsp_settings_status_ok, lsp_settings = pcall(require, "nlspsettings") - if lsp_settings_status_ok then - lsp_settings.setup { - config_home = utils.join_paths(get_config_dir(), "lsp-settings"), - } - end + require("lsp.null-ls").setup() + + require("utils").toggle_autoformat() end return M diff --git a/lua/lsp/kind.lua b/lua/lsp/kind.lua deleted file mode 100644 index b78fd318..00000000 --- a/lua/lsp/kind.lua +++ /dev/null @@ -1,31 +0,0 @@ -local M = {} - -M.icons = { - Class = " ", - Color = " ", - Constant = "ﲀ ", - Constructor = " ", - Enum = "練", - EnumMember = " ", - Event = " ", - Field = " ", - File = "", - Folder = " ", - Function = " ", - Interface = "ﰮ ", - Keyword = " ", - Method = " ", - Module = " ", - Operator = "", - Property = " ", - Reference = " ", - Snippet = " ", - Struct = " ", - Text = " ", - TypeParameter = " ", - Unit = "塞", - Value = " ", - Variable = " ", -} - -return M diff --git a/lua/lsp/manager.lua b/lua/lsp/manager.lua new file mode 100644 index 00000000..24d462ad --- /dev/null +++ b/lua/lsp/manager.lua @@ -0,0 +1,82 @@ +local M = {} + +local Log = require "core.log" +local lsp_utils = require "lsp.utils" + +function M.init_defaults(languages) + for _, entry in ipairs(languages) do + if not lvim.lang[entry] then + lvim.lang[entry] = { + formatters = {}, + linters = {}, + } + end + end +end + +local function is_overridden(server) + local overrides = lvim.lsp.override + if type(overrides) == "table" then + if vim.tbl_contains(overrides, server) then + return + end + end +end + +function M.setup_server(server_name) + vim.validate { + name = { server_name, "string" }, + } + + if lsp_utils.is_client_active(server_name) or is_overridden(server_name) then + return + end + + local lsp_installer_servers = require "nvim-lsp-installer.servers" + local server_available, requested_server = lsp_installer_servers.get_server(server_name) + if server_available then + if not requested_server:is_installed() then + Log:debug(string.format("[%s] is not installed", server_name)) + if lvim.lsp.automatic_servers_installation then + Log:debug(string.format("Installing [%s]", server_name)) + requested_server:install() + else + return + end + end + end + + local default_config = { + on_attach = require("lsp").common_on_attach, + on_init = require("lsp").common_on_init, + capabilities = require("lsp").common_capabilities(), + } + + local status_ok, custom_config = pcall(require, "lsp/providers/" .. requested_server.name) + if status_ok then + local new_config = vim.tbl_deep_extend("force", default_config, custom_config) + Log:debug("Using custom configuration for requested server: " .. requested_server.name) + requested_server:setup(new_config) + else + Log:debug("Using the default configuration for requested server: " .. requested_server.name) + requested_server:setup(default_config) + end +end + +function M.setup(servers) + local status_ok, _ = pcall(require, "nvim-lsp-installer") + if not status_ok then + return + end + + --- allow using a single value + if type(servers) == "string" then + servers = { servers } + end + + for _, server in ipairs(servers) do + M.setup_server(server) + end +end + +return M diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 2c2a4f06..8199aca0 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -1,29 +1,14 @@ local M = {} -local formatters_by_ft = {} local null_ls = require "null-ls" local services = require "lsp.null-ls.services" local Log = require "core.log" -local function list_names(formatters, options) - options = options or {} - local filter = options.filter or "supported" - - return vim.tbl_keys(formatters[filter]) -end - function M.list_supported_names(filetype) - if not formatters_by_ft[filetype] then - return {} - end - return list_names(formatters_by_ft[filetype], { filter = "supported" }) -end - -function M.list_unsupported_names(filetype) - if not formatters_by_ft[filetype] then - return {} - end - return list_names(formatters_by_ft[filetype], { filter = "unsupported" }) + local null_ls_methods = require "null-ls.methods" + local formatter_method = null_ls_methods.internal["FORMATTING"] + local registered_providers = services.list_registered_providers_names(filetype) + return registered_providers[formatter_method] or {} end function M.list_available(filetype) @@ -62,12 +47,13 @@ function M.list_configured(formatter_configs) return { supported = formatters, unsupported = errors } end -function M.setup(filetype, options) - if not lvim.lang[filetype] or (formatters_by_ft[filetype] and not options.force_reload) then +function M.setup(formatter_configs, filetype) + if vim.tbl_isempty(formatter_configs) then return end - formatters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].formatters) + local formatters_by_ft = {} + formatters_by_ft[filetype] = M.list_configured(formatter_configs) null_ls.register { sources = formatters_by_ft[filetype].supported } end diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index ce4c07d9..0540fb48 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -1,44 +1,26 @@ local M = {} -function M.list_supported_provider_names(filetype) - local names = {} - - local formatters = require "lsp.null-ls.formatters" - local linters = require "lsp.null-ls.linters" - - vim.list_extend(names, formatters.list_supported_names(filetype)) - vim.list_extend(names, linters.list_supported_names(filetype)) - - return names -end - -function M.list_unsupported_provider_names(filetype) - local names = {} - - local formatters = require "lsp.null-ls.formatters" - local linters = require "lsp.null-ls.linters" - - vim.list_extend(names, formatters.list_unsupported_names(filetype)) - vim.list_extend(names, linters.list_unsupported_names(filetype)) - - return names -end - --- TODO: for linters and formatters with spaces and '-' replace with '_' -function M.setup(filetype, options) - options = options or {} - - local ok, _ = pcall(require, "null-ls") - if not ok then - require("core.log"):error "Missing null-ls dependency" +local Log = require "core.log" +local formatters = require "lsp.null-ls.formatters" +local linters = require "lsp.null-ls.linters" + +function M:setup() + local status_ok, null_ls = pcall(require, "null-ls") + if not status_ok then + Log:error "Missing null-ls dependency" return end - local formatters = require "lsp.null-ls.formatters" - local linters = require "lsp.null-ls.linters" - - formatters.setup(filetype, options) - linters.setup(filetype, options) + null_ls.config() + require("lspconfig")["null-ls"].setup {} + for _, filetype in pairs(lvim.lang) do + if filetype.formatters then + formatters.setup(filetype.formatters, filetype) + end + if filetype.linters then + linters.setup(filetype.linters, filetype) + end + end end return M diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index d88a8b83..ea45fa87 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -1,29 +1,14 @@ local M = {} -local linters_by_ft = {} local null_ls = require "null-ls" local services = require "lsp.null-ls.services" local Log = require "core.log" -local function list_names(linters, options) - options = options or {} - local filter = options.filter or "supported" - - return vim.tbl_keys(linters[filter]) -end - function M.list_supported_names(filetype) - if not linters_by_ft[filetype] then - return {} - end - return list_names(linters_by_ft[filetype], { filter = "supported" }) -end - -function M.list_unsupported_names(filetype) - if not linters_by_ft[filetype] then - return {} - end - return list_names(linters_by_ft[filetype], { filter = "unsupported" }) + local null_ls_methods = require "null-ls.methods" + local linter_method = null_ls_methods.internal["DIAGNOSTICS"] + local registered_providers = services.list_registered_providers_names(filetype) + return registered_providers[linter_method] or {} end function M.list_available(filetype) @@ -62,12 +47,13 @@ function M.list_configured(linter_configs) return { supported = linters, unsupported = errors } end -function M.setup(filetype, options) - if not lvim.lang[filetype] or (linters_by_ft[filetype] and not options.force_reload) then +function M.setup(linter_configs, filetype) + if vim.tbl_isempty(linter_configs) then return end - linters_by_ft[filetype] = M.list_configured(lvim.lang[filetype].linters) + local linters_by_ft = {} + linters_by_ft[filetype] = M.list_configured(linter_configs) null_ls.register { sources = linters_by_ft[filetype].supported } end diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index 1e76b40a..c62fc709 100644 --- a/lua/lsp/null-ls/services.lua +++ b/lua/lsp/null-ls/services.lua @@ -45,4 +45,19 @@ function M.find_command(command) return nil end +function M.list_registered_providers_names(filetype) + local u = require "null-ls.utils" + local c = require "null-ls.config" + local registered = {} + for method, source in pairs(c.get()._methods) do + for name, filetypes in pairs(source) do + if u.filetype_matches(filetypes, filetype) then + registered[method] = registered[method] or {} + table.insert(registered[method], name) + end + end + end + return registered +end + return M diff --git a/lua/lsp/providers/jsonls.lua b/lua/lsp/providers/jsonls.lua new file mode 100644 index 00000000..55bc1ea2 --- /dev/null +++ b/lua/lsp/providers/jsonls.lua @@ -0,0 +1,30 @@ +local schemas = nil +local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") +if status_ok then + schemas = jsonls_settings.get_default_schemas() +end + +local opts = { + setup = { + settings = { + json = { + schemas = schemas, + -- = { + -- { + -- fileMatch = { "package.json" }, + -- url = "https://json.schemastore.org/package.json", + -- }, + -- }, + }, + }, + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + end, + }, + }, + }, +} + +return opts diff --git a/lua/lsp/providers/sumneko_lua.lua b/lua/lsp/providers/sumneko_lua.lua new file mode 100644 index 00000000..4fee1fd1 --- /dev/null +++ b/lua/lsp/providers/sumneko_lua.lua @@ -0,0 +1,19 @@ +local opts = { + settings = { + Lua = { + diagnostics = { + globals = { "vim", "lvim" }, + }, + workspace = { + library = { + [require("utils").join_paths(get_runtime_dir(), "lvim", "lua")] = true, + [vim.fn.expand "$VIMRUNTIME/lua"] = true, + [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true, + }, + maxPreload = 100000, + preloadFileSize = 10000, + }, + }, + }, +} +return opts diff --git a/lua/lsp/providers/vuels.lua b/lua/lsp/providers/vuels.lua new file mode 100644 index 00000000..3f44275d --- /dev/null +++ b/lua/lsp/providers/vuels.lua @@ -0,0 +1,26 @@ +local opts = { + setup = { + root_dir = function(fname) + local util = require "lspconfig/util" + return util.root_pattern "package.json"(fname) or util.root_pattern "vue.config.js"(fname) or vim.fn.getcwd() + end, + init_options = { + config = { + vetur = { + completion = { + autoImport = true, + tagCasing = "kebab", + useScaffoldSnippets = true, + }, + useWorkspaceDependencies = true, + validation = { + script = true, + style = true, + template = true, + }, + }, + }, + }, + }, +} +return opts diff --git a/lua/lsp/templates.lua b/lua/lsp/templates.lua new file mode 100644 index 00000000..6ded636d --- /dev/null +++ b/lua/lsp/templates.lua @@ -0,0 +1,98 @@ +local M = {} + +local Log = require "core.log" +local utils = require "utils" +local get_supported_filetypes = require("lsp.utils").get_supported_filetypes + +local ftplugin_dir = lvim.lsp.templates_dir + +local join_paths = _G.join_paths + +function M.remove_template_files() + -- remove any outdated files + for _, file in ipairs(vim.fn.glob(ftplugin_dir .. "/*.lua", 1, 1)) do + vim.fn.delete(file) + end +end + +---Checks if a server is ignored by default because of a conflict +---Only TSServer is enabled by default for the javascript-family +---@param server_name string +function M.is_ignored(server_name, filetypes) + --TODO: this is easy to be made configurable once stable + filetypes = filetypes or get_supported_filetypes(server_name) + + if vim.tbl_contains(filetypes, "javascript") then + if server_name == "tsserver" or server_name == "tailwindcss" then + return false + else + return true + end + end + + local blacklist = { + "jedi_language_server", + "pylsp", + "sqlls", + "sqls", + "angularls", + "ansiblels", + } + return vim.tbl_contains(blacklist, server_name) +end + +---Generates an ftplugin file based on the server_name in the selected directory +---@param server_name string name of a valid language server, e.g. pyright, gopls, tsserver, etc. +---@param dir string the full path to the desired directory +function M.generate_ftplugin(server_name, dir) + -- we need to go through lspconfig to get the corresponding filetypes currently + local filetypes = get_supported_filetypes(server_name) or {} + if not filetypes then + return + end + + if M.is_ignored(server_name, filetypes) then + return + end + + -- print("got associated filetypes: " .. vim.inspect(filetypes)) + + for _, filetype in ipairs(filetypes) do + local filename = join_paths(dir, filetype .. ".lua") + local setup_cmd = string.format([[require("lsp.manager").setup(%q)]], server_name) + -- print("using setup_cmd: " .. setup_cmd) + -- overwrite the file completely + utils.write_file(filename, setup_cmd .. "\n", "a") + end +end + +---Generates ftplugin files based on a list of server_names +---The files are generated to a runtimepath: "$LUNARVIM_RUNTIME_DIR/site/after/ftplugin/template.lua" +---@param servers_names table list of servers to be enabled. Will add all by default +function M.generate_templates(servers_names) + servers_names = servers_names or {} + + Log:debug "Templates installation in progress" + + M.remove_template_files() + + if vim.tbl_isempty(servers_names) then + local available_servers = require("nvim-lsp-installer.servers").get_available_servers() + + for _, server in pairs(available_servers) do + table.insert(servers_names, server.name) + end + end + + -- create the directory if it didn't exist + if not utils.is_directory(lvim.lsp.templates_dir) then + vim.fn.mkdir(ftplugin_dir, "p") + end + + for _, server in ipairs(servers_names) do + M.generate_ftplugin(server, ftplugin_dir) + end + Log:debug "Templates installation is complete" +end + +return M diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua index 17b9c3bc..1a5dd79d 100644 --- a/lua/lsp/utils.lua +++ b/lua/lsp/utils.lua @@ -10,19 +10,60 @@ function M.is_client_active(name) return false end --- FIXME: this should return a list instead -function M.get_active_client_by_ft(filetype) - if not lvim.lang[filetype] or not lvim.lang[filetype].lsp then - return nil - end +function M.disable_formatting_capability(client) + -- FIXME: figure out a reasonable way to do this + client.resolved_capabilities.document_formatting = false + require("core.log"):debug(string.format("Turning off formatting capability for language server [%s] ", client.name)) +end +function M.get_active_client_by_ft(filetype) + local matches = {} local clients = vim.lsp.get_active_clients() for _, client in pairs(clients) do - if client.name == lvim.lang[filetype].lsp.provider then - return client + local supported_filetypes = client.config.filetypes or {} + if client.name ~= "null-ls" and vim.tbl_contains(supported_filetypes, filetype) then + table.insert(matches, client) + end + end + return matches +end + +function M.get_ls_capabilities(client_id) + if not client_id then + local buf_clients = vim.lsp.buf_get_clients() + for _, buf_client in ipairs(buf_clients) do + if buf_client.name ~= "null-ls" then + client_id = buf_client.id + break + end + end + end + if not client_id then + error "Unable to determine client_id" + return + end + + local client = vim.lsp.get_client_by_id(tonumber(client_id)) + + local enabled_caps = {} + for capability, status in pairs(client.resolved_capabilities) do + if status == true then + table.insert(enabled_caps, capability) + end + end + + return enabled_caps +end + +function M.get_supported_filetypes(server_name) + -- print("got filetypes query request for: " .. server_name) + local configs = require "lspconfig/configs" + pcall(require, ("lspconfig/" .. server_name)) + for _, config in pairs(configs) do + if config.name == server_name then + return config.document_config.default_config.filetypes or {} end end - return nil end return M diff --git a/lua/plugins.lua b/lua/plugins.lua index 178fb99e..d7f47fcb 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -6,12 +6,7 @@ return { { "jose-elias-alvarez/null-ls.nvim" }, { "antoinemadec/FixCursorHold.nvim" }, -- Needed while issue https://github.com/neovim/neovim/issues/12587 is still open { - "kabouzeid/nvim-lspinstall", - event = "VimEnter", - config = function() - local lspinstall = require "core.lspinstall" - lspinstall.setup() - end, + "williamboman/nvim-lsp-installer", }, { "nvim-lua/popup.nvim" }, diff --git a/lua/utils/init.lua b/lua/utils/init.lua index 7f8e1f77..eaac54f4 100644 --- a/lua/utils/init.lua +++ b/lua/utils/init.lua @@ -99,8 +99,7 @@ function utils.reload_lv_config() vim.cmd ":PackerInstall" vim.cmd ":PackerCompile" -- vim.cmd ":PackerClean" - local null_ls = require "lsp.null-ls" - null_ls.setup(vim.bo.filetype, { force_reload = true }) + require("lsp").setup() Log:info "Reloaded configuration" end @@ -133,15 +132,106 @@ function utils.apply_defaults(config, default_config) end --- Checks whether a given path exists and is a file. ---@param filename (string) path to check +--@param path (string) path to check --@returns (bool) -function utils.is_file(filename) - local stat = uv.fs_stat(filename) +function utils.is_file(path) + local stat = uv.fs_stat(path) return stat and stat.type == "file" or false end +--- Checks whether a given path exists and is a directory +--@param path (string) path to check +--@returns (bool) +function utils.is_directory(path) + local stat = uv.fs_stat(path) + return stat and stat.type == "directory" or false +end + +function utils.write_file(path, txt, flag) + uv.fs_open(path, flag, 438, function(open_err, fd) + assert(not open_err, open_err) + uv.fs_write(fd, txt, -1, function(write_err) + assert(not write_err, write_err) + uv.fs_close(fd, function(close_err) + assert(not close_err, close_err) + end) + end) + end) +end + utils.join_paths = _G.join_paths +function utils.write_file(path, txt, flag) + uv.fs_open(path, flag, 438, function(open_err, fd) + assert(not open_err, open_err) + uv.fs_write(fd, txt, -1, function(write_err) + assert(not write_err, write_err) + uv.fs_close(fd, function(close_err) + assert(not close_err, close_err) + end) + end) + end) +end + +function utils.debounce(ms, fn) + local timer = vim.loop.new_timer() + return function(...) + local argv = { ... } + timer:start(ms, 0, function() + timer:stop() + vim.schedule_wrap(fn)(unpack(argv)) + end) + end +end + +function utils.search_file(file, args) + local Job = require "plenary.job" + local stderr = {} + local stdout, ret = Job + :new({ + command = "grep", + args = { args, file }, + cwd = get_cache_dir(), + on_stderr = function(_, data) + table.insert(stderr, data) + end, + }) + :sync() + return stdout, ret, stderr +end + +function utils.file_contains(file, query) + local stdout, ret, stderr = utils.search_file(file, query) + if ret == 0 then + return true + end + if not vim.tbl_isempty(stderr) then + error(vim.inspect(stderr)) + end + if not vim.tbl_isempty(stdout) then + error(vim.inspect(stdout)) + end + return false +end + +function utils.log_contains(query) + local logfile = require("core.log"):get_path() + local stdout, ret, stderr = utils.search_file(logfile, query) + if ret == 0 then + return true + end + if not vim.tbl_isempty(stderr) then + error(vim.inspect(stderr)) + end + if not vim.tbl_isempty(stdout) then + error(vim.inspect(stdout)) + end + if not vim.tbl_isempty(stderr) then + error(vim.inspect(stderr)) + end + return false +end + return utils -- TODO: find a new home for these autocommands -- cgit v1.2.3 From 48a6d859f34f4f0ce29054f4a59722d485aaa06e Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sun, 3 Oct 2021 22:32:11 +0330 Subject: fix: return correctly for overridden lang servers (#1669) --- lua/lsp/manager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lsp/manager.lua b/lua/lsp/manager.lua index 24d462ad..5b6d9767 100644 --- a/lua/lsp/manager.lua +++ b/lua/lsp/manager.lua @@ -18,7 +18,7 @@ local function is_overridden(server) local overrides = lvim.lsp.override if type(overrides) == "table" then if vim.tbl_contains(overrides, server) then - return + return true end end end -- cgit v1.2.3 From efd8f589b75ba883ef4e69d79982d3c200595ec0 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 22:23:13 +0200 Subject: fix: add deprecation notice for lvim.lang.foo.lsp (#1670) --- lua/config/init.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lua') diff --git a/lua/config/init.lua b/lua/config/init.lua index f0062560..411f7a93 100644 --- a/lua/config/init.lua +++ b/lua/config/init.lua @@ -124,6 +124,26 @@ function M:init(opts) require("lsp.manager").init_defaults(supported_languages) end +local function deprecation_notice() + local in_headless = #vim.api.nvim_list_uis() == 0 + if in_headless then + return + end + + for lang, entry in pairs(lvim.lang) do + local deprecated_config = entry["lsp"] or {} + if not vim.tbl_isempty(deprecated_config) then + local msg = string.format( + "Deprecation notice: [lvim.lang.%s.lsp] setting is no longer supported. See https://github.com/LunarVim/LunarVim#breaking-changes", + lang + ) + vim.schedule(function() + vim.notify(msg, vim.log.levels.WARN) + end) + end + end +end + --- Override the configuration with a user provided one -- @param config_path The path to the configuration overrides function M:load(config_path) @@ -137,6 +157,8 @@ function M:load(config_path) return end + deprecation_notice() + self.path = config_path autocmds.define_augroups(lvim.autocommands) -- cgit v1.2.3 From 7a939ad771403e20341c9465af66573d225300bb Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 22:48:41 +0200 Subject: fix: add missing table entry (#1670) --- lua/lsp/manager.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'lua') diff --git a/lua/lsp/manager.lua b/lua/lsp/manager.lua index 5b6d9767..a2f23a7b 100644 --- a/lua/lsp/manager.lua +++ b/lua/lsp/manager.lua @@ -9,6 +9,7 @@ function M.init_defaults(languages) lvim.lang[entry] = { formatters = {}, linters = {}, + lsp = {}, } end end -- cgit v1.2.3 From 1078f43a517d5a0056b1191aca0fa85994a38ecb Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sun, 3 Oct 2021 23:02:42 +0200 Subject: fix: add packer-install hook on lvim-update --- lua/bootstrap.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index fb2099ce..43ce44d5 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -1,5 +1,7 @@ local M = {} +local in_headless = #vim.api.nvim_list_uis() == 0 + ---Join path segments that were passed as input ---@return string function _G.join_paths(...) @@ -114,10 +116,13 @@ function M:update() M:update_repo() M:reset_cache() require("lsp.templates").generate_templates() - vim.schedule(function() - -- TODO: add a changelog - vim.notify("Update complete", vim.log.levels.INFO) - end) + if not in_headless then + vim.schedule(function() + require("packer").install() + -- TODO: add a changelog + vim.notify("Update complete", vim.log.levels.INFO) + end) + end end local function git_cmd(subcmd) -- cgit v1.2.3 From 2104e3864550e28513cbad5cb2f48233c2c4e79e Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 4 Oct 2021 08:12:25 +0200 Subject: fix: restore the ability to override formatting (#1677) --- lua/lsp/init.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 7f20a39d..fae7ca8d 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -62,18 +62,37 @@ function M.common_capabilities() return capabilities end +local function select_default_formater(client) + local client_formatting = client.resolved_capabilities.document_formatting + or client.resolved_capabilities.document_range_formatting + if client.name == "null-ls" or not client_formatting then + return + end + Log:debug("Checking for formatter overriding for " .. client.name) + local client_filetypes = client.config.filetypes or {} + for _, filetype in ipairs(client_filetypes) do + if not vim.tbl_isempty(lvim.lang[filetype].formatters) then + Log:debug("Formatter overriding detected. Disabling formatting capabilities for " .. client.name) + client.resolved_capabilities.document_formatting = false + client.resolved_capabilities.document_range_formatting = false + return + end + end +end + function M.common_on_init(client, bufnr) if lvim.lsp.on_init_callback then lvim.lsp.on_init_callback(client, bufnr) Log:debug "Called lsp.on_init_callback" return end + select_default_formater(client) end function M.common_on_attach(client, bufnr) if lvim.lsp.on_attach_callback then lvim.lsp.on_attach_callback(client, bufnr) - Log:debug "Called lsp.on_init_callback" + Log:debug "Called lsp.on_attach_callback" end lsp_highlight_document(client) add_lsp_buffer_keybindings(bufnr) -- cgit v1.2.3 From 47f68f4873471b515a5ee1800b287f929aac8641 Mon Sep 17 00:00:00 2001 From: Christian Chiarulli Date: Mon, 4 Oct 2021 07:15:26 +0000 Subject: feat: q quits lsp-installer (#1674) --- lua/core/autocmds.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lua') diff --git a/lua/core/autocmds.lua b/lua/core/autocmds.lua index 041926e5..662afcfa 100644 --- a/lua/core/autocmds.lua +++ b/lua/core/autocmds.lua @@ -13,6 +13,11 @@ lvim.autocommands = { "qf", "nnoremap q :q", }, + { + "FileType", + "lsp-installer", + "nnoremap q :q", + }, { "TextYankPost", "*", -- cgit v1.2.3 From 48472a1bf04aede946893146462e0d3a8ce51360 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 4 Oct 2021 14:04:57 +0330 Subject: feat: better default json schemas (#1678) --- lua/lsp/providers/jsonls.lua | 193 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 184 insertions(+), 9 deletions(-) (limited to 'lua') diff --git a/lua/lsp/providers/jsonls.lua b/lua/lsp/providers/jsonls.lua index 55bc1ea2..4fa92af4 100644 --- a/lua/lsp/providers/jsonls.lua +++ b/lua/lsp/providers/jsonls.lua @@ -1,20 +1,195 @@ -local schemas = nil +local default_schemas = nil local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") if status_ok then - schemas = jsonls_settings.get_default_schemas() + default_schemas = jsonls_settings.get_default_schemas() end +local schemas = { + { + description = "TypeScript compiler configuration file", + fileMatch = { + "tsconfig.json", + "tsconfig.*.json", + }, + url = "https://json.schemastore.org/tsconfig.json", + }, + { + description = "Lerna config", + fileMatch = { "lerna.json" }, + url = "https://json.schemastore.org/lerna.json", + }, + { + description = "Babel configuration", + fileMatch = { + ".babelrc.json", + ".babelrc", + "babel.config.json", + }, + url = "https://json.schemastore.org/babelrc.json", + }, + { + description = "ESLint config", + fileMatch = { + ".eslintrc.json", + ".eslintrc", + }, + url = "https://json.schemastore.org/eslintrc.json", + }, + { + description = "Bucklescript config", + fileMatch = { "bsconfig.json" }, + url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json", + }, + { + description = "Prettier config", + fileMatch = { + ".prettierrc", + ".prettierrc.json", + "prettier.config.json", + }, + url = "https://json.schemastore.org/prettierrc", + }, + { + description = "Vercel Now config", + fileMatch = { "now.json" }, + url = "https://json.schemastore.org/now", + }, + { + description = "Stylelint config", + fileMatch = { + ".stylelintrc", + ".stylelintrc.json", + "stylelint.config.json", + }, + url = "https://json.schemastore.org/stylelintrc", + }, + { + description = "A JSON schema for the ASP.NET LaunchSettings.json files", + fileMatch = { "launchsettings.json" }, + url = "https://json.schemastore.org/launchsettings.json", + }, + { + description = "Schema for CMake Presets", + fileMatch = { + "CMakePresets.json", + "CMakeUserPresets.json", + }, + url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json", + }, + { + description = "Configuration file as an alternative for configuring your repository in the settings page.", + fileMatch = { + ".codeclimate.json", + }, + url = "https://json.schemastore.org/codeclimate.json", + }, + { + description = "LLVM compilation database", + fileMatch = { + "compile_commands.json", + }, + url = "https://json.schemastore.org/compile-commands.json", + }, + { + description = "Config file for Command Task Runner", + fileMatch = { + "commands.json", + }, + url = "https://json.schemastore.org/commands.json", + }, + { + description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.", + fileMatch = { + "*.cf.json", + "cloudformation.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json", + }, + { + description = "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.", + fileMatch = { + "serverless.template", + "*.sam.json", + "sam.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json", + }, + { + description = "Json schema for properties json file for a GitHub Workflow template", + fileMatch = { + ".github/workflow-templates/**.properties.json", + }, + url = "https://json.schemastore.org/github-workflow-template-properties.json", + }, + { + description = "golangci-lint configuration file", + fileMatch = { + ".golangci.toml", + ".golangci.json", + }, + url = "https://json.schemastore.org/golangci-lint.json", + }, + { + description = "JSON Schema for Grafana 5.x Dashboards", + url = "https://json.schemastore.org/grafana-dashboard-5.x.json", + }, + { + description = "JSON schema for the JSON Feed format", + fileMatch = { + "feed.json", + }, + url = "https://json.schemastore.org/feed.json", + versions = { + ["1"] = "https://json.schemastore.org/feed-1.json", + ["1.1"] = "https://json.schemastore.org/feed.json", + }, + }, + { + description = "Packer template JSON configuration", + fileMatch = { + "packer.json", + }, + url = "https://json.schemastore.org/packer.json", + }, + { + description = "NPM configuration file", + fileMatch = { + "package.json", + }, + url = "https://json.schemastore.org/package.json", + }, + { + description = "Traefik v2 Dynamic Configuration File Provider", + url = "https://json.schemastore.org/traefik-v2-file-provider.json", + }, + { + description = "JSON schema for Visual Studio component configuration files", + fileMatch = { + "*.vsconfig", + }, + url = "https://json.schemastore.org/vsconfig.json", + }, + { + description = "Resume json", + fileMatch = { "resume.json" }, + url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json", + }, +} + +local function extend(tab1, tab2) + for _, value in ipairs(tab2) do + table.insert(tab1, value) + end + return tab1 +end + +local extended_schemas = extend(schemas, default_schemas) + local opts = { setup = { settings = { json = { - schemas = schemas, - -- = { - -- { - -- fileMatch = { "package.json" }, - -- url = "https://json.schemastore.org/package.json", - -- }, - -- }, + schemas = extended_schemas, }, }, commands = { -- cgit v1.2.3 From b1ae1e9bfb96fb8dc4b66a7fad17307236a2502e Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 4 Oct 2021 14:10:42 +0330 Subject: feat: better kubernetes support (#1679) --- lua/lsp/providers/yamlls.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 lua/lsp/providers/yamlls.lua (limited to 'lua') diff --git a/lua/lsp/providers/yamlls.lua b/lua/lsp/providers/yamlls.lua new file mode 100644 index 00000000..156a35b0 --- /dev/null +++ b/lua/lsp/providers/yamlls.lua @@ -0,0 +1,30 @@ +local opts = { + settings = { + yaml = { + hover = true, + completion = true, + validate = true, + schemaStore = { + enable = true, + url = "https://www.schemastore.org/api/json/catalog.json", + }, + schemas = { + kubernetes = { + "daemon.{yml,yaml}", + "manager.{yml,yaml}", + "restapi.{yml,yaml}", + "role.{yml,yaml}", + "role_binding.{yml,yaml}", + "*onfigma*.{yml,yaml}", + "*ngres*.{yml,yaml}", + "*ecre*.{yml,yaml}", + "*eployment*.{yml,yaml}", + "*ervic*.{yml,yaml}", + "kubectl-edit*.yaml", + }, + }, + }, + }, +} + +return opts -- cgit v1.2.3 From 6443f156d762cd64ac857c34f10843404f0dffde Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 4 Oct 2021 14:17:27 +0330 Subject: fix: the virtual_text charachter causes issues (#1681) --- lua/lsp/config.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lua') diff --git a/lua/lsp/config.lua b/lua/lsp/config.lua index 146301c9..f9184e6f 100644 --- a/lua/lsp/config.lua +++ b/lua/lsp/config.lua @@ -10,10 +10,7 @@ return { { name = "LspDiagnosticsSignInformation", text = "" }, }, }, - virtual_text = { - prefix = "", - spacing = 0, - }, + virtual_text = true, update_in_insert = false, underline = true, severity_sort = true, -- cgit v1.2.3 From 8fb404f7d6f449ff4a0e3d361de0e4e85e81ab4e Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Mon, 4 Oct 2021 15:48:35 +0330 Subject: fix: bring back NlspConfig completion (#1682) --- lua/lsp/providers/jsonls.lua | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'lua') diff --git a/lua/lsp/providers/jsonls.lua b/lua/lsp/providers/jsonls.lua index 4fa92af4..72c67b47 100644 --- a/lua/lsp/providers/jsonls.lua +++ b/lua/lsp/providers/jsonls.lua @@ -129,10 +129,6 @@ local schemas = { }, url = "https://json.schemastore.org/golangci-lint.json", }, - { - description = "JSON Schema for Grafana 5.x Dashboards", - url = "https://json.schemastore.org/grafana-dashboard-5.x.json", - }, { description = "JSON schema for the JSON Feed format", fileMatch = { @@ -158,10 +154,6 @@ local schemas = { }, url = "https://json.schemastore.org/package.json", }, - { - description = "Traefik v2 Dynamic Configuration File Provider", - url = "https://json.schemastore.org/traefik-v2-file-provider.json", - }, { description = "JSON schema for Visual Studio component configuration files", fileMatch = { @@ -186,18 +178,16 @@ end local extended_schemas = extend(schemas, default_schemas) local opts = { - setup = { - settings = { - json = { - schemas = extended_schemas, - }, - }, - commands = { - Format = { - function() - vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) - end, - }, + settings = { + json = { + schemas = extended_schemas, + }, + }, + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + end, }, }, } -- cgit v1.2.3 From 76bee64f17cb7e7db33ee61645088d2b0729eb09 Mon Sep 17 00:00:00 2001 From: dklymenk <64093836+dklymenk@users.noreply.github.com> Date: Tue, 5 Oct 2021 00:09:40 +0300 Subject: fix: return null ls setup user config (#1683) --- lua/lsp/config.lua | 3 +++ lua/lsp/null-ls/init.lua | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/lsp/config.lua b/lua/lsp/config.lua index f9184e6f..521ab50a 100644 --- a/lua/lsp/config.lua +++ b/lua/lsp/config.lua @@ -21,4 +21,7 @@ return { on_attach_callback = nil, on_init_callback = nil, automatic_servers_installation = true, + null_ls = { + setup = {}, + }, } diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index 0540fb48..1d0af77b 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -12,7 +12,7 @@ function M:setup() end null_ls.config() - require("lspconfig")["null-ls"].setup {} + require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) for _, filetype in pairs(lvim.lang) do if filetype.formatters then formatters.setup(filetype.formatters, filetype) -- cgit v1.2.3 From 5fe7b7ad4d6fa699ca9cc306a788d6485fc0ba8d Mon Sep 17 00:00:00 2001 From: Subho Banerjee Date: Tue, 5 Oct 2021 14:29:58 -0500 Subject: feat(lsp): make lsp buffer-mappings configurable (#1687) --- lua/lsp/config.lua | 17 +++++++++++++++++ lua/lsp/init.lua | 40 ++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 18 deletions(-) (limited to 'lua') diff --git a/lua/lsp/config.lua b/lua/lsp/config.lua index 521ab50a..32185b56 100644 --- a/lua/lsp/config.lua +++ b/lua/lsp/config.lua @@ -21,6 +21,23 @@ return { on_attach_callback = nil, on_init_callback = nil, automatic_servers_installation = true, + buffer_mappings = { + normal_mode = { + ["K"] = { "lua vim.lsp.buf.hover()", "Show hover" }, + ["gd"] = { "lua vim.lsp.buf.definition()", "Goto Definition" }, + ["gD"] = { "lua vim.lsp.buf.declaration()", "Goto declaration" }, + ["gr"] = { "lua vim.lsp.buf.references()", "Goto references" }, + ["gI"] = { "lua vim.lsp.buf.implementation()", "Goto Implementation" }, + ["gs"] = { "lua vim.lsp.buf.signature_help()", "show signature help" }, + ["gp"] = { "lua require'lsp.peek'.Peek('definition')", "Peek definition" }, + ["gl"] = { + "lua require'lsp.handlers'.show_line_diagnostics()", + "Show line diagnostics", + }, + }, + insert_mode = {}, + visual_mode = {}, + }, null_ls = { setup = {}, }, diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index fae7ca8d..284b9dfe 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -22,25 +22,29 @@ local function lsp_highlight_document(client) end local function add_lsp_buffer_keybindings(bufnr) - local status_ok, wk = pcall(require, "which-key") - if not status_ok then - return - end - - local keys = { - ["K"] = { "lua vim.lsp.buf.hover()", "Show hover" }, - ["gd"] = { "lua vim.lsp.buf.definition()", "Goto Definition" }, - ["gD"] = { "lua vim.lsp.buf.declaration()", "Goto declaration" }, - ["gr"] = { "lua vim.lsp.buf.references()", "Goto references" }, - ["gI"] = { "lua vim.lsp.buf.implementation()", "Goto Implementation" }, - ["gs"] = { "lua vim.lsp.buf.signature_help()", "show signature help" }, - ["gp"] = { "lua require'lsp.peek'.Peek('definition')", "Peek definition" }, - ["gl"] = { - "lua require'lsp.handlers'.show_line_diagnostics()", - "Show line diagnostics", - }, + local mappings = { + normal_mode = "n", + insert_mode = "i", + visual_mode = "v", } - wk.register(keys, { mode = "n", buffer = bufnr }) + + if lvim.builtin.which_key.active then + -- Remap using which_key + local status_ok, wk = pcall(require, "which-key") + if not status_ok then + return + end + for mode_name, mode_char in pairs(mappings) do + wk.register(lvim.lsp.buffer_mappings[mode_name], { mode = mode_char, buffer = bufnr }) + end + else + -- Remap using nvim api + for mode_name, mode_char in pairs(mappings) do + for key, remap in pairs(lvim.lsp.buffer_mappings[mode_name]) do + vim.api.nvim_buf_set_keymap(bufnr, mode_char, key, remap[1], { noremap = true, silent = true }) + end + end + end end function M.common_capabilities() -- cgit v1.2.3 From 0ad60e90a9b0dd557df10f73bec344e88549a9d7 Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Wed, 6 Oct 2021 02:07:23 +0330 Subject: [Feature] better code action prompt and auto show codelens actions (#1698) --- lua/core/telescope.lua | 20 ++++++++++++++++++++ lua/core/which-key.lua | 3 ++- lua/lsp/config.lua | 1 + lua/lsp/init.lua | 20 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index eba27eec..0fb735fa 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -159,6 +159,26 @@ function M.view_lunarvim_changelog() }):find() end +function M.code_actions() + local opts = { + winblend = 15, + layout_config = { + prompt_position = "top", + width = 80, + height = 12, + }, + borderchars = { + prompt = { "─", "│", " ", "│", "╭", "╮", "│", "│" }, + results = { "─", "│", "─", "│", "├", "┤", "╯", "╰" }, + preview = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + }, + border = {}, + previewer = false, + shorten_path = false, + } + require("telescope.builtin").lsp_code_actions(require("telescope.themes").get_dropdown(opts)) +end + function M.setup() local telescope = require "telescope" diff --git a/lua/core/which-key.lua b/lua/core/which-key.lua index a115bcc5..c9e9b2f4 100644 --- a/lua/core/which-key.lua +++ b/lua/core/which-key.lua @@ -139,7 +139,7 @@ M.config = function() l = { name = "LSP", - a = { "lua vim.lsp.buf.code_action()", "Code Action" }, + a = { "lua require('core.telescope').code_actions()", "Code Action" }, d = { "Telescope lsp_document_diagnostics", "Document Diagnostics", @@ -159,6 +159,7 @@ M.config = function() "lua vim.lsp.diagnostic.goto_prev({popup_opts = {border = lvim.lsp.popup_border}})", "Prev Diagnostic", }, + l = { "lua vim.lsp.codelens.run()", "CodeLens Action" }, p = { name = "Peek", d = { "lua require('lsp.peek').Peek('definition')", "Definition" }, diff --git a/lua/lsp/config.lua b/lua/lsp/config.lua index 32185b56..f13d9659 100644 --- a/lua/lsp/config.lua +++ b/lua/lsp/config.lua @@ -17,6 +17,7 @@ return { }, override = {}, document_highlight = true, + code_lens_refresh = true, popup_border = "single", on_attach_callback = nil, on_init_callback = nil, diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 284b9dfe..2631c0fc 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -21,6 +21,25 @@ local function lsp_highlight_document(client) end end +local function lsp_code_lens_refresh(client) + if lvim.lsp.code_lens_refresh == false then + return + end + + if client.resolved_capabilities.code_lens then + vim.api.nvim_exec( + [[ + augroup lsp_code_lens_refresh + autocmd! * + autocmd InsertLeave lua vim.lsp.codelens.refresh() + autocmd InsertLeave lua vim.lsp.codelens.display() + augroup END + ]], + false + ) + end +end + local function add_lsp_buffer_keybindings(bufnr) local mappings = { normal_mode = "n", @@ -99,6 +118,7 @@ function M.common_on_attach(client, bufnr) Log:debug "Called lsp.on_attach_callback" end lsp_highlight_document(client) + lsp_code_lens_refresh(client) add_lsp_buffer_keybindings(bufnr) end -- cgit v1.2.3 From c0e3c8d43ae6ca011e4036329ae31115957d1394 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 7 Oct 2021 17:47:53 +0200 Subject: feat(lsp): handle user configuration in setup() (#1707) --- lua/bootstrap.lua | 49 +++++++++++++++---------------- lua/core/commands.lua | 4 +-- lua/lsp/init.lua | 1 + lua/lsp/manager.lua | 81 ++++++++++++++++++++++++++------------------------- lua/lsp/templates.lua | 2 +- lua/utils/hooks.lua | 33 +++++++++++++++++++++ 6 files changed, 102 insertions(+), 68 deletions(-) create mode 100644 lua/utils/hooks.lua (limited to 'lua') diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index 43ce44d5..866403b7 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -1,6 +1,7 @@ local M = {} -local in_headless = #vim.api.nvim_list_uis() == 0 +package.loaded["utils.hooks"] = nil +local _, hooks = pcall(require, "utils.hooks") ---Join path segments that were passed as input ---@return string @@ -42,12 +43,23 @@ function _G.get_cache_dir() return lvim_cache_dir end +---Get the full path to the currently installed lunarvim repo +---@return string +local function get_install_path() + local lvim_runtime_dir = os.getenv "LUNARVIM_RUNTIME_DIR" + if not lvim_runtime_dir then + -- when nvim is used directly + return vim.fn.stdpath "config" + end + return join_paths(lvim_runtime_dir, "lvim") +end + ---Get currently installed version of LunarVim ---@param type string can be "short" ---@return string function _G.get_version(type) type = type or "" - local lvim_full_ver = vim.fn.system("git -C " .. get_runtime_dir() .. "/lvim describe --tags") + local lvim_full_ver = vim.fn.system("git -C " .. get_install_path() .. " describe --tags") if string.match(lvim_full_ver, "%d") == nil then return nil @@ -65,7 +77,7 @@ function M:init() self.runtime_dir = get_runtime_dir() self.config_dir = get_config_dir() self.cache_path = get_cache_dir() - self.repo_dir = join_paths(self.runtime_dir, "lvim") + self.install_path = get_install_path() self.pack_dir = join_paths(self.runtime_dir, "site", "pack") self.packer_install_dir = join_paths(self.runtime_dir, "site", "pack", "packer", "start", "packer.nvim") @@ -113,23 +125,15 @@ end ---Update LunarVim ---pulls the latest changes from github and, resets the startup cache function M:update() + hooks.run_pre_update() M:update_repo() - M:reset_cache() - require("lsp.templates").generate_templates() - if not in_headless then - vim.schedule(function() - require("packer").install() - -- TODO: add a changelog - vim.notify("Update complete", vim.log.levels.INFO) - end) - end + hooks.run_post_update() end local function git_cmd(subcmd) local Job = require "plenary.job" local Log = require "core.log" - local repo_dir = join_paths(get_runtime_dir(), "lvim") - local args = { "-C", repo_dir } + local args = { "-C", get_install_path() } vim.list_extend(args, subcmd) local stderr = {} @@ -137,7 +141,7 @@ local function git_cmd(subcmd) :new({ command = "git", args = args, - cwd = repo_dir, + cwd = get_install_path(), on_stderr = function(_, data) table.insert(stderr, data) end, @@ -167,7 +171,8 @@ function M:update_repo() local ret = git_cmd(sub_commands.fetch) if ret ~= 0 then - error "Update failed! Check the log for further information" + Log:error "Update failed! Check the log for further information" + return end ret = git_cmd(sub_commands.diff) @@ -180,17 +185,9 @@ function M:update_repo() ret = git_cmd(sub_commands.merge) if ret ~= 0 then - error "Error: unable to guarantee data integrity while updating your branch" - error "Please pull the changes manually instead." + Log:error "Update failed! Please pull the changes manually instead." + return end end ----Reset any startup cache files used by Packer and Impatient ----Tip: Useful for clearing any outdated settings -function M:reset_cache() - _G.__luacache.clear_cache() - _G.__luacache.save_cache() - require("plugin-loader"):cache_reset() -end - return M diff --git a/lua/core/commands.lua b/lua/core/commands.lua index f732c9a2..6ceeaaff 100644 --- a/lua/core/commands.lua +++ b/lua/core/commands.lua @@ -11,8 +11,8 @@ M.defaults = { endfunction ]], -- :LvimInfo - [[command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype)]], - [[ command! LvimCacheReset lua require('bootstrap').reset_cache() ]], + [[ command! LvimInfo lua require('core.info').toggle_popup(vim.bo.filetype) ]], + [[ command! LvimCacheReset lua require('utils.hooks').reset_cache() ]], [[ command! LvimUpdate lua require('bootstrap').update() ]], } diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 2631c0fc..18b27513 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -149,6 +149,7 @@ function M.setup() for _, sign in ipairs(lvim.lsp.diagnostics.signs.values) do vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = sign.name }) end + require("lsp.handlers").setup() if not utils.is_directory(lvim.lsp.templates_dir) then diff --git a/lua/lsp/manager.lua b/lua/lsp/manager.lua index a2f23a7b..9cb81910 100644 --- a/lua/lsp/manager.lua +++ b/lua/lsp/manager.lua @@ -24,59 +24,62 @@ local function is_overridden(server) end end -function M.setup_server(server_name) - vim.validate { - name = { server_name, "string" }, - } - - if lsp_utils.is_client_active(server_name) or is_overridden(server_name) then - return - end - - local lsp_installer_servers = require "nvim-lsp-installer.servers" - local server_available, requested_server = lsp_installer_servers.get_server(server_name) - if server_available then - if not requested_server:is_installed() then - Log:debug(string.format("[%s] is not installed", server_name)) - if lvim.lsp.automatic_servers_installation then - Log:debug(string.format("Installing [%s]", server_name)) - requested_server:install() - else - return - end - end - end - - local default_config = { +---Resolve the configuration for a server based on both common and user configuration +---@param name string +---@param user_config table [optional] +---@return table +local function resolve_config(name, user_config) + local config = { on_attach = require("lsp").common_on_attach, on_init = require("lsp").common_on_init, capabilities = require("lsp").common_capabilities(), } - local status_ok, custom_config = pcall(require, "lsp/providers/" .. requested_server.name) + local status_ok, custom_config = pcall(require, "lsp/providers/" .. name) if status_ok then - local new_config = vim.tbl_deep_extend("force", default_config, custom_config) - Log:debug("Using custom configuration for requested server: " .. requested_server.name) - requested_server:setup(new_config) - else - Log:debug("Using the default configuration for requested server: " .. requested_server.name) - requested_server:setup(default_config) + Log:debug("Using custom configuration for requested server: " .. name) + config = vim.tbl_deep_extend("force", config, custom_config) end + + if user_config then + config = vim.tbl_deep_extend("force", config, user_config) + end + + return config end -function M.setup(servers) - local status_ok, _ = pcall(require, "nvim-lsp-installer") - if not status_ok then +---Setup a language server by providing a name +---@param server_name string name of the language server +---@param user_config table [optional] when available it will take predence over any default configurations +function M.setup(server_name, user_config) + vim.validate { name = { server_name, "string" } } + + if lsp_utils.is_client_active(server_name) or is_overridden(server_name) then return end - --- allow using a single value - if type(servers) == "string" then - servers = { servers } + local config = resolve_config(server_name, user_config) + local server_available, requested_server = require("nvim-lsp-installer.servers").get_server(server_name) + + local function ensure_installed(server) + if server:is_installed() then + return true + end + if not lvim.lsp.automatic_servers_installation then + Log:debug(server.name .. " is not managed by the automatic installer") + return false + end + Log:debug(string.format("Installing [%s]", server.name)) + server:install() + vim.schedule(function() + vim.cmd [[LspStart]] + end) end - for _, server in ipairs(servers) do - M.setup_server(server) + if server_available and ensure_installed(requested_server) then + requested_server:setup(config) + else + require("lspconfig")[server_name].setup(config) end end diff --git a/lua/lsp/templates.lua b/lua/lsp/templates.lua index 6ded636d..fbbc37f6 100644 --- a/lua/lsp/templates.lua +++ b/lua/lsp/templates.lua @@ -23,7 +23,7 @@ function M.is_ignored(server_name, filetypes) filetypes = filetypes or get_supported_filetypes(server_name) if vim.tbl_contains(filetypes, "javascript") then - if server_name == "tsserver" or server_name == "tailwindcss" then + if server_name == "tsserver" then return false else return true diff --git a/lua/utils/hooks.lua b/lua/utils/hooks.lua new file mode 100644 index 00000000..fa667cfd --- /dev/null +++ b/lua/utils/hooks.lua @@ -0,0 +1,33 @@ +local M = {} + +local Log = require "core.log" +local in_headless = #vim.api.nvim_list_uis() == 0 + +function M.run_pre_update() + Log:debug "Starting pre-update hook" +end + +---Reset any startup cache files used by Packer and Impatient +---Tip: Useful for clearing any outdated settings +function M.reset_cache() + _G.__luacache.clear_cache() + require("plugin-loader"):cache_reset() +end + +function M.run_post_update() + M.reset_cache() + Log:debug "Starting post-update hook" + package.loaded["lsp.templates"] = nil + require("lsp.templates").generate_templates() + + if not in_headless then + vim.schedule(function() + require("packer").install() + -- TODO: add a changelog + vim.notify("Update complete", vim.log.levels.INFO) + vim.cmd "LspStart" + end) + end +end + +return M -- cgit v1.2.3 From f4899e316516fc6fc544b148cb7e9a04fbda130e Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Fri, 8 Oct 2021 08:57:11 +0200 Subject: fix: register null-ls providers per filetype (#1709) --- lua/lsp/null-ls/formatters.lua | 13 ++++++++----- lua/lsp/null-ls/init.lua | 10 +++++----- lua/lsp/null-ls/linters.lua | 13 ++++++++----- 3 files changed, 21 insertions(+), 15 deletions(-) (limited to 'lua') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 8199aca0..636b0bde 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return formatters end -function M.list_configured(formatter_configs) +function M.list_configured(formatter_configs, filetype) local formatters, errors = {}, {} for _, fmt_config in ipairs(formatter_configs) do @@ -39,7 +39,11 @@ function M.list_configured(formatter_configs) errors[fmt_config.exe] = {} -- Add data here when necessary else Log:debug("Using formatter: " .. formatter_cmd) - formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args } + formatters[fmt_config.exe] = formatter.with { + command = formatter_cmd, + extra_args = fmt_config.args, + filetypes = { filetype }, + } end end end @@ -52,9 +56,8 @@ function M.setup(formatter_configs, filetype) return end - local formatters_by_ft = {} - formatters_by_ft[filetype] = M.list_configured(formatter_configs) - null_ls.register { sources = formatters_by_ft[filetype].supported } + local formatters_by_ft = M.list_configured(formatter_configs, filetype) + null_ls.register { sources = formatters_by_ft.supported } end return M diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index 1d0af77b..3c8909af 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -13,12 +13,12 @@ function M:setup() null_ls.config() require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) - for _, filetype in pairs(lvim.lang) do - if filetype.formatters then - formatters.setup(filetype.formatters, filetype) + for filetype, config in pairs(lvim.lang) do + if not vim.tbl_isempty(config.formatters) then + formatters.setup(config.formatters, filetype) end - if filetype.linters then - linters.setup(filetype.linters, filetype) + if not vim.tbl_isempty(config.linters) then + linters.setup(config.linters, filetype) end end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index ea45fa87..34a78a65 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return linters end -function M.list_configured(linter_configs) +function M.list_configured(linter_configs, filetype) local linters, errors = {}, {} for _, lnt_config in pairs(linter_configs) do @@ -39,7 +39,11 @@ function M.list_configured(linter_configs) errors[lnt_config.exe] = {} -- Add data here when necessary else Log:debug("Using linter: " .. linter_cmd) - linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args } + linters[lnt_config.exe] = linter.with { + command = linter_cmd, + extra_args = lnt_config.args, + filetypes = { filetype }, + } end end end @@ -52,9 +56,8 @@ function M.setup(linter_configs, filetype) return end - local linters_by_ft = {} - linters_by_ft[filetype] = M.list_configured(linter_configs) - null_ls.register { sources = linters_by_ft[filetype].supported } + local linters_by_ft = M.list_configured(linter_configs, filetype) + null_ls.register { sources = linters_by_ft.supported } end return M -- cgit v1.2.3 From a814ea2e14792f542092f7428e7c5446b0908b03 Mon Sep 17 00:00:00 2001 From: Chris Dawkins Date: Fri, 8 Oct 2021 01:00:05 -0600 Subject: fix: correct variable names in NvimTree setup table (#1710) Co-authored-by: chris --- lua/core/nvimtree.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/core/nvimtree.lua b/lua/core/nvimtree.lua index 8d3b1b6a..55cc6175 100644 --- a/lua/core/nvimtree.lua +++ b/lua/core/nvimtree.lua @@ -6,9 +6,9 @@ function M.config() active = true, on_config_done = nil, setup = { - auto_open = 0, + open_on_setup = 0, auto_close = 1, - tab_open = 0, + open_on_tab = 0, update_focused_file = { enable = 1, }, -- cgit v1.2.3 From 85e7b7804a2c9d6847ff978c82bb3a3ac16d757f Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Fri, 8 Oct 2021 22:24:55 +0330 Subject: fix: don't use the cmp floating window (#1715) --- lua/core/cmp.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lua') diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua index 965285c7..b058bd6a 100644 --- a/lua/core/cmp.lua +++ b/lua/core/cmp.lua @@ -34,6 +34,10 @@ M.config = function() behavior = cmp.ConfirmBehavior.Replace, select = true, }, + experimental = { + ghost_text = false, + native_menu = true, + }, formatting = { kind_icons = { Class = " ", -- cgit v1.2.3 From e2df61f2565e2b1c16444b31e657f1f9df8e716b Mon Sep 17 00:00:00 2001 From: Xavier Young <45989017+younger-1@users.noreply.github.com> Date: Sat, 9 Oct 2021 13:55:45 +0800 Subject: fix(telescope): prompt position when find/grep LunarVim files (#1711) --- lua/core/telescope.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/core/telescope.lua b/lua/core/telescope.lua index 0fb735fa..ba0a9ee1 100644 --- a/lua/core/telescope.lua +++ b/lua/core/telescope.lua @@ -26,7 +26,6 @@ function M.config() layout_strategy = "horizontal", layout_config = { width = 0.75, - prompt_position = "bottom", preview_cutoff = 120, horizontal = { mirror = false }, vertical = { mirror = false }, @@ -91,7 +90,7 @@ function M.find_lunarvim_files(opts) local theme_opts = themes.get_ivy { sorting_strategy = "ascending", layout_strategy = "bottom_pane", - prompt = ">> ", + prompt_prefix = ">> ", prompt_title = "~ LunarVim files ~", cwd = utils.join_paths(get_runtime_dir(), "lvim"), find_command = { "git", "ls-files" }, @@ -106,7 +105,7 @@ function M.grep_lunarvim_files(opts) local theme_opts = themes.get_ivy { sorting_strategy = "ascending", layout_strategy = "bottom_pane", - prompt = ">> ", + prompt_prefix = ">> ", prompt_title = "~ search LunarVim ~", cwd = utils.join_paths(get_runtime_dir(), "lvim"), } -- cgit v1.2.3 From 5fef931d8720f2ef0d7a0fca18b96f31fd36689a Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 9 Oct 2021 09:33:23 +0330 Subject: fix: move jsonls commands under setup (#1685) --- lua/lsp/providers/jsonls.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lua') diff --git a/lua/lsp/providers/jsonls.lua b/lua/lsp/providers/jsonls.lua index 72c67b47..1fffa686 100644 --- a/lua/lsp/providers/jsonls.lua +++ b/lua/lsp/providers/jsonls.lua @@ -183,11 +183,13 @@ local opts = { schemas = extended_schemas, }, }, - commands = { - Format = { - function() - vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) - end, + setup = { + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + end, + }, }, }, } -- cgit v1.2.3 From 195b07a464d37328892a502cf7ce3690b6a5b2e4 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 9 Oct 2021 13:38:35 +0200 Subject: fix(lsp): use correct check for formatter override (#1726) --- lua/lsp/init.lua | 3 +-- lua/lsp/utils.lua | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'lua') diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 18b27513..88111005 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -94,11 +94,10 @@ local function select_default_formater(client) Log:debug("Checking for formatter overriding for " .. client.name) local client_filetypes = client.config.filetypes or {} for _, filetype in ipairs(client_filetypes) do - if not vim.tbl_isempty(lvim.lang[filetype].formatters) then + if lvim.lang[filetype] and #vim.tbl_keys(lvim.lang[filetype].formatters) > 0 then Log:debug("Formatter overriding detected. Disabling formatting capabilities for " .. client.name) client.resolved_capabilities.document_formatting = false client.resolved_capabilities.document_range_formatting = false - return end end end diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua index 1a5dd79d..87ba2337 100644 --- a/lua/lsp/utils.lua +++ b/lua/lsp/utils.lua @@ -10,12 +10,6 @@ function M.is_client_active(name) return false end -function M.disable_formatting_capability(client) - -- FIXME: figure out a reasonable way to do this - client.resolved_capabilities.document_formatting = false - require("core.log"):debug(string.format("Turning off formatting capability for language server [%s] ", client.name)) -end - function M.get_active_client_by_ft(filetype) local matches = {} local clients = vim.lsp.get_active_clients() -- cgit v1.2.3 From efd82c87568a791b2f7fb9c94b763f2c1950dc8e Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Sat, 9 Oct 2021 13:39:15 +0200 Subject: feat: configure multiple filetypes per provider (#1725) --- lua/lsp/null-ls/formatters.lua | 8 ++++---- lua/lsp/null-ls/init.lua | 10 ++++++++-- lua/lsp/null-ls/linters.lua | 10 +++++----- 3 files changed, 17 insertions(+), 11 deletions(-) (limited to 'lua') diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index 636b0bde..d6455d5f 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return formatters end -function M.list_configured(formatter_configs, filetype) +function M.list_configured(formatter_configs) local formatters, errors = {}, {} for _, fmt_config in ipairs(formatter_configs) do @@ -42,7 +42,7 @@ function M.list_configured(formatter_configs, filetype) formatters[fmt_config.exe] = formatter.with { command = formatter_cmd, extra_args = fmt_config.args, - filetypes = { filetype }, + filetypes = fmt_config.filetypes, } end end @@ -51,12 +51,12 @@ function M.list_configured(formatter_configs, filetype) return { supported = formatters, unsupported = errors } end -function M.setup(formatter_configs, filetype) +function M.setup(formatter_configs) if vim.tbl_isempty(formatter_configs) then return end - local formatters_by_ft = M.list_configured(formatter_configs, filetype) + local formatters_by_ft = M.list_configured(formatter_configs) null_ls.register { sources = formatters_by_ft.supported } end diff --git a/lua/lsp/null-ls/init.lua b/lua/lsp/null-ls/init.lua index 3c8909af..0d030c22 100644 --- a/lua/lsp/null-ls/init.lua +++ b/lua/lsp/null-ls/init.lua @@ -15,10 +15,16 @@ function M:setup() require("lspconfig")["null-ls"].setup(lvim.lsp.null_ls.setup) for filetype, config in pairs(lvim.lang) do if not vim.tbl_isempty(config.formatters) then - formatters.setup(config.formatters, filetype) + vim.tbl_map(function(c) + c.filetypes = { filetype } + end, config.formatters) + formatters.setup(config.formatters) end if not vim.tbl_isempty(config.linters) then - linters.setup(config.linters, filetype) + vim.tbl_map(function(c) + c.filetypes = { filetype } + end, config.formatters) + linters.setup(config.linters) end end end diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index 34a78a65..e60411e6 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -23,7 +23,7 @@ function M.list_available(filetype) return linters end -function M.list_configured(linter_configs, filetype) +function M.list_configured(linter_configs) local linters, errors = {}, {} for _, lnt_config in pairs(linter_configs) do @@ -42,7 +42,7 @@ function M.list_configured(linter_configs, filetype) linters[lnt_config.exe] = linter.with { command = linter_cmd, extra_args = lnt_config.args, - filetypes = { filetype }, + filetypes = lnt_config.filetypes, } end end @@ -51,13 +51,13 @@ function M.list_configured(linter_configs, filetype) return { supported = linters, unsupported = errors } end -function M.setup(linter_configs, filetype) +function M.setup(linter_configs) if vim.tbl_isempty(linter_configs) then return end - local linters_by_ft = M.list_configured(linter_configs, filetype) - null_ls.register { sources = linters_by_ft.supported } + local linters = M.list_configured(linter_configs) + null_ls.register { sources = linters.supported } end return M -- cgit v1.2.3 From b524100f016de6b934894547d48f9ef811902397 Mon Sep 17 00:00:00 2001 From: Luc Sinet Date: Sat, 9 Oct 2021 13:45:34 +0200 Subject: feat: support wildcard filetypes for null-ls providers (#1447) Co-authored-by: kylo252 <59826753+kylo252@users.noreply.github.com> --- lua/core/info.lua | 6 +++--- lua/lsp/null-ls/formatters.lua | 9 ++++++--- lua/lsp/null-ls/linters.lua | 9 ++++++--- lua/lsp/null-ls/services.lua | 4 ++-- lua/lsp/utils.lua | 15 +++++++-------- lua/utils/table.lua | 24 ++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 lua/utils/table.lua (limited to 'lua') diff --git a/lua/core/info.lua b/lua/core/info.lua index ff024fa5..16001d07 100644 --- a/lua/core/info.lua +++ b/lua/core/info.lua @@ -11,6 +11,7 @@ local M = { local fmt = string.format local text = require "interface.text" +local lsp_utils = require "lsp.utils" local function str_list(list) return fmt("[ %s ]", table.concat(list, ", ")) @@ -67,7 +68,7 @@ local function tbl_set_highlight(terms, highlight_group) end local function make_client_info(client) - local client_enabled_caps = require("lsp.utils").get_ls_capabilities(client.id) + local client_enabled_caps = lsp_utils.get_client_capabilities(client.id) local name = client.name local id = client.id local document_formatting = client.resolved_capabilities.document_formatting @@ -89,8 +90,7 @@ local function make_client_info(client) end function M.toggle_popup(ft) - local lsp_utils = require "lsp.utils" - local clients = lsp_utils.get_active_client_by_ft(ft) + local clients = lsp_utils.get_active_clients_by_ft(ft) local client_names = {} local header = { diff --git a/lua/lsp/null-ls/formatters.lua b/lua/lsp/null-ls/formatters.lua index d6455d5f..4728b908 100644 --- a/lua/lsp/null-ls/formatters.lua +++ b/lua/lsp/null-ls/formatters.lua @@ -13,9 +13,11 @@ end function M.list_available(filetype) local formatters = {} + local tbl = require "utils.table" for _, provider in pairs(null_ls.builtins.formatting) do - -- TODO: Add support for wildcard filetypes - if vim.tbl_contains(provider.filetypes or {}, filetype) then + if tbl.contains(provider.filetypes or {}, function(ft) + return ft == "*" or ft == filetype + end) then table.insert(formatters, provider.name) end end @@ -27,7 +29,8 @@ function M.list_configured(formatter_configs) local formatters, errors = {}, {} for _, fmt_config in ipairs(formatter_configs) do - local formatter = null_ls.builtins.formatting[fmt_config.exe] + local formatter_name = fmt_config.exe:gsub("-", "_") + local formatter = null_ls.builtins.formatting[formatter_name] if not formatter then Log:error("Not a valid formatter: " .. fmt_config.exe) diff --git a/lua/lsp/null-ls/linters.lua b/lua/lsp/null-ls/linters.lua index e60411e6..549c6cdd 100644 --- a/lua/lsp/null-ls/linters.lua +++ b/lua/lsp/null-ls/linters.lua @@ -13,9 +13,11 @@ end function M.list_available(filetype) local linters = {} + local tbl = require "utils.table" for _, provider in pairs(null_ls.builtins.diagnostics) do - -- TODO: Add support for wildcard filetypes - if vim.tbl_contains(provider.filetypes or {}, filetype) then + if tbl.contains(provider.filetypes or {}, function(ft) + return ft == "*" or ft == filetype + end) then table.insert(linters, provider.name) end end @@ -27,7 +29,8 @@ function M.list_configured(linter_configs) local linters, errors = {}, {} for _, lnt_config in pairs(linter_configs) do - local linter = null_ls.builtins.diagnostics[lnt_config.exe] + local linter_name = lnt_config.exe:gsub("-", "_") + local linter = null_ls.builtins.diagnostics[linter_name] if not linter then Log:error("Not a valid linter: " .. lnt_config.exe) diff --git a/lua/lsp/null-ls/services.lua b/lua/lsp/null-ls/services.lua index c62fc709..ef9e7d22 100644 --- a/lua/lsp/null-ls/services.lua +++ b/lua/lsp/null-ls/services.lua @@ -4,8 +4,8 @@ local function find_root_dir() local util = require "lspconfig/util" local lsp_utils = require "lsp.utils" - local status_ok, ts_client = lsp_utils.is_client_active "typescript" - if status_ok then + local ts_client = lsp_utils.is_client_active "typescript" + if ts_client then return ts_client.config.root_dir end local dirname = vim.fn.expand "%:p:h" diff --git a/lua/lsp/utils.lua b/lua/lsp/utils.lua index 87ba2337..59003406 100644 --- a/lua/lsp/utils.lua +++ b/lua/lsp/utils.lua @@ -1,16 +1,15 @@ local M = {} +local tbl = require "utils.table" + function M.is_client_active(name) local clients = vim.lsp.get_active_clients() - for _, client in pairs(clients) do - if client.name == name then - return true, client - end - end - return false + return tbl.find_first(clients, function(client) + return client.name == name + end) end -function M.get_active_client_by_ft(filetype) +function M.get_active_clients_by_ft(filetype) local matches = {} local clients = vim.lsp.get_active_clients() for _, client in pairs(clients) do @@ -22,7 +21,7 @@ function M.get_active_client_by_ft(filetype) return matches end -function M.get_ls_capabilities(client_id) +function M.get_client_capabilities(client_id) if not client_id then local buf_clients = vim.lsp.buf_get_clients() for _, buf_client in ipairs(buf_clients) do diff --git a/lua/utils/table.lua b/lua/utils/table.lua new file mode 100644 index 00000000..1ac5949e --- /dev/null +++ b/lua/utils/table.lua @@ -0,0 +1,24 @@ +local Table = {} + +--- Find the first entry for which the predicate returns true. +-- @param t The table +-- @param predicate The function called for each entry of t +-- @return The entry for which the predicate returned True or nil +function Table.find_first(t, predicate) + for _, entry in pairs(t) do + if predicate(entry) then + return entry + end + end + return nil +end + +--- Check if the predicate returns True for at least one entry of the table. +-- @param t The table +-- @param predicate The function called for each entry of t +-- @return True if predicate returned True at least once, false otherwise +function Table.contains(t, predicate) + return Table.find_first(t, predicate) ~= nil +end + +return Table -- cgit v1.2.3 From 484c618d09150980746afd37b34b96f1ce15b81d Mon Sep 17 00:00:00 2001 From: Abouzar Parvan Date: Sat, 9 Oct 2021 17:51:32 +0330 Subject: feat: support nvim-cmp floating menu highlights (#1719) --- lua/onedarker/highlights.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lua') diff --git a/lua/onedarker/highlights.lua b/lua/onedarker/highlights.lua index dbdd2416..28e7c07f 100644 --- a/lua/onedarker/highlights.lua +++ b/lua/onedarker/highlights.lua @@ -94,6 +94,14 @@ local highlights = { TabLine = { fg = C.light_gray, bg = C.alt_bg }, TabLineSel = { fg = C.fg, bg = C.alt_bg }, TabLineFill = { fg = C.fg, bg = C.alt_bg }, + CmpDocumentation = { fg = C.fg, bg = C.none }, + CmpDocumentationBorder = { fg = C.fg_dark, bg = C.none }, + CmpItemAbbr = { fg = C.fg, bg = C.none }, + CmpItemAbbrDeprecated = { fg = C.gray, bg = C.none }, + CmpItemAbbrMatch = { fg = C.cyan, bg = C.none }, + CmpItemAbbrMatchFuzzy = { fg = C.cyan, bg = C.none }, + CmpItemKind = { fg = C.blue, bg = C.none }, + CmpItemMenu = { fg = C.light_gray, bg = C.none }, } return highlights -- cgit v1.2.3 From 82b7a35858479223c1e34bea2f64451ecf1e5f66 Mon Sep 17 00:00:00 2001 From: Chase Colman <5411+chase@users.noreply.github.com> Date: Sun, 10 Oct 2021 02:47:01 +0800 Subject: fix(cmp/autopairs): prevent out of bounds jump and re-enable jump after confirm (#1708) --- lua/core/autopairs.lua | 12 ++--- lua/core/cmp.lua | 128 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 116 insertions(+), 24 deletions(-) (limited to 'lua') diff --git a/lua/core/autopairs.lua b/lua/core/autopairs.lua index a67f3b07..eb080fb1 100644 --- a/lua/core/autopairs.lua +++ b/lua/core/autopairs.lua @@ -4,14 +4,8 @@ function M.config() lvim.builtin.autopairs = { active = true, on_config_done = nil, - ---@usage map on insert mode - map_cr = true, ---@usage auto insert after select function or method item map_complete = true, - ---@usage automatically select the first item - auto_select = true, - ---@usage use insert confirm behavior instead of replace - insert = false, ---@usage -- modifies the function or method delimiter by filetypes map_char = { all = "(", @@ -60,12 +54,12 @@ M.setup = function() if package.loaded["cmp"] then require("nvim-autopairs.completion.cmp").setup { - map_cr = lvim.builtin.autopairs.map_cr, + map_cr = false, map_complete = lvim.builtin.autopairs.map_complete, - auto_select = lvim.builtin.autopairs.auto_select, - insert = lvim.builtin.autopairs.insert, map_char = lvim.builtin.autopairs.map_char, } + -- we map CR explicitly in cmp.lua but we still need to setup the autopairs CR keymap + vim.api.nvim_set_keymap("i", "", "v:lua.MPairs.autopairs_cr()", { expr = true, noremap = true }) end require("nvim-treesitter.configs").setup { autopairs = { enable = true } } diff --git a/lua/core/cmp.lua b/lua/core/cmp.lua index b058bd6a..d5d92314 100644 --- a/lua/core/cmp.lua +++ b/lua/core/cmp.lua @@ -29,14 +29,106 @@ M.config = function() if not status_luasnip_ok then return end + local win_get_cursor = vim.api.nvim_win_get_cursor + local get_current_buf = vim.api.nvim_get_current_buf + + local function inside_snippet() + -- for outdated versions of luasnip + if not luasnip.session.current_nodes then + return false + end + + local node = luasnip.session.current_nodes[get_current_buf()] + if not node then + return false + end + + local snip_begin_pos, snip_end_pos = node.parent.snippet.mark:pos_begin_end() + local pos = win_get_cursor(0) + pos[1] = pos[1] - 1 -- LuaSnip is 0-based not 1-based like nvim for rows + return pos[1] >= snip_begin_pos[1] and pos[1] <= snip_end_pos[1] + end + + ---sets the current buffer's luasnip to the one nearest the cursor + ---@return boolean true if a node is found, false otherwise + local function seek_luasnip_cursor_node() + -- for outdated versions of luasnip + if not luasnip.session.current_nodes then + return false + end + + local pos = win_get_cursor(0) + pos[1] = pos[1] - 1 + local node = luasnip.session.current_nodes[get_current_buf()] + if not node then + return false + end + + local snippet = node.parent.snippet + local exit_node = snippet.insert_nodes[0] + + -- exit early if we're past the exit node + if exit_node then + local exit_pos_end = exit_node.mark:pos_end() + if (pos[1] > exit_pos_end[1]) or (pos[1] == exit_pos_end[1] and pos[2] > exit_pos_end[2]) then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + node = snippet.inner_first:jump_into(1, true) + while node ~= nil and node.next ~= nil and node ~= snippet do + local n_next = node.next + local next_pos = n_next and n_next.mark:pos_begin() + local candidate = n_next ~= snippet and next_pos and (pos[1] < next_pos[1]) + or (pos[1] == next_pos[1] and pos[2] < next_pos[2]) + + -- Past unmarked exit node, exit early + if n_next == nil or n_next == snippet.next then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + + if candidate then + luasnip.session.current_nodes[get_current_buf()] = node + return true + end + + local ok + ok, node = pcall(node.jump_from, node, 1, true) -- no_move until last stop + if not ok then + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + + return false + end + end + + -- No candidate, but have an exit node + if exit_node then + -- to jump to the exit node, seek to snippet + luasnip.session.current_nodes[get_current_buf()] = snippet + return true + end + + -- No exit node, exit from snippet + snippet:remove_from_jumplist() + luasnip.session.current_nodes[get_current_buf()] = nil + return false + end + lvim.builtin.cmp = { confirm_opts = { behavior = cmp.ConfirmBehavior.Replace, - select = true, + select = false, }, experimental = { - ghost_text = false, - native_menu = true, + ghost_text = true, + native_menu = false, }, formatting = { kind_icons = { @@ -111,10 +203,12 @@ M.config = function() [""] = cmp.mapping.scroll_docs(4), -- TODO: potentially fix emmet nonsense [""] = cmp.mapping(function() - if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(T "", "n") - elseif luasnip.expand_or_jumpable() then - vim.fn.feedkeys(T "luasnip-expand-or-jump", "") + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() then + luasnip.jump(1) elseif check_backspace() then vim.fn.feedkeys(T "", "n") elseif is_emmet_active() then @@ -127,10 +221,10 @@ M.config = function() "s", }), [""] = cmp.mapping(function(fallback) - if vim.fn.pumvisible() == 1 then - vim.fn.feedkeys(T "", "n") - elseif luasnip.jumpable(-1) then - vim.fn.feedkeys(T "luasnip-jump-prev", "") + if cmp.visible() then + cmp.select_prev_item() + elseif inside_snippet() and luasnip.jumpable(-1) then + luasnip.jump(-1) else fallback() end @@ -142,12 +236,16 @@ M.config = function() [""] = cmp.mapping.complete(), [""] = cmp.mapping.close(), [""] = cmp.mapping(function(fallback) - if not require("cmp").confirm(lvim.builtin.cmp.confirm_opts) then - if luasnip.jumpable() then - vim.fn.feedkeys(T "luasnip-jump-next", "") - else + if cmp.visible() and cmp.confirm(lvim.builtin.cmp.confirm_opts) then + return + end + + if inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() then + if not luasnip.jump(1) then fallback() end + else + fallback() end end), }, -- cgit v1.2.3