Update snippets
This commit is contained in:
2
init.lua
2
init.lua
@@ -19,7 +19,7 @@ require('helpers').edit_cf('v', '/init.lua')
|
|||||||
TODO: Neovim configurations I want to add:
|
TODO: Neovim configurations I want to add:
|
||||||
- [x] Clearer line numbers (weirdly not as simple as it sounds)
|
- [x] Clearer line numbers (weirdly not as simple as it sounds)
|
||||||
- [ ] Debugging keymap that works like PHPStorm
|
- [ ] Debugging keymap that works like PHPStorm
|
||||||
- [ ] Improve snippet expansion (an get rid of that stupid #endsection snippet)
|
- [ ] Improve snippet expansion (and get rid of that stupid #endsection snippet)
|
||||||
- [ ] Better organising of buffers when opening side panels (like AI chat and test summary)
|
- [ ] Better organising of buffers when opening side panels (like AI chat and test summary)
|
||||||
- [ ] Close test panel when opening debugger and vice versa using edgy
|
- [ ] Close test panel when opening debugger and vice versa using edgy
|
||||||
- [ ] Close terminal from inside terminal buffer
|
- [ ] Close terminal from inside terminal buffer
|
||||||
|
|||||||
@@ -26,6 +26,14 @@ vim.api.nvim_create_autocmd('InsertLeave', {
|
|||||||
command = 'silent! wa', -- Save all files when leaving insert mode
|
command = 'silent! wa', -- Save all files when leaving insert mode
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd('SwapExists', {
|
||||||
|
desc = 'Always choose to delete the swap file, files are saved automatically',
|
||||||
|
group = vim.api.nvim_create_augroup('NoSwaps', { clear = true }),
|
||||||
|
callback = function(args)
|
||||||
|
vim.cmd("let v:swapchoice = 'd'")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
-- vim.api.nvim_create_autocmd('TextChanged', {
|
-- vim.api.nvim_create_autocmd('TextChanged', {
|
||||||
-- group = autosave_group,
|
-- group = autosave_group,
|
||||||
-- pattern = '*',
|
-- pattern = '*',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-- [[ Basic Keymaps ]]
|
-- Basic Keymaps
|
||||||
-- See `:help vim.keymap.set()`
|
-- See `:help vim.keymap.set()`
|
||||||
|
|
||||||
-- Swap : and ; around
|
-- Swap : and ; around
|
||||||
@@ -12,6 +12,10 @@ vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
|
|||||||
-- Diagnostic keymaps
|
-- Diagnostic keymaps
|
||||||
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
|
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })
|
||||||
|
|
||||||
|
vim.keymap.set({ 'n', 'v' }, 'c', '"zc', { desc = 'Change without copying to clipboard' })
|
||||||
|
vim.keymap.set({ 'n', 'v' }, 'x', '"zx', { desc = 'Cut without copying to clipboard' })
|
||||||
|
vim.keymap.set('v', 'p', '"zdP', { desc = 'Paste over selection without yanking replaced text' })
|
||||||
|
|
||||||
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
|
-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
|
||||||
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
|
-- for people to discover. Otherwise, you normally need to press <C-\><C-n>, which
|
||||||
-- is not what someone will guess without a bit more experience.
|
-- is not what someone will guess without a bit more experience.
|
||||||
@@ -235,6 +239,22 @@ vim.keymap.set('n', '<Leader>tc', function()
|
|||||||
require('neotest').output_panel.close()
|
require('neotest').output_panel.close()
|
||||||
end, { desc = 'Close test panels' })
|
end, { desc = 'Close test panels' })
|
||||||
|
|
||||||
|
-- vim.keymap.set('i', '<Tab>', function()
|
||||||
|
-- local copilot = require 'copilot.suggestion'
|
||||||
|
-- local ls = require 'luasnip'
|
||||||
|
-- if copilot.is_visible() then
|
||||||
|
-- vim.api.nvim_echo({{'Accepting copilot suggestion'}}, false, {})
|
||||||
|
-- copilot.accept()
|
||||||
|
-- copilot.dismiss()
|
||||||
|
-- elseif ls.jumpable(1) then
|
||||||
|
-- vim.api.nvim_echo({{'Jumping in snippet'}}, false, {})
|
||||||
|
-- ls.jump()
|
||||||
|
-- else
|
||||||
|
-- vim.api.nvim_echo({{'Inserting tab'}}, false, {})
|
||||||
|
-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Tab>', true, true, true), 'n', true)
|
||||||
|
-- end
|
||||||
|
-- end, { desc = 'Luasnip accept copilot or jump forward' })
|
||||||
|
|
||||||
-- Leaving this commented out, I will try the format command instead
|
-- Leaving this commented out, I will try the format command instead
|
||||||
-- "A command to properly indent json code
|
-- "A command to properly indent json code
|
||||||
-- command! FormatJSON %!python -m json.tool
|
-- command! FormatJSON %!python -m json.tool
|
||||||
@@ -243,8 +263,11 @@ end, { desc = 'Close test panels' })
|
|||||||
-- directory if the file does not exist
|
-- directory if the file does not exist
|
||||||
vim.keymap.set('n', '<Leader>es', function()
|
vim.keymap.set('n', '<Leader>es', function()
|
||||||
local ft = vim.bo.filetype
|
local ft = vim.bo.filetype
|
||||||
|
if ft == 'vue' then
|
||||||
|
ft = 'javascript'
|
||||||
|
end
|
||||||
local snippets_dir = vim.fn.stdpath 'config' .. '/lua/snippets'
|
local snippets_dir = vim.fn.stdpath 'config' .. '/lua/snippets'
|
||||||
local snippets_file = snippets_dir .. '/' .. ft .. '.json'
|
local snippets_file = snippets_dir .. '/' .. ft .. '.lua'
|
||||||
vim.cmd('tabedit ' .. snippets_file)
|
vim.cmd('tabedit ' .. snippets_file)
|
||||||
end, { desc = 'Edit snippets file' })
|
end, { desc = 'Edit snippets file' })
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ return {
|
|||||||
event = 'VimEnter',
|
event = 'VimEnter',
|
||||||
version = '1.*',
|
version = '1.*',
|
||||||
dependencies = {
|
dependencies = {
|
||||||
-- Compatibility for Avante with Blink (it typically only works with cmp)
|
|
||||||
-- 'Kaiser-Yang/blink-cmp-avante',
|
|
||||||
-- Snippet Engine
|
|
||||||
'L3MON4D3/LuaSnip',
|
'L3MON4D3/LuaSnip',
|
||||||
'folke/lazydev.nvim',
|
'folke/lazydev.nvim',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,21 @@
|
|||||||
return {
|
return {
|
||||||
'github/copilot.vim',
|
'zbirenbaum/copilot.lua',
|
||||||
|
event = 'InsertEnter',
|
||||||
|
config = function()
|
||||||
|
require('copilot').setup {
|
||||||
|
suggestion = {
|
||||||
|
enabled = true,
|
||||||
|
auto_trigger = true,
|
||||||
|
keymap = {
|
||||||
|
accept = '<Tab>',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filetypes = {
|
||||||
|
yaml = true,
|
||||||
|
markdown = true,
|
||||||
|
gitcommit = true,
|
||||||
|
gitrebase = true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ return {
|
|||||||
event = { 'BufReadPre', 'BufNewFile' },
|
event = { 'BufReadPre', 'BufNewFile' },
|
||||||
config = function()
|
config = function()
|
||||||
local lint = require 'lint'
|
local lint = require 'lint'
|
||||||
lint.linters_by_ft = {
|
-- lint.linters_by_ft = {
|
||||||
markdown = { 'markdownlint' },
|
-- markdown = { 'markdownlint' },
|
||||||
}
|
-- }
|
||||||
|
lint.linters_by_ft['markdown'] = nil
|
||||||
lint.linters_by_ft['javascript'] = nil
|
lint.linters_by_ft['javascript'] = nil
|
||||||
lint.linters_by_ft['vue'] = nil
|
lint.linters_by_ft['vue'] = nil
|
||||||
lint.linters_by_ft['html'] = nil
|
lint.linters_by_ft['html'] = nil
|
||||||
|
|||||||
@@ -11,21 +11,12 @@ return {
|
|||||||
return 'make install_jsregexp'
|
return 'make install_jsregexp'
|
||||||
end)(),
|
end)(),
|
||||||
config = function()
|
config = function()
|
||||||
|
local ls = require 'luasnip'
|
||||||
|
ls.filetype_extend('vue', { 'javascript' })
|
||||||
local snippets_dir = vim.fn.stdpath 'config' .. '/lua/snippets'
|
local snippets_dir = vim.fn.stdpath 'config' .. '/lua/snippets'
|
||||||
require('luasnip.loaders.from_vscode').lazy_load {
|
require('luasnip.loaders.from_lua').load {
|
||||||
paths = { snippets_dir },
|
paths = { snippets_dir },
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
dependencies = {
|
|
||||||
-- `friendly-snippets` contains a variety of premade snippets.
|
|
||||||
-- See the README about individual language/framework/plugin snippets:
|
|
||||||
-- https://github.com/rafamadriz/friendly-snippets
|
|
||||||
{
|
|
||||||
'rafamadriz/friendly-snippets',
|
|
||||||
config = function()
|
|
||||||
require('luasnip.loaders.from_vscode').lazy_load()
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
opts = {},
|
opts = {},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
{}
|
|
||||||
1
lua/snippets/all.lua
Normal file
1
lua/snippets/all.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
return {}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Log function": {
|
|
||||||
"prefix": "du",
|
|
||||||
"body": [
|
|
||||||
"console.log($0);"
|
|
||||||
],
|
|
||||||
"description": "Log variable"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
45
lua/snippets/javascript.lua
Normal file
45
lua/snippets/javascript.lua
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
local ls = require 'luasnip'
|
||||||
|
local s = ls.snippet
|
||||||
|
local t = ls.text_node
|
||||||
|
local i = ls.insert_node
|
||||||
|
local f = ls.function_node
|
||||||
|
|
||||||
|
return {
|
||||||
|
s('du', { t 'console.log(', i(0), t ');' }),
|
||||||
|
|
||||||
|
s('vue', {
|
||||||
|
t { '<template>', '' },
|
||||||
|
t { '', '</template>', '', '', '<script setup>', '' },
|
||||||
|
i(0),
|
||||||
|
t { '', '</script>', '', '', '<style scoped>', '', '.o-share-page {', '}', '', '</style>' },
|
||||||
|
}),
|
||||||
|
|
||||||
|
s('fun', {
|
||||||
|
t 'function ',
|
||||||
|
i(1),
|
||||||
|
t '(',
|
||||||
|
i(2),
|
||||||
|
t ') {',
|
||||||
|
t { '', ' ' },
|
||||||
|
i(0),
|
||||||
|
t { '', '}' },
|
||||||
|
}),
|
||||||
|
|
||||||
|
s('afun', {
|
||||||
|
t 'async function ',
|
||||||
|
i(1),
|
||||||
|
t '(',
|
||||||
|
i(2),
|
||||||
|
t ') {',
|
||||||
|
t { '', ' ' },
|
||||||
|
i(0),
|
||||||
|
t { '', '}' },
|
||||||
|
}),
|
||||||
|
|
||||||
|
s('()', {
|
||||||
|
t '() => {',
|
||||||
|
t { '', ' ' },
|
||||||
|
i(0),
|
||||||
|
t { '', '}' },
|
||||||
|
}),
|
||||||
|
}
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "example-snippets",
|
|
||||||
"contributes": {
|
|
||||||
"snippets": [
|
|
||||||
{
|
|
||||||
"language": [
|
|
||||||
"all"
|
|
||||||
],
|
|
||||||
"path": "./snippets/all.json"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"language": [
|
|
||||||
"php"
|
|
||||||
],
|
|
||||||
"path": "./php.json"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"language": [
|
|
||||||
"javascript",
|
|
||||||
"vue"
|
|
||||||
],
|
|
||||||
"path": "./javascript-vue.json"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
{
|
|
||||||
"Dump function": {
|
|
||||||
"prefix": "du",
|
|
||||||
"body": [
|
|
||||||
"dump($0);"
|
|
||||||
],
|
|
||||||
"description": "Dump variable"
|
|
||||||
},
|
|
||||||
"Type dump function": {
|
|
||||||
"prefix": "dt",
|
|
||||||
"body": [
|
|
||||||
"\\PhpStan\\dumpType($0);"
|
|
||||||
],
|
|
||||||
"description": "Dump PHPStan type"
|
|
||||||
},
|
|
||||||
"Test case": {
|
|
||||||
"prefix": "test",
|
|
||||||
"body": [
|
|
||||||
"test($1, function () {",
|
|
||||||
" $0",
|
|
||||||
"});"
|
|
||||||
],
|
|
||||||
"description": "Test case"
|
|
||||||
},
|
|
||||||
"Create doc block": {
|
|
||||||
"prefix": "/**",
|
|
||||||
"body": [
|
|
||||||
"/**",
|
|
||||||
" * $0",
|
|
||||||
" */"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"DocBlock property": {
|
|
||||||
"prefix": "@p",
|
|
||||||
"body": "@property $1 $$0",
|
|
||||||
"description": "DocBlock property"
|
|
||||||
},
|
|
||||||
"DocBlock boolean property": {
|
|
||||||
"prefix": "@pb",
|
|
||||||
"body": "@property bool $$0",
|
|
||||||
"description": "DocBlock boolean property"
|
|
||||||
},
|
|
||||||
"DocBlock string property": {
|
|
||||||
"prefix": "@ps",
|
|
||||||
"body": "@property string $$0",
|
|
||||||
"description": "DocBlock string property"
|
|
||||||
},
|
|
||||||
"DocBlock int property": {
|
|
||||||
"prefix": "@pi",
|
|
||||||
"body": "@property int $$0",
|
|
||||||
"description": "DocBlock int property"
|
|
||||||
},
|
|
||||||
"DocBlock Collection property": {
|
|
||||||
"prefix": "@pc",
|
|
||||||
"body": "@property \\Illuminate\\Support\\Collection<int, $1> $$0",
|
|
||||||
"description": "DocBlock int property"
|
|
||||||
},
|
|
||||||
"DocBlock date property": {
|
|
||||||
"prefix": "@pd",
|
|
||||||
"body": "@property \\Illuminate\\Support\\Carbon $$0",
|
|
||||||
"description": "DocBlock date property"
|
|
||||||
},
|
|
||||||
"DocBlock model properties": {
|
|
||||||
"prefix": "@pp",
|
|
||||||
"body": [
|
|
||||||
"/**",
|
|
||||||
" * @property int $$id",
|
|
||||||
" * $1",
|
|
||||||
" * @property \\Illuminate\\Support\\Carbon $$created_at",
|
|
||||||
" * @property \\Illuminate\\Support\\Carbon $$updated_at",
|
|
||||||
" *",
|
|
||||||
" * Relationships",
|
|
||||||
" * $2",
|
|
||||||
" */"
|
|
||||||
],
|
|
||||||
"description": "DocBlock model properties"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
84
lua/snippets/php.lua
Normal file
84
lua/snippets/php.lua
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
local ls = require("luasnip")
|
||||||
|
local s = ls.snippet
|
||||||
|
local t = ls.text_node
|
||||||
|
local i = ls.insert_node
|
||||||
|
local f = ls.function_node
|
||||||
|
|
||||||
|
local function psr_namespace(args, snip)
|
||||||
|
local path = snip.env.TM_FILENAME_FULL or ""
|
||||||
|
local root = "/src/"
|
||||||
|
local ns = path:match(root .. "(.*)/[^/]+%.php$")
|
||||||
|
if ns then
|
||||||
|
return ns:gsub("/", "\\")
|
||||||
|
else
|
||||||
|
return "App"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function class_name(args, snip)
|
||||||
|
local filename = snip.env.TM_FILENAME or ""
|
||||||
|
return filename:match("([^%.]+)") or "ClassName"
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
s("du", { t("dump("), i(1), t(");") }),
|
||||||
|
s("dt", { t("\\PhpStan\\dumpType("), i(1), t(");") }),
|
||||||
|
s("ql", {
|
||||||
|
t("\\Illuminate\\Support\\Facades\\DB::listen(function (\\Illuminate\\Database\\Events\\QueryExecuted $e) {"),
|
||||||
|
t({"", " dump($e->sql, $e->bindings);"}),
|
||||||
|
t({"", "});"})
|
||||||
|
}),
|
||||||
|
s("test", {
|
||||||
|
t("test("), i(1), t(", function () {"),
|
||||||
|
t({"", " "}), i(2),
|
||||||
|
t({"", ");"})
|
||||||
|
}),
|
||||||
|
s("/**", {
|
||||||
|
t("/**"),
|
||||||
|
t({"", " * "}), i(1),
|
||||||
|
t({"", " */"})
|
||||||
|
}),
|
||||||
|
s("@p", { t("@property "), i(1), t(" $"), i(2) }),
|
||||||
|
s("@pb", { t("@property bool $"), i(1) }),
|
||||||
|
s("@ps", { t("@property string $"), i(1) }),
|
||||||
|
s("@pi", { t("@property int $"), i(1) }),
|
||||||
|
s("@pc", { t("@property \\Illuminate\\Support\\Collection<int, "), i(1), t("> $"), i(2) }),
|
||||||
|
s("@pd", { t("@property \\Illuminate\\Support\\Carbon $"), i(1) }),
|
||||||
|
s("@pp", {
|
||||||
|
t("/**"),
|
||||||
|
t({"", " * @property int $id"}),
|
||||||
|
t({"", " * "}), i(1),
|
||||||
|
t({"", " * @property \\Illuminate\\Support\\Carbon $created_at"}),
|
||||||
|
t({"", " * @property \\Illuminate\\Support\\Carbon $updated_at"}),
|
||||||
|
t({"", " *", " * Relationships"}),
|
||||||
|
t({"", " * "}), i(2),
|
||||||
|
t({"", " */"})
|
||||||
|
}),
|
||||||
|
s("php", {
|
||||||
|
t("<?php"),
|
||||||
|
t({"", ""}),
|
||||||
|
t("namespace "),
|
||||||
|
f(psr_namespace, {}),
|
||||||
|
t(";"),
|
||||||
|
t({"", "", "/**", " * Class "}),
|
||||||
|
f(class_name, {}),
|
||||||
|
t({"", " */", "class "}),
|
||||||
|
f(class_name, {}),
|
||||||
|
i(1),
|
||||||
|
t({"", "{", " public function __construct()", " {", " "}),
|
||||||
|
i(2, "// TODO: Implement constructor"),
|
||||||
|
t({"", " }", "}"})
|
||||||
|
}),
|
||||||
|
s("pub", {
|
||||||
|
t("public function "), i(1), t("("), i(2), t(")"),
|
||||||
|
t({"", "{"}),
|
||||||
|
t({"", " "}), i(3),
|
||||||
|
t({"", "}"})
|
||||||
|
}),
|
||||||
|
s("pro", {
|
||||||
|
t("protected function "), i(1), t("("), i(2), t(")"),
|
||||||
|
t({"", "{"}),
|
||||||
|
t({"", " "}), i(3),
|
||||||
|
t({"", "}"})
|
||||||
|
}),
|
||||||
|
}
|
||||||
@@ -4,3 +4,5 @@ local line_number_color = '#5d6487'
|
|||||||
vim.cmd('highlight LineNr guifg=' .. line_number_color)
|
vim.cmd('highlight LineNr guifg=' .. line_number_color)
|
||||||
vim.cmd('highlight LineNrAbove guifg=' .. line_number_color)
|
vim.cmd('highlight LineNrAbove guifg=' .. line_number_color)
|
||||||
vim.cmd('highlight LineNrBelow guifg=' .. line_number_color)
|
vim.cmd('highlight LineNrBelow guifg=' .. line_number_color)
|
||||||
|
|
||||||
|
vim.api.nvim_set_hl(0, "CopilotSuggestion", { fg = "#888888", italic = true })
|
||||||
|
|||||||
Reference in New Issue
Block a user