aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorAriel D'Alessandro <dalessandro.ariel@gmail.com>2022-09-09 08:47:02 +0200
committerAriel D'Alessandro <dalessandro.ariel@gmail.com>2022-09-09 08:47:02 +0200
commitb5af6000bdacef641182bd094dc23908dde14110 (patch)
treeafdfc5fcb4fe871c0bdb25839f8ed3c02675ed94 /lua
parent7d5683672cdf1d73914b637b7266e5602f3ac34b (diff)
downloadnvim-conf-b5af6000bdacef641182bd094dc23908dde14110.tar.gz
nvim-conf-b5af6000bdacef641182bd094dc23908dde14110.zip
Add composer check locally to avoid needing external library for that
Diffstat (limited to 'lua')
-rw-r--r--lua/alpha/composer.lua21
-rw-r--r--lua/alpha/dap.lua5
-rw-r--r--lua/alpha/snips/ft/php.lua4
3 files changed, 25 insertions, 5 deletions
diff --git a/lua/alpha/composer.lua b/lua/alpha/composer.lua
new file mode 100644
index 0000000..e67d523
--- /dev/null
+++ b/lua/alpha/composer.lua
@@ -0,0 +1,21 @@
+local M = {}
+
+M.query = function (path)
+ if vim.fn.findfile("composer.json") == "" then
+ P("did not found the file")
+ return nil
+ end
+
+ local target = vim.fn.json_decode(vim.fn.readfile(vim.fn.getcwd() .. "/composer.json"))
+
+ for _, part in ipairs(path) do
+ target = target[part]
+ if target == nil then
+ return nil
+ end
+ end
+
+ return target
+end
+
+return M
diff --git a/lua/alpha/dap.lua b/lua/alpha/dap.lua
index e1bcf87..74004e7 100644
--- a/lua/alpha/dap.lua
+++ b/lua/alpha/dap.lua
@@ -1,4 +1,5 @@
local dap, dapui, dap_go = require("dap"), require("dapui"), require("dap-go")
+local composer = require("alpha.composer")
require("nvim-dap-virtual-text").setup({})
-- dap.set_log_level('TRACE')
@@ -53,9 +54,7 @@ dap.configurations.php = {
name = "Listen for Xdebug",
port = 9003,
pathMappings = function()
- -- TODO change this to not depends on the composer
- local sail = vim.call("composer#query", "require-dev.laravel/sail")
- if sail == "" then
+ if composer.query({"require-dev", "laravel/sali"}) ~= nil then
return { ["/app"] = vim.fn.getcwd() }
end
return { ["/var/www/html"] = vim.fn.getcwd() }
diff --git a/lua/alpha/snips/ft/php.lua b/lua/alpha/snips/ft/php.lua
index 41272a7..dbd872e 100644
--- a/lua/alpha/snips/ft/php.lua
+++ b/lua/alpha/snips/ft/php.lua
@@ -1,4 +1,5 @@
local ls = require("luasnip")
+local composer = require("alpha.composer")
local snippet_from_nodes = ls.sn
local c = ls.choice_node
@@ -33,8 +34,7 @@ end
local namespace = function()
local dir = vim.fn.expand("%:h")
- -- replace this since I don't want to use this composer
- local autoloads = vim.call("composer#query", "autoload.psr-4")
+ local autoloads = composer.query({"autoload", "psr-4"})
if autoloads == nil then
return (dir:gsub("^%l", string.upper))
end