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

Set the Delve port dynamically for remote debug #78

Merged
merged 7 commits into from
Aug 6, 2024

Conversation

cyb3rd4d
Copy link
Contributor

Currently the Delve port can be defined either randomly or hard-coded by hand.

Hard-coded port allows to know which port to use in remote debug configurations, but in practice with many Go projects, it would be great to set the Delve port in debug configurations.

Luckily nvim-dap allows to set an on_config callback for an adapter, which can be used to resolve the adapter settings when a debug session starts. This PR implements this nvim-dap feature, which can be used with the support of VSCode launch.json files to greatly enhance the developer experience.

This potentially resolves #73

@cyb3rd4d
Copy link
Contributor Author

Hello @leoluz, is it possible to get some feedback please?

@leoluz
Copy link
Owner

leoluz commented May 27, 2024

Hard-coded port allows to know which port to use in remote debug configurations, but in practice with many Go projects, it would be great to set the Delve port in debug configurations.

I am not sure that I understand exactly what is your use-case. You don't have to setup a different Delve port per Go project. They can all use the same port configuration unless you are trying to debug different Go projects at the same time. Can you please clarify what your use-case is?

@cyb3rd4d
Copy link
Contributor Author

cyb3rd4d commented May 27, 2024

I work on projects deployed on a local k8s cluster (k3d), most of them have a binary for an HTTP server and others for workers (kafka consumers for example).

Also I always have multiple apps running in my cluster, each app is deployed in a development docker image with its own delve port. Each port must be unique to be able to setup port forwarding on my local host.

It's really more convenient for me to keep the delve clients configuration inside my projects instead of having to set a long list of config entries in my neovim's config.

@hippeus
Copy link

hippeus commented May 27, 2024

Same here, I am looking forward to such addition. I have a setup that uses telepresence that randomly allocates a different free port so I can use it to debug my application inside a cluster with a very distributed system.

@cyb3rd4d
Copy link
Contributor Author

cyb3rd4d commented Jul 3, 2024

Do you have any other questions @leoluz?

@leoluz
Copy link
Owner

leoluz commented Jul 4, 2024

@cyb3rd4d Tks for the explanation. I'll try to review your PR soon.

Copy link
Owner

@leoluz leoluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!
Can you please also update the doc/nvim-dap-go.txt file?

lua/dap-go.lua Outdated Show resolved Hide resolved
@cyb3rd4d
Copy link
Contributor Author

Thank you for your contribution! Can you please also update the doc/nvim-dap-go.txt file?

Oh yes sorry I forgot this one!

Currently the Delve port can be defined either randomly or hard-coded by
hand.

Hard-coded port allows to know which port to use in debug
configurations, but in practice with many Go projects, it would be
great to set the Delve port in debug configurations.

Luckily `nvim-dap` allows to set an `on_config` callback for an adapter,
which can be used to resolve the adapter settings when a debug session
starts. This PR implements this `nvim-dap` feature, which can be used
with the support of VSCode `launch.json` files to greatly enhance the developer
experience.

This potentially resolves leoluz#73
@cyb3rd4d
Copy link
Contributor Author

I rebased and added config validation + completed the doc.

Copy link
Owner

@leoluz leoluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update. I added one more comment.

lua/dap-go.lua Outdated Show resolved Hide resolved
The extension now decides if it should enable the remote debugging if a
port is defined in the user configuration.
Copy link
Owner

@leoluz leoluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thank you for contributing!

@leoluz leoluz merged commit 5511788 into leoluz:main Aug 6, 2024
2 checks passed
@cyb3rd4d cyb3rd4d deleted the vscode-launch-support branch August 6, 2024 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

multiple configurations with different ports
3 participants