diff --git a/vim/.vim/lua/config/lsp.lua b/vim/.vim/lua/config/lsp.lua index 6af18a5..deff0da 100644 --- a/vim/.vim/lua/config/lsp.lua +++ b/vim/.vim/lua/config/lsp.lua @@ -1,4 +1,7 @@ local use_google = require("utils").use_google +local tprint = require("utils").tprint +local dump = require("utils").dump +local log = require("utils").log local notify = require 'notify' local lsp_status = require('lsp-status') @@ -244,7 +247,6 @@ local conditionalSources = { }, } -local use_google = require("utils").use_google if use_google() then table.insert(conditionalSources, { name = 'nvim_ciderlsp', priority = 9 }) table.insert(conditionalSources, { name = 'analysislsp', priority = 9 }) @@ -253,6 +255,54 @@ else end +local i = 0 + +function cmp_format(opts) + if opts == nil then + opts = {} + end + if opts.preset or opts.symbol_map then + lspkind.init(opts) + end + + return function(entry, vim_item) + if opts.before then + vim_item = opts.before(entry, vim_item) + end + + vim_item.kind = lspkind.symbolic(vim_item.kind, opts) + if i == 0 then + if entry.source.name == "nvim_lsp" then + log(vim.json.encode(entry.source)) + i = i + 1 + end + end + + if opts.menu ~= nil then + vim_item.menu = opts.menu[entry.source.name] + -- if entry.source.client ~= nil then + -- if entry.source.client.name ~= nil then + -- log(entry.source.client.name) + -- end + -- end + -- vim_item.menu = opts.menu[entry.source.name+":"+entry.source.client.name] + end + + if opts.maxwidth ~= nil then + if opts.ellipsis_char == nil then + vim_item.abbr = string.sub(vim_item.abbr, 1, opts.maxwidth) + else + local label = vim_item.abbr + local truncated_label = vim.fn.strcharpart(label, 0, opts.maxwidth) + if truncated_label ~= label then + vim_item.abbr = truncated_label .. opts.ellipsis_char + end + end + end + return vim_item + end +end + cmp.setup({ mapping = { [""] = cmp.mapping.scroll_docs(-4), @@ -334,6 +384,7 @@ cmp.setup({ }, formatting = { + -- format = cmp_format({ format = lspkind.cmp_format({ with_text = true, maxwidth = 40, -- half max width diff --git a/vim/.vim/lua/plugins.lua b/vim/.vim/lua/plugins.lua index c1cbbd1..78f8b13 100644 --- a/vim/.vim/lua/plugins.lua +++ b/vim/.vim/lua/plugins.lua @@ -231,6 +231,8 @@ require('packer').startup(function(use) use 'scrooloose/nerdcommenter' use 'mhinz/vim-signify' use { 'j-hui/fidget.nvim', config = [[require("fidget").setup()]] } + use({ "iamcco/markdown-preview.nvim", run = "cd app && npm install", setup = function() vim.g.mkdp_filetypes = { "markdown" } end, ft = { "markdown" }, }) + -- Automatically set up your configuration after cloning packer.nvim -- Put this at the end after all plugins diff --git a/vim/.vim/lua/utils.lua b/vim/.vim/lua/utils.lua index 8bf07c7..b4fd873 100644 --- a/vim/.vim/lua/utils.lua +++ b/vim/.vim/lua/utils.lua @@ -30,4 +30,37 @@ function M.dump(o) end end +function M.tprint (tbl, indent) + if not indent then indent = 0 end + local toprint = string.rep(" ", indent) .. "{\r\n" + indent = indent + 2 + for k, v in pairs(tbl) do + toprint = toprint .. string.rep(" ", indent) + if (type(k) == "number") then + toprint = toprint .. "[" .. k .. "] = " + elseif (type(k) == "string") then + toprint = toprint .. k .. "= " + end + if (type(v) == "number") then + toprint = toprint .. v .. ",\r\n" + elseif (type(v) == "string") then + toprint = toprint .. "\"" .. v .. "\",\r\n" + elseif (type(v) == "table") then + toprint = toprint .. M.tprint(v, indent + 2) .. ",\r\n" + else + toprint = toprint .. "\"" .. tostring(v) .. "\",\r\n" + end + end + toprint = toprint .. string.rep(" ", indent-2) .. "}" + return toprint +end + +function M.log(message) + local log_file_path = vim.fn.expand('$HOME/nvim.log') + local log_file = io.open(log_file_path, "a") + io.output(log_file) + io.write(message.."\n") + io.close(log_file) +end + return M