aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha
diff options
context:
space:
mode:
Diffstat (limited to 'lua/alpha')
-rw-r--r--lua/alpha/scratchs/draft.lua14
-rw-r--r--lua/alpha/snippets/init.lua1
-rw-r--r--lua/alpha/snippets/php.lua27
-rw-r--r--lua/alpha/telescope_laravel.lua2
4 files changed, 39 insertions, 5 deletions
diff --git a/lua/alpha/scratchs/draft.lua b/lua/alpha/scratchs/draft.lua
index 30cc365..bc0568e 100644
--- a/lua/alpha/scratchs/draft.lua
+++ b/lua/alpha/scratchs/draft.lua
@@ -1,9 +1,15 @@
+local api = vim.api
+
function GlobalFunction()
local position_params = vim.lsp.util.make_position_params()
+ P(position_params)
+
+ vim.lsp.buf_request(0, "textDocument/completion", position_params, function(err, result)
+ if vim.tbl_isempty(result or {}) then return end
+
+ local textEdit = result.items[1].additionalTextEdits;
- vim.lsp.buf_request(0, "textDocument/completion", position_params, function(err, method, result)
- if method ~= nil then
- vim.lsp.util.apply_text_document_edit(method.items, 1)
- end
+ local bufnr = vim.api.nvim_get_current_buf()
+ vim.lsp.util.apply_text_edits(textEdit, bufnr)
end)
end
diff --git a/lua/alpha/snippets/init.lua b/lua/alpha/snippets/init.lua
index 8318486..316e66b 100644
--- a/lua/alpha/snippets/init.lua
+++ b/lua/alpha/snippets/init.lua
@@ -1 +1,2 @@
require('alpha.snippets.config')
+require('alpha.snippets.php')
diff --git a/lua/alpha/snippets/php.lua b/lua/alpha/snippets/php.lua
index f42ed45..0831aa3 100644
--- a/lua/alpha/snippets/php.lua
+++ b/lua/alpha/snippets/php.lua
@@ -5,6 +5,8 @@ local t = ls.text_node
local i = ls.insert_node
local c = ls.choice_node
local d = ls.dynamic_node
+local f = ls.function_node
+local l = require("luasnip.extras").lambda
-- visibility allows to reuse it pasing the first option to show for the
-- snippet
@@ -24,6 +26,19 @@ visibility = function (_, _, _, initial_text)
return sn(nil, { c(1, options) })
end
+local releation
+releation = function (_, snip,_, type)
+ local relationType = type
+ local relationName = snip.captures[1]
+
+ return sn(nil, {
+ -- I would like t o auto import the relation but for now just ommit it
+ -- t({"public function ".. relationName:gsub("^%u", string.lower) .. "(): " .. relationType:gsub("^%l", string.upper) , "{", ""}),
+ t({"public function ".. relationName:gsub("^%u", string.lower) .. "()" , "{", ""}),
+ t({"\treturn $this->".. relationType .. "(".. relationName .. "::class);", "}"}),
+ })
+end
+
local promo_property
promo_property = function()
return sn(
@@ -120,3 +135,15 @@ ls.snippets = {
}),
}
}
+
+local relationTypes = {"hasOne", "belongsTo", "hasMany", "belongsToMany"}
+for _, type in pairs(relationTypes) do
+ table.insert(ls.snippets.php,
+ s(
+ { trig= type .. "(.*)", regTrig=true },
+ {
+ d(1, releation, {}, type),
+ }
+ )
+ )
+end
diff --git a/lua/alpha/telescope_laravel.lua b/lua/alpha/telescope_laravel.lua
index 562a151..fc730b6 100644
--- a/lua/alpha/telescope_laravel.lua
+++ b/lua/alpha/telescope_laravel.lua
@@ -28,7 +28,7 @@ local mt_string_entry = {
end,
}
-function getArtisanCommand(args)
+local function getArtisanCommand(args)
local artCmdStr = vim.g.laravel_artisan
if artCmdStr == nil then
artCmdStr = "php artisan"