first version, bunch of plugins, keymaps and configuration

This commit is contained in:
Noah Håkansson 2024-01-29 10:08:59 +01:00
parent 2510c29d62
commit ec6733a0ea
30 changed files with 1425 additions and 96 deletions

158
lua/utils/icons.lua Normal file
View file

@ -0,0 +1,158 @@
return {
kind = {
Array = '',
Boolean = '',
Class = '',
Color = '',
Constant = '',
Constructor = '',
Enum = '',
EnumMember = '',
Event = '',
Field = '',
File = '',
Folder = '󰉋 ',
Function = '',
Interface = '',
Key = '',
Keyword = '',
Method = '',
-- Module = " ",
Module = '',
Namespace = '',
Null = '󰟢 ',
Number = '',
Object = '',
Operator = '',
Package = '',
Property = '',
Reference = '',
Snippet = '',
String = '',
Struct = '',
Text = '',
TypeParameter = '',
Unit = '',
Value = '',
Variable = '',
},
git = {
LineAdded = '',
LineModified = '',
LineRemoved = '',
FileDeleted = '',
FileIgnored = '',
FileRenamed = '',
FileStaged = 'S',
FileUnmerged = '',
FileUnstaged = '',
FileUntracked = 'U',
Diff = '',
Repo = '',
Octoface = '',
Copilot = '',
Branch = '',
},
ui = {
ArrowCircleDown = '',
ArrowCircleLeft = '',
ArrowCircleRight = '',
ArrowCircleUp = '',
BoldArrowDown = '',
BoldArrowLeft = '',
BoldArrowRight = '',
BoldArrowUp = '',
BoldClose = '',
BoldDividerLeft = '',
BoldDividerRight = '',
BoldLineLeft = '',
BoldLineMiddle = '',
BoldLineDashedMiddle = '',
BookMark = '',
BoxChecked = '',
Bug = '',
Stacks = '',
Scopes = '',
Watches = '󰂥',
DebugConsole = '',
Calendar = '',
Check = '',
ChevronRight = '',
ChevronShortDown = '',
ChevronShortLeft = '',
ChevronShortRight = '',
ChevronShortUp = '',
Circle = '',
Close = '󰅖',
CloudDownload = '',
Code = '',
Comment = '',
Dashboard = '',
DividerLeft = '',
DividerRight = '',
DoubleChevronRight = '»',
Ellipsis = '',
EmptyFolder = '',
EmptyFolderOpen = '',
File = '',
FileSymlink = '',
Files = '',
FindFile = '󰈞',
FindText = '󰊄',
Fire = '',
Folder = '󰉋 ',
FolderOpen = '',
FolderSymlink = '',
Forward = '',
Gear = '',
History = '',
Lightbulb = '',
LineLeft = '',
LineMiddle = '',
List = '',
Lock = '',
NewFile = ' ',
Note = '',
Package = '',
Pencil = '󰏫 ',
Plus = '',
Project = '',
Search = '',
SignIn = '',
SignOut = '',
Tab = '󰌒 ',
Table = '',
Target = '󰀘 ',
Telescope = '',
Text = '',
Tree = '',
Triangle = '󰐊',
TriangleShortArrowDown = '',
TriangleShortArrowLeft = '',
TriangleShortArrowRight = '',
TriangleShortArrowUp = '',
},
diagnostics = {
BoldError = '',
Error = '',
BoldWarning = '',
Warning = '',
BoldInformation = '',
Information = '',
BoldQuestion = '',
Question = '',
BoldHint = '',
Hint = '󰌶',
Debug = '',
Trace = '',
},
misc = {
Robot = '󰚩 ',
Squirrel = '',
Tag = '',
Watch = '',
Smiley = '',
Package = '',
CircuitBoard = '',
},
}

View file

@ -0,0 +1,16 @@
local colors = {
bg = '#202328',
fg = '#bbc2cf',
yellow = '#ECBE7B',
cyan = '#008080',
darkblue = '#081633',
green = '#98be65',
orange = '#FF8800',
violet = '#a9a1e1',
magenta = '#c678dd',
purple = '#c678dd',
blue = '#51afef',
red = '#ec5f67',
}
return colors

View file

@ -0,0 +1,163 @@
--
-- This file contains the components that are used in the lualine configuration
--
local icons = require('utils.icons')
local conditions = require('utils.lualine.conditions')
local colors = require('utils.lualine.colors')
return {
branch = {
'b:gitsigns_head',
icon = icons.git.Branch,
color = { gui = 'bold' },
},
filename = {
'filename',
color = {},
cond = nil,
},
diff = {
'diff',
symbols = {
added = icons.git.LineAdded .. ' ',
modified = icons.git.LineModified .. ' ',
removed = icons.git.LineRemoved .. ' ',
},
padding = { left = 2, right = 1 },
diff_color = {
added = { fg = colors.green },
modified = { fg = colors.yellow },
removed = { fg = colors.red },
},
cond = nil,
},
diagnostics = {
'diagnostics',
sources = { 'nvim_diagnostic' },
symbols = {
error = icons.diagnostics.BoldError .. ' ',
warn = icons.diagnostics.BoldWarning .. ' ',
info = icons.diagnostics.BoldInformation .. ' ',
hint = icons.diagnostics.BoldHint .. ' ',
},
-- cond = conditions.hide_in_width,
},
treesitter = {
function()
return icons.ui.Tree
end,
color = function()
local buf = vim.api.nvim_get_current_buf()
local ts = vim.treesitter.highlighter.active[buf]
return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red }
end,
cond = conditions.hide_in_width,
},
copilot = {
function()
local client = require('copilot.client')
local copilot_active = client.buf_is_attached(vim.api.nvim_get_current_buf())
-- local buf_clients = vim.lsp.get_active_clients({ bufnr = 0 })
-- local copilot_active = false
--
-- -- look for copilot client
-- for _, client in pairs(buf_clients) do
-- if client.name == 'copilot' then
-- copilot_active = true
-- end
-- end
--
if copilot_active then
return icons.git.Copilot
end
return ''
end,
color = function()
local api = require('copilot.api')
local status = api.status.data.status
if status == 'InProgress' then
return { gui = 'bold', fg = colors.yellow }
elseif status == 'Warning' then
return { gui = 'bold', fg = colors.red }
end
return { gui = 'bold', fg = colors.green }
end,
cond = conditions.hide_in_width,
},
lsp = {
function()
local buf_clients = vim.lsp.get_active_clients({ bufnr = 0 })
if #buf_clients == 0 then
return 'LSP Inactive'
end
local buf_ft = vim.bo.filetype
local buf_client_names = {}
-- add client
for _, client in pairs(buf_clients) do
if client.name ~= 'null-ls' and client.name ~= 'copilot' then
table.insert(buf_client_names, client.name)
end
end
-- add formatter
local formatters = require('utils.none-ls.formatters')
local supported_formatters = formatters.list_registered(buf_ft)
vim.list_extend(buf_client_names, supported_formatters)
-- add linter
local linters = require('utils.none-ls.linters')
local supported_linters = linters.list_registered(buf_ft)
vim.list_extend(buf_client_names, supported_linters)
local unique_client_names = vim.fn.uniq(buf_client_names)
local language_servers = '[' .. table.concat(unique_client_names, ', ') .. ']'
return language_servers
end,
color = { gui = 'bold' },
cond = conditions.hide_in_width,
},
location = { 'location' },
progress = {
'progress',
fmt = function()
return '%P/%L'
end,
color = {},
},
spaces = {
function()
local shiftwidth = vim.api.nvim_buf_get_option(0, 'shiftwidth')
return icons.ui.Tab .. ' ' .. shiftwidth
end,
padding = 1,
},
encoding = {
'o:encoding',
fmt = string.upper,
color = {},
cond = conditions.hide_in_width,
},
filetype = { 'filetype', cond = nil, padding = { left = 1, right = 1 } },
scrollbar = {
function()
local current_line = vim.fn.line('.')
local total_lines = vim.fn.line('$')
local chars = { '__', '▁▁', '▂▂', '▃▃', '▄▄', '▅▅', '▆▆', '▇▇', '██' }
local line_ratio = current_line / total_lines
local index = math.ceil(line_ratio * #chars)
return chars[index]
end,
padding = { left = 0, right = 0 },
color = 'SLProgress',
cond = nil,
},
}

View file

@ -0,0 +1,17 @@
local window_width_limit = 100
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
end,
hide_in_width = function()
return vim.o.columns > window_width_limit
end,
-- check_git_workspace = function()
-- local filepath = vim.fn.expand "%:p:h"
-- local gitdir = vim.fn.finddir(".git", filepath .. ";")
-- return gitdir and #gitdir > 0 and #gitdir < #filepath
-- end,
}
return conditions

View file

@ -0,0 +1,31 @@
local M = {}
local null_ls = require('null-ls')
local services = require('utils.none-ls.services')
local method = null_ls.methods.FORMATTING
function M.list_registered(filetype)
local registered_providers = services.list_registered_providers_names(filetype)
return registered_providers[method] or {}
end
function M.list_supported(filetype)
local s = require('null-ls.sources')
local supported_formatters = s.get_supported(filetype, 'formatting')
table.sort(supported_formatters)
return supported_formatters
end
function M.setup(formatter_configs)
if vim.tbl_isempty(formatter_configs) then
return
end
local registered = services.register_sources(formatter_configs, method)
if #registered > 0 then
vim.notify('Registered the following formatters: ' .. unpack(registered), vim.log.levels.DEBUG)
end
end
return M

View file

@ -0,0 +1,41 @@
local M = {}
local null_ls = require('null-ls')
local services = require('utils.none-ls.services')
local method = null_ls.methods.DIAGNOSTICS
local alternative_methods = {
null_ls.methods.DIAGNOSTICS,
null_ls.methods.DIAGNOSTICS_ON_OPEN,
null_ls.methods.DIAGNOSTICS_ON_SAVE,
}
function M.list_registered(filetype)
local registered_providers = services.list_registered_providers_names(filetype)
local providers_for_methods = vim.tbl_flatten(vim.tbl_map(function(m)
return registered_providers[m] or {}
end, alternative_methods))
return providers_for_methods
end
function M.list_supported(filetype)
local s = require('null-ls.sources')
local supported_linters = s.get_supported(filetype, 'diagnostics')
table.sort(supported_linters)
return supported_linters
end
function M.setup(linter_configs)
if vim.tbl_isempty(linter_configs) then
return
end
local registered = services.register_sources(linter_configs, method)
if #registered > 0 then
vim.notify('Registered the following linters: ' .. unpack(registered), vim.log.levels.DEBUG)
end
end
return M

View file

@ -0,0 +1,56 @@
local M = {}
function M.list_registered_providers_names(filetype)
local s = require('null-ls.sources')
local available_sources = s.get_available(filetype)
local registered = {}
for _, source in ipairs(available_sources) do
for method in pairs(source.methods) do
registered[method] = registered[method] or {}
table.insert(registered[method], source.name)
end
end
return registered
end
function M.register_sources(configs, method)
local null_ls = require('null-ls')
local is_registered = require('null-ls.sources').is_registered
local sources, registered_names = {}, {}
for _, config in ipairs(configs) do
local cmd = config.exe or config.command
local name = config.name or cmd:gsub('-', '_')
local type = method == null_ls.methods.CODE_ACTION and 'code_actions' or null_ls.methods[method]:lower()
local source = type and null_ls.builtins[type][name]
vim.notify(string.format('Received request to register [%s] as a %s source', name, type), vim.log.levels.DEBUG)
if not source then
vim.notify('Not a valid source: ' .. name, vim.log.levels.ERROR)
elseif is_registered({ name = source.name or name, method = method }) then
vim.notify(string.format('Skipping registering [%s] more than once', name), vim.log.levels.TRACE)
else
local command = M.find_command(source._opts.command) or source._opts.command
-- treat `args` as `extra_args` for backwards compatibility. Can otherwise use `generator_opts.args`
local compat_opts = vim.deepcopy(config)
if config.args then
compat_opts.extra_args = config.args or config.extra_args
compat_opts.args = nil
end
local opts = vim.tbl_deep_extend('keep', { command = command }, compat_opts)
vim.notify('Registering source ' .. name, vim.log.levels.DEBUG)
vim.notify(vim.inspect(opts), vim.log.levels.TRACE)
table.insert(sources, source.with(opts))
vim.list_extend(registered_names, { source.name })
end
end
if #sources > 0 then
null_ls.register({ sources = sources })
end
return registered_names
end
return M