From f930fee1bebf3bf69bfab7d8ab2b995aa7839124 Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Sun, 2 Feb 2025 16:13:36 +0100 Subject: [PATCH 1/4] add todo --- todo.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 todo.md diff --git a/todo.md b/todo.md new file mode 100644 index 0000000..7785aa5 --- /dev/null +++ b/todo.md @@ -0,0 +1,16 @@ +# Goal + +Quiero poder usar gf o dejado para quien quiera para ir a la defincion del archivo +de view, Route::view, config & env + +- [ ] Get node at cursor, and validate that is in string on one of the supported functions. +- [ ] get the needed information of the file +- [ ] for config and env should get to the line were defined. +- [ ] for config will be a bit hard, need to get the file name from the first part + +need to use function get_node_at_cursor(winnr) +From that I need to get the parser, and get the termins + +get_node_text({node}, {source}, {opts}) +source can be the buf number +nvim_get_current_buf should be able to use it, or 0 From 6d3fc049d1d66408d1a2b7859c412c178c5ec325 Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Sun, 2 Feb 2025 20:53:49 +0100 Subject: [PATCH 2/4] add notes --- todo.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/todo.md b/todo.md index 7785aa5..d42dfde 100644 --- a/todo.md +++ b/todo.md @@ -8,9 +8,50 @@ de view, Route::view, config & env - [ ] for config and env should get to the line were defined. - [ ] for config will be a bit hard, need to get the file name from the first part +## After MVP +- [ ] Env completion + +## Low priority +- [ ] blink source to not depend on compat + need to use function get_node_at_cursor(winnr) From that I need to get the parser, and get the termins get_node_text({node}, {source}, {opts}) source can be the buf number nvim_get_current_buf should be able to use it, or 0 + +Asi puedo sobreescribir el gf para usarlo +```lua +vim.keymap.set("n", "gf", function() + if require("obsidian").util.cursor_on_markdown_link() then + return "ObsidianFollowLink" + else + return "gf" + end +end, { noremap = false, expr = true }) +``` + +```lua +require('laravel').app('util').gf_passthrough() +``` + +This can engloble it + +also can have + +```lua +require('laravel').app('util').hover_passthrough() +``` +could try to do the hover if not fallback to the lspaction ? or ask for it. +mimic the same hover + +could use `vim.lsp.util.make_floating_popup_options()` +that can be pass to +``` + Creates a table with sensible default options for a floating window. The + table can be passed to |nvim_open_win()|. +``` +`nvim_open_win({buffer}, {enter}, {config})` + +create a buffer with just that and the common options. From cdf22bbcd2ba985912cd10b56b453abee632ff14 Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Tue, 4 Feb 2025 14:19:10 +0100 Subject: [PATCH 3/4] more ideas --- todo.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/todo.md b/todo.md index d42dfde..02f7dfc 100644 --- a/todo.md +++ b/todo.md @@ -55,3 +55,21 @@ that can be pass to `nvim_open_win({buffer}, {enter}, {config})` create a buffer with just that and the common options. + + + +Thinker how to set parser for filetype. +I want to set filetype thinker and map to PHP_ONLY parser + + +Model completion, cache model show info +Need to get current position, get the MODEL on parent. +also check the alias to see if it's a model + + + +TODO I was able to reproduce the issue of laravel is not active, need to check when locale or lative, that composer and php are executalble. +I have the check but the environment looks like is still set, so need to debug more there + +Improve the healthcheck and how to map using some check for cmp, blink and the provider. +The provider for picker can be auto to look for the plugins configured From 5df4345febffeda421ef7bb2a178136f8fd1ded3 Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Fri, 7 Feb 2025 15:57:40 +0100 Subject: [PATCH 4/4] support gf comand to go to view, route, config, and env --- lua/laravel/providers/laravel_provider.lua | 1 + .../providers/user_command_provider.lua | 31 ++++---- lua/laravel/services/commands/gf.lua | 65 ++++++++++++++++ lua/laravel/services/gf.lua | 44 +++++++++++ todo.md | 75 ------------------- 5 files changed, 126 insertions(+), 90 deletions(-) create mode 100644 lua/laravel/services/commands/gf.lua create mode 100644 lua/laravel/services/gf.lua delete mode 100644 todo.md diff --git a/lua/laravel/providers/laravel_provider.lua b/lua/laravel/providers/laravel_provider.lua index dd0e40d..16536f4 100644 --- a/lua/laravel/providers/laravel_provider.lua +++ b/lua/laravel/providers/laravel_provider.lua @@ -18,6 +18,7 @@ function laravel_provider:register(app) app:bindIf("ui_handler", "laravel.services.ui_handler") app:bindIf("view_finder", "laravel.services.view_finder") app:bindIf("views", "laravel.services.views") + app:bindIf("gf", "laravel.services.gf") app:singeltonIf("cache", "laravel.services.cache") app:singeltonIf("env", "laravel.services.environment") diff --git a/lua/laravel/providers/user_command_provider.lua b/lua/laravel/providers/user_command_provider.lua index ec449e2..35e8669 100644 --- a/lua/laravel/providers/user_command_provider.lua +++ b/lua/laravel/providers/user_command_provider.lua @@ -11,6 +11,7 @@ function user_command_provider:register(app) app:bindIf("resources_command", "laravel.services.commands.resources", { tags = { "command" } }) app:bindIf("view_finder_command", "laravel.services.commands.view_finder", { tags = { "command" } }) app:bindIf("flush_cache_command", "laravel.services.commands.flush_cache", { tags = { "command" } }) + app:bindIf("gf_command", "laravel.services.commands.gf", { tags = { "command" } }) app:singeltonIf("serve_command", "laravel.services.commands.serve", { tags = { "command" } }) app:singeltonIf("assets_command", "laravel.services.commands.assets", { tags = { "command" } }) @@ -31,12 +32,12 @@ function user_command_provider:boot(app) if not args.fargs[1] then vim.ui.select( vim - .iter(app("user_commands")) - :map(function(command) - return command:commands() - end) - :flatten() - :totable(), + .iter(app("user_commands")) + :map(function(command) + return command:commands() + end) + :flatten() + :totable(), { prompt = "Laravel command: " }, function(selected) if not selected then @@ -67,15 +68,15 @@ function user_command_provider:boot(app) local fCmdLine = vim.split(cmdLine, " ") if #fCmdLine <= 2 then return vim - .iter(app("user_commands")) - :map(function(command) - return command:commands() - end) - :flatten() - :filter(function(subcommand) - return vim.startswith(subcommand, argLead) - end) - :totable() + .iter(app("user_commands")) + :map(function(command) + return command:commands() + end) + :flatten() + :filter(function(subcommand) + return vim.startswith(subcommand, argLead) + end) + :totable() elseif #fCmdLine == 3 then local command = vim.iter(app("user_commands")):find(function(cmd) return vim.iter(cmd:commands()):any(function(name) diff --git a/lua/laravel/services/commands/gf.lua b/lua/laravel/services/commands/gf.lua new file mode 100644 index 0000000..2f02c4e --- /dev/null +++ b/lua/laravel/services/commands/gf.lua @@ -0,0 +1,65 @@ +local split = require("laravel.utils").split +local actions = require("laravel.pickers.common.actions") + +local gf_command = {} + +function gf_command:new(views, gf, cache_routes_repository) + local instance = { + views = views, + gf = gf, + routes = cache_routes_repository, + } + setmetatable(instance, self) + self.__index = self + return instance +end + +function gf_command:commands() + return { "gf" } +end + +function gf_command:handle() + local node, resource_type = self.gf:cursor_on_resource() + if not node then + return + end + + if resource_type == "view" then + self.views:open(vim.treesitter.get_node_text(node, 0, {})) + return + end + + if resource_type == "config" then + -- app.name + local config_name = vim.treesitter.get_node_text(node, 0, {}) + local s = split(config_name, ".") + + -- TODO: can be improve by parsing the file with treesitter. + -- find the return and with the the array elements with the next items + vim.cmd("e config/" .. s[1] .. ".php") + return + end + + if resource_type == "env" then + local env_name = vim.treesitter.get_node_text(node, 0, {}) + vim.cmd("e .env") + vim.fn.search(env_name) + vim.cmd("normal zt") + return + end + + if resource_type == "route" then + local route_name = vim.treesitter.get_node_text(node, 0, {}) + self.routes:all():thenCall(function(routes) + for _, route in ipairs(routes) do + if route.name == route_name then + actions.open_route(route) + return + end + end + vim.notify("Route not found", vim.log.levels.WARN) + end) + end +end + +return gf_command diff --git a/lua/laravel/services/gf.lua b/lua/laravel/services/gf.lua new file mode 100644 index 0000000..ef97aec --- /dev/null +++ b/lua/laravel/services/gf.lua @@ -0,0 +1,44 @@ +local gf = {} + +function gf:new() + local instance = { + } + setmetatable(instance, self) + self.__index = self + return instance +end + +function gf:cursor_on_resource() + local node = vim.treesitter.get_node() + if not node then + return false + end + + if node:type() ~= "string_content" then + return false + end + + local parent = node:parent() + while parent ~= nil and parent:type() ~= "function_call_expression" do + parent = parent:parent() + end + + if not parent then + return false + end + + local func_node = parent:child(0) + if not func_node then + return false + end + + local func_name = vim.treesitter.get_node_text(func_node, 0, {}) + + if vim.tbl_contains({'route', 'view', 'config', 'env'}, func_name) then + return node, func_name + end + + return false +end + +return gf diff --git a/todo.md b/todo.md deleted file mode 100644 index 02f7dfc..0000000 --- a/todo.md +++ /dev/null @@ -1,75 +0,0 @@ -# Goal - -Quiero poder usar gf o dejado para quien quiera para ir a la defincion del archivo -de view, Route::view, config & env - -- [ ] Get node at cursor, and validate that is in string on one of the supported functions. -- [ ] get the needed information of the file -- [ ] for config and env should get to the line were defined. -- [ ] for config will be a bit hard, need to get the file name from the first part - -## After MVP -- [ ] Env completion - -## Low priority -- [ ] blink source to not depend on compat - -need to use function get_node_at_cursor(winnr) -From that I need to get the parser, and get the termins - -get_node_text({node}, {source}, {opts}) -source can be the buf number -nvim_get_current_buf should be able to use it, or 0 - -Asi puedo sobreescribir el gf para usarlo -```lua -vim.keymap.set("n", "gf", function() - if require("obsidian").util.cursor_on_markdown_link() then - return "ObsidianFollowLink" - else - return "gf" - end -end, { noremap = false, expr = true }) -``` - -```lua -require('laravel').app('util').gf_passthrough() -``` - -This can engloble it - -also can have - -```lua -require('laravel').app('util').hover_passthrough() -``` -could try to do the hover if not fallback to the lspaction ? or ask for it. -mimic the same hover - -could use `vim.lsp.util.make_floating_popup_options()` -that can be pass to -``` - Creates a table with sensible default options for a floating window. The - table can be passed to |nvim_open_win()|. -``` -`nvim_open_win({buffer}, {enter}, {config})` - -create a buffer with just that and the common options. - - - -Thinker how to set parser for filetype. -I want to set filetype thinker and map to PHP_ONLY parser - - -Model completion, cache model show info -Need to get current position, get the MODEL on parent. -also check the alias to see if it's a model - - - -TODO I was able to reproduce the issue of laravel is not active, need to check when locale or lative, that composer and php are executalble. -I have the check but the environment looks like is still set, so need to debug more there - -Improve the healthcheck and how to map using some check for cmp, blink and the provider. -The provider for picker can be auto to look for the plugins configured