Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add vscode/intellij debugger configs #1918

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**/build
**/.gradle
**/.idea
!**/.idea/runConfigurations/
/.vscode
!.vscode/tasks.json
**/*.sw*
Expand Down
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.hermit/
.vscode/
.vscode/*
!/.vscode/settings.json
.idea/
!/.vscode/launch.json
.idea/*
!.idea/runConfigurations/
*.iml
target/
build/
Expand All @@ -20,6 +22,7 @@ testdata/**/go.work
testdata/**/go.work.sum
**/testdata/**/_ftl
**/examples/**/_ftl
**/examples/**/types.ftl.go
buildengine/.gitignore
go.work*
junit*.xml
Expand Down
10 changes: 10 additions & 0 deletions .idea/runConfigurations/Debug_FTL.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug FTL",
"type": "go",
"request": "attach",
"mode": "remote",
"apiVersion": 2,
"host": "127.0.0.1",
"port": 2345
}
]
}
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,35 @@ just publish-extension

This will publish the extension to the FTL marketplace. This command will require you to have a Personal Access Token (PAT) with the `Marketplace` scope. You can create a PAT [here](https://dev.azure.com/ftl-org/_usersSettings/tokens).

## Debugging with Delve

### Building with Full Debug Information

To build a binary with full debug information for Delve, use the following command:

```sh
FTL_DEBUG=true just build ftl
```

### Debugging a Running Process

For an in-line replacement of `ftl dev <args>`, use the command:

```sh
just debug <args>
```

This command compiles a binary with debug information, runs `ftl dev <args>` using this binary, and provides an endpoint to attach a remote debugger at __127.0.0.1:2345__.
You do not need to run `FTL_DEBUG=true just build ftl` separately when using this command.
### Attaching a Debugger

By running `just debug <args>` and then attaching a remote debugger, you can debug the FTL infrastructure while running your project.

#### IntelliJ
Run `Debug FTL` from the `Run/Debug Configurations` dropdown while in the FTL project.
#### VSCode
Run `Debug FTL` from the `Run and Debug` dropdown while in the FTL project.

## Useful links

- [VSCode extension samples](https://github.com/microsoft/vscode-extension-samples)
Expand Down
24 changes: 23 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ build-generate:
build +tools: build-protos build-zips build-frontend
#!/bin/bash
shopt -s extglob
for tool in $@; do mk "{{RELEASE}}/$tool" : !(build|integration) -- go build -o "{{RELEASE}}/$tool" -tags release -ldflags "-X github.com/TBD54566975/ftl.Version={{VERSION}} -X github.com/TBD54566975/ftl.Timestamp={{TIMESTAMP}}" "./cmd/$tool"; done

if [ "${FTL_DEBUG:-}" = "true" ]; then
for tool in $@; do go build -o "{{RELEASE}}/$tool" -tags release -gcflags=all="-N -l" -ldflags "-X github.com/TBD54566975/ftl.Version={{VERSION}} -X github.com/TBD54566975/ftl.Timestamp={{TIMESTAMP}}" "./cmd/$tool"; done
else
for tool in $@; do mk "{{RELEASE}}/$tool" : !(build|integration) -- go build -o "{{RELEASE}}/$tool" -tags release -ldflags "-X github.com/TBD54566975/ftl.Version={{VERSION}} -X github.com/TBD54566975/ftl.Timestamp={{TIMESTAMP}}" "./cmd/$tool"; done
fi

# Build all backend binaries
build-backend:
Expand Down Expand Up @@ -148,3 +153,20 @@ docs:
# Generate LSP hover help text
lsp-generate:
@mk lsp/hoveritems.go : lsp docs/content -- "scripts/ftl-gen-lsp"

# Run `ftl dev` providing a Delve endpoint for attaching a debugger.
debug *args:
#!/bin/bash
set -euo pipefail

cleanup() {
if [ -n "${dlv_pid:-}" ] && kill -0 "$dlv_pid" 2>/dev/null; then
kill "$dlv_pid"
fi
}
trap cleanup EXIT

FTL_DEBUG=true just build ftl
dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec "{{RELEASE}}/ftl" -- dev {{args}} &
dlv_pid=$!
wait "$dlv_pid"
1 change: 1 addition & 0 deletions bin/.dlv-1.22.1.pkg
1 change: 1 addition & 0 deletions bin/delve-1.22.1
Loading