style(core): run stylua

This commit is contained in:
Ade Attwood 2023-11-24 08:01:34 +00:00
parent 0fa7e58c98
commit da223e930d
8 changed files with 193 additions and 188 deletions

View file

@ -1,6 +1,5 @@
require("modules.clojure")
require("modules.lua-lsp")
require("modules.nvim")
require("modules.nvm")
require("modules.tmux")
require "modules.clojure"
require "modules.lua-lsp"
require "modules.nvim"
require "modules.nvm"
require "modules.tmux"

View file

@ -14,7 +14,7 @@
-- locations the duplication exists.
--
local codeclimate_namespace = vim.api.nvim_create_namespace("codeclimate")
local codeclimate_namespace = vim.api.nvim_create_namespace "codeclimate"
local codeclimate_auto_command_group = vim.api.nvim_create_augroup("codeclimate", { clear = true })
-- Get the relative path of a `buffer` to the vim current working directory
@ -31,7 +31,7 @@ local function read_line(file_path, line_number)
return ""
end
local index = 0;
local index = 0
while index < line_number do
file:read()
index = index + 1
@ -46,8 +46,10 @@ end
-- Populates the vim diagnostics with the codeclimate issues from '/tmp/cc.json'
local function codeclimate_add_diagnostics()
local file = io.open("/tmp/cc.json", "rb")
if not file then return nil end
local issues = vim.json.decode(file:read("*a"))
if not file then
return nil
end
local issues = vim.json.decode(file:read "*a")
local buffer = vim.api.nvim_win_get_buf(0)
local buffer_name = get_relative_path(buffer)
@ -55,9 +57,8 @@ local function codeclimate_add_diagnostics()
for index = 1, #issues do
if issues[index]["location"] ~= nil and issues[index]["location"]["path"] == buffer_name then
local start_line = 0;
local end_line = 0;
local start_line = 0
local end_line = 0
if issues[index]["location"]["lines"] ~= nil then
start_line = issues[index]["location"]["lines"]["begin"] - 1
@ -86,8 +87,8 @@ local function codeclimate_add_diagnostics()
message = issues[index]["description"],
severity = vim.diagnostic.severity.ERROR,
user_data = {
other_locations = issues[index]["other_locations"]
}
other_locations = issues[index]["other_locations"],
},
})
::continue::
@ -99,7 +100,7 @@ end
local function other_to_quick_fix()
local point = vim.api.nvim_win_get_cursor(0)
local diagnostics = vim.diagnostic.get(0, {lnum = point[1] - 1})
local diagnostics = vim.diagnostic.get(0, { lnum = point[1] - 1 })
local issues = {}
-- TODO(ade): Add in a message to say this issues dose not have any other
@ -126,7 +127,7 @@ local function other_to_quick_fix()
})
end
vim.fn.setqflist({}, "r", {title = "Code Climate Other Locations", items = issues})
vim.fn.setqflist({}, "r", { title = "Code Climate Other Locations", items = issues })
vim.cmd "copen"
end

View file

@ -1,2 +1 @@
require('Comment').setup()
require("Comment").setup()

View file

@ -1,102 +1,105 @@
local cmp = require'cmp'
local luasnip = require'luasnip'
local cmp = require "cmp"
local luasnip = require "luasnip"
require("copilot").setup({
require("copilot").setup {
suggestion = { enabled = false },
panel = { enabled = false },
})
}
require("copilot_cmp").setup()
local icons = {
Text = "",
Method = "",
Function = "",
Constructor = "",
Field = "",
Variable = "",
Class = "",
Interface = "",
Module = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
Text = "",
Method = "",
Function = "",
Constructor = "",
Field = "",
Variable = "",
Class = "",
Interface = "",
Module = "",
Property = "",
Unit = "",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "",
Event = "",
Operator = "",
}
cmp.setup({
mapping = cmp.mapping.preset.insert({
['<C-j>'] = cmp.get_config().mapping['<Down>'],
['<C-k>'] = cmp.get_config().mapping['<Up>'],
['<C-l>'] = function() luasnip.jump(1) end,
['<C-h>'] = function() luasnip.jump(-1) end,
cmp.setup {
mapping = cmp.mapping.preset.insert {
["<C-j>"] = cmp.get_config().mapping["<Down>"],
["<C-k>"] = cmp.get_config().mapping["<Up>"],
["<C-l>"] = function()
luasnip.jump(1)
end,
["<C-h>"] = function()
luasnip.jump(-1)
end,
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm { select = true },
["<Tab>"] = cmp.mapping(function(fallback)
if luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = {
{ name = "luasnip" },
{ name = "copilot" },
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' },
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
fields = { 'menu', 'abbr', 'kind' },
format = function(entry, vim_item)
-- Give the completion menu a consistent size to stop it jumping arround
local width = 40
if #vim_item.abbr > width then
vim_item.abbr = string.sub(vim_item.abbr, 1, width)
else
vim_item.abbr = vim_item.abbr .. string.rep(" ", width - #vim_item.abbr)
end
["<S-Tab>"] = cmp.mapping(function(fallback)
if luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = {
{ name = "luasnip" },
{ name = "copilot" },
{ name = "nvim_lsp" },
{ name = "buffer" },
{ name = "path" },
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
formatting = {
fields = { "menu", "abbr", "kind" },
format = function(entry, vim_item)
-- Give the completion menu a consistent size to stop it jumping arround
local width = 40
if #vim_item.abbr > width then
vim_item.abbr = string.sub(vim_item.abbr, 1, width)
else
vim_item.abbr = vim_item.abbr .. string.rep(" ", width - #vim_item.abbr)
end
vim_item.menu = icons[vim_item.kind] or " "
vim_item.kind = "(" .. entry.source.name .. ")"
return vim_item
end,
},
experimental = {
ghost_text = true,
},
})
vim_item.menu = icons[vim_item.kind] or " "
vim_item.kind = "(" .. entry.source.name .. ")"
return vim_item
end,
},
experimental = {
ghost_text = true,
},
}
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),

View file

@ -1,4 +1,4 @@
local lint = require('lint')
local lint = require "lint"
local severities = {
error = vim.diagnostic.severity.ERROR,
@ -6,35 +6,35 @@ local severities = {
}
lint.linters.psalm = {
cmd = 'psalm',
stdin = false,
args = {
'--output-format=json',
'--show-info=true'
},
-- ignore_exitcode = true,
parser = function(output, _)
if vim.trim(output) == '' then
return {}
end
local errors = vim.json.decode(output)
local diagnostics = {}
for _, err in ipairs(errors or {}) do
table.insert(diagnostics, {
lnum = err.line_from - 1,
end_lnum = err.line_to - 1,
col = err.column_from - 1,
end_col = err.column_to - 1,
message = err.message,
source = 'psalm',
severity = assert(severities[err.severity], 'missing mapping for severity ' .. err.severity),
})
end
return diagnostics
cmd = "psalm",
stdin = false,
args = {
"--output-format=json",
"--show-info=true",
},
-- ignore_exitcode = true,
parser = function(output, _)
if vim.trim(output) == "" then
return {}
end
local errors = vim.json.decode(output)
local diagnostics = {}
for _, err in ipairs(errors or {}) do
table.insert(diagnostics, {
lnum = err.line_from - 1,
end_lnum = err.line_to - 1,
col = err.column_from - 1,
end_col = err.column_to - 1,
message = err.message,
source = "psalm",
severity = assert(severities[err.severity], "missing mapping for severity " .. err.severity),
})
end
return diagnostics
end,
}
local get_language_id = function()
@ -42,57 +42,57 @@ local get_language_id = function()
return "--language-id=" .. file_type
end
lint.linters.cspell = {
cmd = 'cspell',
lint.linters.cspell = {
cmd = "cspell",
stdin = true,
ignore_exitcode = true,
args = {
'lint',
'--no-color',
'--no-progress',
'--no-summary',
"--config=" .. os.getenv("HOME") .. "/.cspell.json",
"lint",
"--no-color",
"--no-progress",
"--no-summary",
"--config=" .. os.getenv "HOME" .. "/.cspell.json",
get_language_id,
'--',
'stdin'
"--",
"stdin",
},
stream = 'stdout',
parser = require('lint.parser').from_errorformat('%f:%l:%c - %m', {
source = 'cspell',
severity = vim.diagnostic.severity.INFO
})
stream = "stdout",
parser = require("lint.parser").from_errorformat("%f:%l:%c - %m", {
source = "cspell",
severity = vim.diagnostic.severity.INFO,
}),
}
lint.linters_by_ft = {};
lint.linters_by_ft = {}
if vim.fn.executable('phpcs') == 1 then
if vim.fn.executable "phpcs" == 1 then
lint.linters_by_ft.php = { "phpcs" }
end
if vim.fn.executable('eslint_d') == 1 then
if vim.fn.executable "eslint_d" == 1 then
lint.linters_by_ft.typescript = { "eslint_d" }
lint.linters_by_ft.javascript = { "eslint_d" }
lint.linters_by_ft.typescriptreact = { "eslint_d" }
lint.linters_by_ft.javascriptreact = { "eslint_d" }
end
if vim.fn.executable('luacheck') == 1 then
if vim.fn.executable "luacheck" == 1 then
lint.linters_by_ft.lua = { "luacheck" }
end
if vim.fn.executable('stylelint') == 1 then
if vim.fn.executable "stylelint" == 1 then
lint.linters_by_ft.scss = { "stylelint" }
end
if vim.fn.executable('rubocop') == 1 then
if vim.fn.executable "rubocop" == 1 then
lint.linters_by_ft.ruby = { "rubocop" }
end
if vim.fn.executable('erb_lint') == 1 then
if vim.fn.executable "erb_lint" == 1 then
lint.linters_by_ft.eruby = { "erb_lint" }
end
local file_types_map = { [ "" ] = false, qf = false, ivy = false }
local file_types_map = { [""] = false, qf = false, ivy = false }
-- Lint code with nvim-lint on save. This will lint all filetypes with cspell
-- and then any other filetypes will be linted per the config.
@ -112,10 +112,9 @@ vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost" }, {
-- Only try and run spell checking on buffers that have a filetype. This is
-- mainly to disable spell checking in vim lsp popup buffers.
if should_lint then
table.insert(linters, 'cspell')
table.insert(linters, "cspell")
end
lint.try_lint(linters)
end,
})

View file

@ -1,7 +1,7 @@
local lspconfig = require "lspconfig"
local workspace_library = vim.api.nvim_get_runtime_file("lua", true)
table.insert(workspace_library, os.getenv("HOME") .. "/Code/src/github.com/AdeAttwood/Configz/definitions/configz.lua")
table.insert(workspace_library, os.getenv "HOME" .. "/Code/src/github.com/AdeAttwood/Configz/definitions/configz.lua")
local servers = {
-- Language servers for the day to day web development, could probably think
@ -56,7 +56,7 @@ local on_attach = function(_, bufnr)
vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
buffer = bufnr,
callback = function ()
callback = function()
-- Highlight document symbles for every file type other erb files because
-- solargraph only supports textDocument/documentHighlight in rb files.
local file_type = vim.api.nvim_buf_get_option(0, "filetype")
@ -70,13 +70,12 @@ local on_attach = function(_, bufnr)
vim.api.nvim_create_autocmd("CursorMoved", {
buffer = bufnr,
callback = function ()
callback = function()
vim.lsp.buf.clear_references()
end,
group = "lsp_document_highlight",
desc = "Clear All the References",
})
end
local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities())
@ -99,23 +98,23 @@ vim.fn.sign_define(
{ text = "", texthl = "DiagnosticSignError", numhl = "DiagnosticSignError" }
)
local border = 'rounded'
local border = "rounded"
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border})
vim.lsp.handlers["textDocument/show_line_diagnostics"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border})
vim.lsp.handlers["textDocument/diagnostic"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border})
vim.lsp.handlers["textDocument/diagnostics"] = vim.lsp.with(vim.lsp.handlers.hover, {border = border})
vim.diagnostic.config({
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers["textDocument/show_line_diagnostics"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers["textDocument/diagnostic"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.lsp.handlers["textDocument/diagnostics"] = vim.lsp.with(vim.lsp.handlers.hover, { border = border })
vim.diagnostic.config {
float = {
focusable=false,
border = border
}
})
focusable = false,
border = border,
},
}
vim.cmd([[set updatetime=1000]])
vim.cmd [[set updatetime=1000]]
vim.api.nvim_create_augroup("diagnostic_float", { clear = true })
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
callback = function ()
callback = function()
vim.diagnostic.open_float()
end,
group = "diagnostic_float",

View file

@ -23,4 +23,3 @@ vim.api.nvim_create_user_command("PrrGoToLine", function()
vim.cmd("e " .. target_file)
vim.fn.cursor(target_line - 1, column)
end, { bang = true, desc = "Open the current file at the poin in a prr buffer" })

View file

@ -1,13 +1,19 @@
require'nvim-treesitter.configs'.setup {
playground = { enable = true },
indent = { enable = false },
rainbow = { enable = true },
highlight = {
-- `false` will disable the whole extension
enable = true,
additional_vim_regex_highlighting = true,
},
ensure_installed = {
"typescript", "javascript", "tsx", "php", "html", "go", "clojure"
},
require("nvim-treesitter.configs").setup {
playground = { enable = true },
indent = { enable = false },
rainbow = { enable = true },
highlight = {
-- `false` will disable the whole extension
enable = true,
additional_vim_regex_highlighting = true,
},
ensure_installed = {
"typescript",
"javascript",
"tsx",
"php",
"html",
"go",
"clojure",
},
}