Skip to content

Commit

Permalink
route: add support to set the browser to open the routes
Browse files Browse the repository at this point in the history
  • Loading branch information
adalessa committed Mar 22, 2024
1 parent 0636952 commit 37a8795
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lua/laravel/config/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

---@class LaravelOptions
---@field lsp_server string
---@field browser string|nil
---@field register_user_commands boolean
---@field features LaravelFeatures
---@field ui LaravelOptionsUI
Expand All @@ -30,6 +31,7 @@ return {
position = "right",
},
},
browser = nil,
ui = require "laravel.config.ui",
commands_options = require "laravel.config.command_options",
environments = require "laravel.config.environments",
Expand Down
25 changes: 15 additions & 10 deletions lua/laravel/telescope/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ local ui_run = require "laravel.telescope.ui_run"
local go = require "laravel.routes.go"
local run = require "laravel.run"
local lsp = require "laravel._lsp"
local config = require "laravel.app.config"
local app_config = require "laravel.app.config"
local config = require "laravel.config"

local M = {}

Expand Down Expand Up @@ -39,7 +40,7 @@ end
function M.open_browser(prompt_bufnr)
actions.close(prompt_bufnr)
local entry = action_state.get_selected_entry()
local app_url = config.get "app.url"
local app_url = app_config.get "app.url"
if not app_url then
return
end
Expand All @@ -52,15 +53,19 @@ function M.open_browser(prompt_bufnr)
end

local url = string.format("%s/%s", app_url, uri)
local command = nil
local command = config.options.browser

if vim.fn.executable "xdg-open" == 1 then
command = "xdg-open"
elseif vim.fn.executable "open" == 1 then
command = "open"
end
if not command then
return
if command == nil then
if vim.fn.executable "xdg-open" == 1 then
command = "xdg-open"
elseif vim.fn.executable "open" == 1 then
command = "open"
else
vim.notify(
"There is no command to open the url add the option browser into your configuration",
vim.log.levels.WARN
)
end
end

vim.schedule(function()
Expand Down

0 comments on commit 37a8795

Please sign in to comment.