Skip to content

Commit

Permalink
feat: open dev tools when running in debug mode (#419)
Browse files Browse the repository at this point in the history
* feat: open dev tools when running in debug mode

* fix: update token

* fixup! fix: update token

* fix: update formatting

* chore: update checkout action to v4
  • Loading branch information
sidlatau authored Dec 23, 2024
1 parent 85492be commit 2f9db8b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 26 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/contributing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ jobs:
name: Check codestyle
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.WORKFLOW_ACCESS_TOKEN }}
- uses: actions/checkout@v4
- uses: JohnnyMorganz/stylua-action@v2
with:
token: ${{ secrets.WORKFLOW_ACCESS_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
args: --color always --check .
2 changes: 1 addition & 1 deletion .github/workflows/formatting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
stylua:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: ${{ secrets.WORKFLOW_ACCESS_TOKEN }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
os: [ ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Neovim
shell: bash
run: |
Expand All @@ -34,7 +34,7 @@ jobs:
needs: tests
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: panvimdoc
uses: kdheepak/panvimdoc@main
with:
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
package-name: flutter-tools.nvim
# extra-files: |
# lua/flutter-tools/core/config.lua
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: tag stable versions
if: ${{ steps.release.outputs.release_created }}
run: |
Expand Down
4 changes: 1 addition & 3 deletions ftplugin/dart/init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
-- See section 'DISABLING' in :h ftplugin
if vim.b.flutter_tools_did_ftplugin then
return
end
if vim.b.flutter_tools_did_ftplugin then return end
vim.b.flutter_tools_did_ftplugin = 1

require("flutter-tools.lsp").attach()
Expand Down
41 changes: 26 additions & 15 deletions lua/flutter-tools/dev_tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ local function try_get_profiler_url_chrome(data)
return data:match("(ws%:%/%/127%.0%.0%.1%:%d+/.+/ws)$")
end

function M.start_browser()
local auto_open_browser = config.dev_tools.auto_open_browser
if not auto_open_browser then return end

local url = M.get_profiler_url()
if not url then return end

---@param url string
local function open_dev_tools(url)
local open_command = utils.open_command()
if not open_command then
return ui.notify(
Expand All @@ -59,10 +54,27 @@ function M.start_browser()
Job:new({
command = open_command,
args = { url },
detached = true
detached = true,
}):start()
end

local function start_browser()
local auto_open_browser = config.dev_tools.auto_open_browser
if not auto_open_browser then return end
local url = M.get_profiler_url()
if not url then return end
open_dev_tools(url)
end

function M.open_dev_tools()
local url = M.get_profiler_url()
if url then
open_dev_tools(url)
else
ui.notify("No active devtools server found")
end
end

function M.handle_log(data)
if devtools_profiler_url or (profiler_url and devtools_url) then return end

Expand Down Expand Up @@ -92,7 +104,7 @@ function M.register_profiler_url(url)
end

function M.handle_devtools_available()
M.start_browser()
start_browser()
ui.notify("Detected devtools url, execute FlutterCopyProfilerUrl to copy it")
end

Expand Down Expand Up @@ -120,12 +132,8 @@ local function handle_start(_, data, _)
if not json.params.host or not json.params.port then return end

devtools_url = string.format("http://%s:%s", json.params.host, json.params.port)
M.start_browser()
ui.notify(
string.format("Serving DevTools at %s", devtools_url),
ui.INFO,
{ timeout = 10000 }
)
start_browser()
ui.notify(string.format("Serving DevTools at %s", devtools_url), ui.INFO, { timeout = 10000 })
end

---Handler errors whilst opening dev tools
Expand Down Expand Up @@ -224,4 +232,7 @@ function M.on_flutter_shutdown()
devtools_profiler_url = nil
end

function M.set_devtools_url(url) devtools_url = url end
function M.set_profiler_url(url) profiler_url = url end

return M
4 changes: 4 additions & 0 deletions lua/flutter-tools/runners/debugger_runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ function DebuggerRunner:run(
end

function DebuggerRunner:send(cmd, quiet)
if cmd == "open_dev_tools" then
dev_tools.open_dev_tools()
return
end
local request = command_requests[cmd]
if request ~= nil then
dap.session():request(request)
Expand Down
11 changes: 11 additions & 0 deletions lua/flutter-tools/runners/vm_service_extensions.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
local lazy = require("flutter-tools.lazy")
local dev_tools = lazy.require("flutter-tools.dev_tools") ---@module "flutter-tools.dev_tools"

---@class flutter.VmServiceExtensions
---@field set_service_extensions_state fun(extension: string, value: string)
---@field get_request_params fun(cmd: string): table | nil
---@field reset fun()
---@field set_isolate_id fun(extension: string, isolate_id: string)

local state_key_active_dev_tools_server_address = "ext.flutter.activeDevToolsServerAddress"
local state_key_connected_vm_service_uri = "ext.flutter.connectedVmServiceUri"

local service_extensions_state = {}
local service_extensions_isolateid = {}

Expand Down Expand Up @@ -41,6 +47,11 @@ end
return {
set_service_extensions_state = function(extension, value)
if extension and value then service_extensions_state[extension] = value end
if extension == state_key_active_dev_tools_server_address then
dev_tools.set_devtools_url(value)
elseif extension == state_key_connected_vm_service_uri then
dev_tools.set_profiler_url(value)
end
end,

get_request_params = function(cmd)
Expand Down

0 comments on commit 2f9db8b

Please sign in to comment.