Move Nix files into a nix directory

Move everything from `config` to the root level.
This commit is contained in:
Oliver Davies 2024-11-20 21:37:15 +00:00
parent 9f47df62b5
commit 69a397e624
124 changed files with 14 additions and 14 deletions

View file

@ -0,0 +1,13 @@
P = function(v)
print(vim.inspect(v))
return v
end
RELOAD = function(...)
return require("plenary.reload").reload_module(...)
end
R = function(name)
RELOAD(name)
return require(name)
end

View file

@ -0,0 +1,6 @@
pcall("require", impatient)
require "opdavies.globals"
require "opdavies.keymaps"
require "opdavies.options"
require "opdavies.lsp"

View file

@ -0,0 +1,115 @@
local set = vim.keymap.set
set("n", "<Leader>so", ":call opdavies#save_and_exec()<CR>")
-- Format paragraphs to an 80 character line length.
set("n", "<Leader>g", "gqap")
set("x", "<Leader>g", "gqa")
-- Make the current file executable
set("n", "<Leader>x", ":!chmod +x %<Cr>")
-- Yank from the current column to the end of the line
set("n", "Y", "yg$")
-- Keep things centred
set("n", "n", "nzzzv")
set("n", "N", "Nzzzv")
-- Disable up and down arrow keys.
set("v", "<down>", "<nop>")
set("v", "<up>", "<nop>")
-- Use the left and right arrow keys to change tabs.
set("v", "<left>", "gT")
set("v", "<right>", "gt")
-- Easily switch back to visual mode.
set("i", "jk", "<Esc>")
-- Easy insertion of a trailing ; or , from insert mode
set("i", ",,", "<Esc>A,<Esc>")
set("i", ";;", "<Esc>A;<Esc>")
set("n", "ga", "<Plug>(EasyAlign)")
set("x", "ga", "<Plug>(EasyAlign)")
-- Focus on the current buffer.
set("n", "<leader>-", ":wincmd _<cr>:wincmd |<cr>", { noremap = true, silent = true })
-- Automatically resize buffers.
set("n", "<leader>=", ":wincmd =<cr>", { noremap = true, silent = true })
-- Move line(s) up and down.
local opts = { noremap = true, silent = true }
set("i", "<M-j>", "<Esc>:m .+1<CR>==gi", opts)
set("i", "<M-k>", "<Esc>:m .-2<CR>==gi", opts)
set("n", "<M-j>", ":m .+1<CR>==", opts)
set("n", "<M-k>", ":m .-2<CR>==", opts)
set("v", "<M-j>", ":m '>+1<CR>gv=gv", opts)
set("v", "<M-k>", ":m '<-2<CR>gv=gv", opts)
-- Re-centre when navigating.
set("n", "#", "#zz", opts)
set("n", "%", "%zz", opts)
set("n", "*", "*zz", opts)
set("n", "<C-d>", "<C-d>zz", opts)
set("n", "<C-i>", "<C-i>zz", opts)
set("n", "<C-o>", "<C-o>zz", opts)
set("n", "<C-u>", "<C-u>zz", opts)
set("n", "G", "Gzz", opts)
set("n", "N", "Nzz", opts)
set("n", "gg", "ggzz", opts)
set("n", "n", "Nzz", opts)
set("n", "{", "{zz", opts)
set("n", "}", "}zz", opts)
-- Clears hlsearch after doing a search, otherwise just does normal <CR> stuff
vim.cmd [[ nnoremap <expr> <CR> {-> v:hlsearch ? ":nohl\<CR>" : "\<CR>"}() ]]
-- Quicker macro playback.
set("n", "Q", "@qj")
set("x", "Q", ":norm @q<CR>")
-- Easier navigation between splits.
set("n", "<C-h>", "<C-w><C-h>")
set("n", "<C-j>", "<C-w><C-j>")
set("n", "<C-k>", "<C-w><C-k>")
set("n", "<C-l>", "<C-w><C-l>")
set("v", "Q", "<nop>")
set("v", "J", ":m '>+1<CR>gvrgv")
set("v", "K", ":m '<-2<CR>gv=gv")
set("n", "J", "mzJ`z")
set("n", "<C-d>", "<C-d>zz")
set("n", "<C-u>", "<C-u>zz")
set("n", "n", "nzzzv")
set("n", "N", "Nzzzv")
-- Easily access project-specific notes.
set("n", "<leader>en", function()
if vim.fn.filereadable ".ignored/notes" == 1 then
vim.cmd "tabnew .ignored/notes"
else
vim.cmd "tabnew notes"
end
end)
-- Easily access project-specific todos.
set("n", "<leader>et", function()
if vim.fn.filereadable ".ignored/todo" == 1 then
vim.cmd "tabnew .ignored/todo"
else
vim.cmd "tabnew todo"
end
end)
set("n", "<leader>ec", ":edit composer.json")
-- These mappings control the size of splits (height/width).
set("n", "<M-,>", "<c-w>5<")
set("n", "<M-.>", "<c-w>5>")
set("n", "<M-t>", "<C-W>+")
set("n", "<M-s>", "<C-W>-")

View file

@ -0,0 +1,73 @@
local M = {}
local function should_remove_diagnostic(messages_to_filter, message)
for _, filter_message in ipairs(messages_to_filter) do
if message:match(filter_message) then
return true
end
end
return false
end
M.definition = function()
local params = vim.lsp.util.make_position_params()
vim.lsp.buf_request(0, "textDocument/definition", params, function(err, result, ctx, config)
local bufnr = ctx.bufnr
local ft = vim.api.nvim_buf_get_option(bufnr, "filetype")
local new_result = vim.tbl_filter(function(v)
-- Remove any definitions within the nix store via the .direnv directory.
if string.find(v.targetUri, ".direnv") then
return false
end
-- Remove definitions within vendor-bin directory for PHP files.
if ft == "php" then
if string.find(v.targetUri, "vendor%-bin") then
return false
end
end
return true
end, result)
if #new_result > 0 then
result = new_result
end
vim.lsp.handlers["textDocument/definition"](err, result, ctx, config)
vim.cmd [[normal! zz]]
end)
end
M.on_publish_diagnostics = function(_, result, ctx, config)
local client = vim.lsp.get_client_by_id(ctx.client_id)
if client.name == "cssls" then
local filtered_diagnostics = {}
local messages_to_filter = {
"Unknown at rule @apply",
"Unknown at rule @plugin",
"Unknown at rule @tailwind",
"Unknown at rule @theme",
}
-- For each diagnostic, ensure its mesages doesn't match one I want to
-- ignore before adding it to the result. If it matches, don't add it to the
-- result and it won't be shown.
for _, diagnostic in ipairs(result.diagnostics) do
if not should_remove_diagnostic(messages_to_filter, diagnostic.message) then
table.insert(filtered_diagnostics, diagnostic)
end
end
result.diagnostics = filtered_diagnostics
end
vim.lsp.diagnostic.on_publish_diagnostics(_, result, ctx, config)
end
return M

View file

@ -0,0 +1,128 @@
local cmp_nvim_lsp = require "cmp_nvim_lsp"
local handlers = require "opdavies.lsp.handlers"
local lspconfig = require "lspconfig"
require("neodev").setup {}
local capabilities = cmp_nvim_lsp.default_capabilities(vim.lsp.protocol.make_client_capabilities())
lspconfig.bashls.setup {
capabilities = capabilities,
}
lspconfig.cssls.setup {
capabilities = capabilities,
on_attach = function(_, _)
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(handlers.on_publish_diagnostics, {})
end,
}
lspconfig.gopls.setup {
capabilities = capabilities,
}
lspconfig.html.setup {
capabilities = capabilities,
}
lspconfig.intelephense.setup {
capabilities = capabilities,
}
lspconfig.lua_ls.setup {
capabilities = capabilities,
settings = {
Lua = {
completion = {
callSnippet = "Replace",
},
diagnostics = {
globals = { "vim" },
},
runtime = {
version = "LuaJIT",
},
telemetry = {
enabled = false,
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
},
},
},
}
lspconfig.marksman.setup {
capabilities = capabilities,
}
lspconfig.nixd.setup {
capabilities = capabilities,
cmd = { "nixd" },
settings = {
nixd = {
nixpkgs = {
expr = "import <nixpkgs> { }",
},
formatting = {
command = "nix fmt",
},
},
},
}
lspconfig.tailwindcss.setup {
capabilities = capabilities,
filetypes = { "html", "javascript", "twig", "typescript", "vue" },
settings = {
init_options = {
userLanguages = {
["html.twig"] = "html",
},
},
},
}
lspconfig.terraformls.setup {
capabilities = capabilities,
}
lspconfig.ts_ls.setup {
capabilities = capabilities,
}
lspconfig.vuels.setup {
capabilities = capabilities,
}
lspconfig.yamlls.setup {
capabilities = capabilities,
settings = {
yaml = {
keyOrdering = false,
},
},
}
vim.diagnostic.config {
float = { source = true },
signs = true,
underline = false,
update_in_insert = false,
virtual_text = { spacing = 2 },
}
vim.api.nvim_create_autocmd("LspAttach", {
callback = function()
local builtin = require "telescope.builtin"
vim.keymap.set("n", "gd", builtin.lsp_definitions, { buffer = 0 })
vim.keymap.set("n", "gr", builtin.lsp_references, { buffer = 0 })
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { buffer = 0 })
vim.keymap.set("n", "gT", vim.lsp.buf.type_definition, { buffer = 0 })
vim.keymap.set("n", "K", vim.lsp.buf.hover, { buffer = 0 })
vim.keymap.set("n", "<space>cr", vim.lsp.buf.rename, { buffer = 0 })
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, { buffer = 0 })
end,
})

View file

@ -0,0 +1,53 @@
vim.g.mapleader = " "
vim.g.snippets = "luasnip"
local settings = {
autoindent = true,
backup = false,
breakindent = true,
expandtab = true,
foldlevel = 1,
foldlevelstart = 99,
foldmethod = "indent",
formatoptions = "clqjp",
hidden = false,
hlsearch = false,
inccommand = "split",
laststatus = 3,
linebreak = true,
list = true,
mouse = "",
number = true,
pumblend = 10,
pumheight = 10,
relativenumber = true,
scrolloff = 5,
shiftwidth = 2,
showmode = false,
signcolumn = "yes:1",
smartindent = true,
softtabstop = 2,
spellfile = "/home/opdavies/Code/dotfiles.nix/config/neovim/spell/en.utf-8.add",
splitbelow = true,
splitright = true,
swapfile = false,
syntax = "on",
tabstop = 2,
termguicolors = true,
textwidth = 0,
undodir = os.getenv "HOME" .. "/.vim/undodir",
undofile = true,
updatetime = 1000,
wrap = false,
}
for key, value in pairs(settings) do
vim.o[key] = value
end
vim.opt.backupdir:remove "." -- keep backups out of the current directory
vim.opt.clipboard:append "unnamedplus"
vim.opt.completeopt = { "menu", "menuone", "noinsert", "noselect" }
vim.opt.listchars:append {
trail = "·",
}

View file

@ -0,0 +1,31 @@
local ls = require "luasnip"
local fmta = require("luasnip.extras.fmt").fmta
return {
run = fmta(
[=[
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
function help {
printf "%s <<task>> [args]\n\nTasks:\n" "${0}"
compgen -A function | grep -v "^_" | cat -n
printf "\nExtended help:\n Each task has comments for general usage\n"
}
# Include any local tasks.
# https://stackoverflow.com/a/6659698
[[ -e "${BASH_SOURCE%/*}/run.local" ]] && source "${BASH_SOURCE%/*}/run.local"
TIMEFORMAT="Task completed in %3lR"
time "${@:-help}"
]=],
{}
),
}

View file

@ -0,0 +1,10 @@
local fmta = require("luasnip.extras.fmt").fmta
local ls = require "luasnip"
local i = ls.insert_node
local M = {
log = fmta("console.log(<>);", { i(1, "value") }),
}
return M

View file

@ -0,0 +1,27 @@
local ls = require "luasnip"
local fmt = require("luasnip.extras.fmt").fmt
local rep = require("luasnip.extras").rep
local f, i = ls.function_node, ls.insert_node
return {
pcall = fmt(
[[
local status_ok, {} = pcall(require, "{}")
if not status_ok then
return
end
]],
{ i(1), rep(1) }
),
req = fmt([[local {} = require "{}"]], {
f(function(import_name)
local parts = vim.split(import_name[1][1], ".", true)
return parts[#parts] or ""
end, { 1 }),
i(1),
}),
}

View file

@ -0,0 +1,20 @@
local fmt = require("luasnip.extras.fmt").fmt
local ls = require "luasnip"
local i = ls.insert_node
local M = {
frontmatter = fmt(
[[
---
title: {}
---
{}
]],
{ i(1), i(0) }
),
link = fmt([[[{}]({}){} ]], { i(1), i(2), i(0) }),
}
return M

View file

@ -0,0 +1,23 @@
local fmta = require("luasnip.extras.fmt").fmta
local ls = require "luasnip"
local c = ls.choice_node
local i = ls.insert_node
local t = ls.text_node
local M = {
vimplugin = fmta(
[[
{
plugin = <>.<>;
type = "lua";
config = ''
<>
'';
}<>
]],
{ c(1, { t "vimPlugins", t "customVim" }), i(2), i(3), i(0) }
),
}
return M

View file

@ -0,0 +1,115 @@
local fmta = require("luasnip.extras.fmt").fmta
local ls = require "luasnip"
local c = ls.choice_node
local f = ls.function_node
local i = ls.insert_node
local t = ls.text_node
local M = {
__construct = fmta(
[[
public function __construct(<>) {
<>
}
]],
{ i(1), i(0) }
),
__invoke = fmta(
[[
public function __invoke(<>) {
<>
}
]],
{ i(1), i(0) }
),
drupalclass = fmta(
[[
<<?php
declare(strict_types=1);
namespace <>;
final class <> {
<>
}]],
{
f(function()
local filepath = vim.fn.expand "%:h"
local filepath_parts = vim.fn.split(filepath, "/")
if not vim.tbl_contains(filepath_parts, "src") then
return ""
end
local namespace_parts = { "Drupal" }
local is_test_file = vim.tbl_contains(filepath_parts, "tests")
if is_test_file then
table.insert(namespace_parts, "Tests")
end
-- Find and add the module name.
for k, v in ipairs(filepath_parts) do
if v == "src" then
if is_test_file then
table.insert(namespace_parts, filepath_parts[k - 2])
else
table.insert(namespace_parts, filepath_parts[k - 1])
end
end
end
-- Add the rest of the namespace.
local namespace = vim.split(filepath, "src/")
local final_part = (namespace[2] or ""):gsub("/", "\\")
table.insert(namespace_parts, final_part)
return table.concat(namespace_parts, "\\")
end),
f(function()
return vim.fn.expand "%:t:r"
end),
i(0),
}
),
func = fmta("function <>(<>)<> {\n <>\n}<>", { i(1), i(2), i(3), i(4), i(0) }),
met = fmta(
[[
<> function <>(<>)<> {
<>
}<>
]],
{ c(1, { t "public", t "protected", t "private" }), i(2), i(3), i(4), i(5), i(0) }
),
pest = fmta("<>('<>', function() {\n <>\n});", { c(1, { t "it", t "test" }), i(2), i(0) }),
test = fmta(
[[
public function test<>(): void {
<>
}<>
]],
{ i(1), i(2), i(0) }
),
testa = fmta(
[[
/** @test */
public function <>(): void {
<>
}<>
]],
{ i(1), i(2), i(0) }
),
}
return M

View file

@ -0,0 +1,49 @@
local fmta = require("luasnip.extras.fmt").fmta
local ls = require "luasnip"
local i = ls.insert_node
local f = ls.function_node
local fill_line = function(char)
return function()
local row = vim.api.nvim_win_get_cursor(0)[1]
local lines = vim.api.nvim_buf_get_lines(0, row - 2, row, false)
return string.rep(char, #lines[1])
end
end
local M = {
class = { ".. class:: ", i(1) },
footer = { ".. footer:: ", i(1) },
link = { ".. _", i(1), ":" },
raw = { ".. raw:: ", i(1) },
-- TODO: add an optional new line and ":width" property.
image = { ".. image:: ", i(1) },
head = f(fill_line "=", {}),
sub = f(fill_line "-", {}),
subsub = f(fill_line "^", {}),
-- Add a page break with an optional page template.
pb = fmta(
[[
.. raw:: pdf
PageBreak<>
]],
{ i(0) }
),
-- Add a new speaker note.
ta = fmta(
[[
.. raw:: pdf
TextAnnotation "<>"
]],
{ i(0) }
),
}
return M

View file

@ -0,0 +1,10 @@
local fmta = require("luasnip.extras.fmt").fmta
local ls = require "luasnip"
local i = ls.insert_node
local M = {
bp = fmta("@include breakpoint(<>) {\n <>\n}", { i(1), i(0) }),
}
return M

View file

@ -0,0 +1,31 @@
local fmta = require("luasnip.extras.fmt").fmta
local ls = require "luasnip"
local i = ls.insert_node
local M = {
stories = fmta(
[[
{% stories <name> with { title: '<title>' } %}
<finish>
{% endstories %}
]],
{ name = i(1), title = i(2), finish = i(0) }
),
story = fmta(
[[
{% story <name> with {
name: '<label>',
args: {},
} %}
<finish>
{% endstory %}
]],
{ name = i(1, "default"), label = i(2), finish = i(0) }
),
}
return M

View file

@ -0,0 +1,39 @@
local fmta = require("luasnip.extras.fmt").fmta
local ls = require "luasnip"
local rep = require("luasnip.extras").rep
local c = ls.choice_node
local i = ls.insert_node
local t = ls.text_node
local M = {
drupal_info = fmta(
[[
name: <module_name>
description: <description>
core_version_requirement: ^10 || ^11
type: <type>
package: <package>
]],
{ module_name = i(1), description = i(2), type = c(3, { t "module", t "theme" }), package = i(0) }
),
drupal_route = fmta(
[[
<module>.<route>:
path: /<path>
defaults:
_controller: Drupal\<module_same>\Controller\<class>
# _form:
# _title:
# _title_callback:
methods: [GET]
requirements:
_permission: access content
# _access: TRUE<finish>
]],
{ module = i(1), route = i(2), path = i(3), module_same = rep(1), class = i(4), finish = i(0) }
),
}
return M