Skip to content

Commit

Permalink
feat: UI styling, unrelated small fix to inlayhints clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
konradmalik committed Sep 26, 2023
1 parent 5e3b4d2 commit 08e5024
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ local luasnip = require("konrad.cmp.snippets")

local lazy = require("konrad.lazy")
-- load copilot on demand
lazy.make_enable_command(
"CopilotEnable",
{ "copilot.lua", "copilot-cmp" },
function()
require("konrad.cmp.copilot")
end,
{
desc = "Initialize Copilot server and cmp source",
})
lazy.make_enable_command("CopilotEnable", { "copilot.lua", "copilot-cmp" }, function()
require("konrad.cmp.copilot")
end, {
desc = "Initialize Copilot server and cmp source",
})

local cmp = require("cmp")

Expand All @@ -23,6 +19,13 @@ local menu_entries = {
path = "[Path]",
}

-- fill native LSP completion_item_kind
-- cmp is filled below in format
local kinds = vim.lsp.protocol.CompletionItemKind
for i, kind in ipairs(kinds) do
kinds[i] = kind_icons[kind] or kind
end

cmp.setup({
snippet = {
expand = function(args)
Expand All @@ -38,32 +41,32 @@ cmp.setup({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
['<C-n>'] = cmp.mapping(function(fallback)
["<C-n>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<C-p>'] = cmp.mapping(function(fallback)
end, { "i", "s" }),
["<C-p>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
end, { "i", "s" }),
}),
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
vim_item.kind = kind_icons[vim_item.kind]
vim_item.kind = kind_icons[vim_item.kind] or vim_item.kind
if entry.source.name == "nvim_lsp" then
-- name of lsp client
vim_item.menu = '[' .. entry.source.source.client.name .. ']'
vim_item.menu = "[" .. entry.source.source.client.name .. "]"
else
vim_item.menu = menu_entries[entry.source.name] or entry.source.name
end
Expand Down
5 changes: 3 additions & 2 deletions config/native/after/plugin/fidget.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
require("fidget").setup {
require("fidget").setup({
text = {
spinner = "dots",
},
window = {
relative = "editor",
},
}
})

10 changes: 6 additions & 4 deletions config/native/after/plugin/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require("konrad.lsp.borders")

require("konrad.lsp").initialize()

local lsp = require("konrad.lsp.event_handlers")
Expand All @@ -16,8 +18,8 @@ local on_detach = function(client, bufnr)
lsp.detach(client, bufnr)
end

vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('personal-lsp-attach', { clear = true }),
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("personal-lsp-attach", { clear = true }),
callback = function(args)
local client_id = args.data.client_id
local client = vim.lsp.get_client_by_id(client_id)
Expand All @@ -26,8 +28,8 @@ vim.api.nvim_create_autocmd('LspAttach', {
end,
})

vim.api.nvim_create_autocmd('LspDetach', {
group = vim.api.nvim_create_augroup('personal-lsp-detach', { clear = true }),
vim.api.nvim_create_autocmd("LspDetach", {
group = vim.api.nvim_create_augroup("personal-lsp-detach", { clear = true }),
callback = function(args)
local client_id = args.data.client_id
local client = vim.lsp.get_client_by_id(client_id)
Expand Down
41 changes: 20 additions & 21 deletions config/native/lua/konrad/icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@

return {
kind = {
Text = "",
Method = "m",
Function = "󰊕",
Class = "",
Color = "",
Constant = "",
Constructor = "",
Copilot = "",
Enum = "",
EnumMember = "",
Event = "",
Field = "",
Variable = "",
Class = "",
File = "",
Folder = "",
Function = "󰊕",
Interface = "",
Keyword = "",
Method = "m",
Module = "",
Operator = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Snippet = "",
Struct = "",
Event = "",
Operator = "",
Text = "",
TypeParameter = "",
Copilot = "",
Unit = "",
Value = "",
Variable = "",
},
documents = {
File = "",
Expand Down Expand Up @@ -101,7 +101,7 @@ return {
Animations = {
-- keep those odd
Fill = { " ", "_ ", "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" },
ThinFill = { '_', '', '', '', '', '', '', '', '' },
ThinFill = { "_", "", "", "", "", "", "", "", "" },
},
},
lines = {
Expand Down Expand Up @@ -146,6 +146,5 @@ return {
StepOver = "",
RunLast = "",
Close = "󰅙 ",
}

},
}
3 changes: 1 addition & 2 deletions config/native/lua/konrad/lsp/augroups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ local _augroups = {}
---@return integer
M.get_augroup = function(client)
if not _augroups[client.id] then
local group_name = string.format('personal-lsp-%s-%d', client.name, client.id)
local group_name = string.format("personal-lsp-%s-%d", client.name, client.id)
local group = vim.api.nvim_create_augroup(group_name, { clear = true })
_augroups[client.id] = group
return group
end
return _augroups[client.id]
end


---@param augroup integer
---@param bufnr integer
local del_autocmds_for_buf = function(augroup, bufnr)
Expand Down
19 changes: 19 additions & 0 deletions config/native/lua/konrad/lsp/borders.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local border = {
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
{ "", "FloatBorder" },
}

-- override globally
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
---@diagnostic disable-next-line: duplicate-set-field
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {}
opts.border = opts.border or border
return orig_util_open_floating_preview(contents, syntax, opts, ...)
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ M.attach = function(data)
vim.api.nvim_create_autocmd({ "InsertLeave" }, {
callback = function()
if inlayhints_is_enabled then
vim.lsp.inlay_hint(bufnr, false)
pcall(vim.lsp.inlay_hint, bufnr, false)
end
end,
})
Expand Down

0 comments on commit 08e5024

Please sign in to comment.