IDE Integration
Dagger uses GraphQL as its low-level language-agnostic API query language, and each Dagger SDK generates native code-bindings for all dependencies from this API. This gives you all the benefits of type-checking, code completion and other IDE features for your favorite language when developing Dagger Functions.
The dagger develop
command bootstraps a Dagger module template in the selected programming language and sets up or updates all the resources needed to develop a module. After running this command, follow the steps below to have your IDE recognize the Dagger module.
- Go
- Python
- TypeScript
To get your IDE to recognize a Dagger Go module, configure your go.work
file to include the path to your module.
When you generate a Dagger module for the first time, Dagger will create a go.mod
file just for the module. If the module exists in a sub-directory of an outer Go project (such as dagger/
, the default), this might confuse the IDE.
If there is already a go.mod
in the parent directory that you would like to use instead, delete the newly-generated go.mod
and go.sum
and Dagger will use the parent one instead. This is not advisable if your Dagger module has certain dependencies that are not relevant to your core product, since most consumers will prefer a narrower set of dependencies.
To keep the generated go.mod
file and edit your Dagger module in the same IDE session as your project code, one option is to set up a Go workspace:
# in the root of your repository
go work init
go work use ./
go work use ./path/to/mod
After restarting the IDE, you should be able to use IDE features such as go-to-definition, even when editing dagger/main.go
from the project root.
In most cases, go.work
should not be committed to the repository, so it is advisable to add it to the project's .gitignore
file:
echo go.work >> .gitignore
echo go.work.sum >> .gitignore
You can also choose to omit the local Go files generated by dagger develop
from your version control system, as they aren't required to run the module.
To get your IDE to recognize a Dagger Python module and any added Dagger module dependencies in the generated client, follow the steps below for your package manager.
- pip
- Poetry
- Hatch
Install the Python SDK in a virtual environment from the generated ./sdk
directory, as shown below:
python -m venv .venv
source .venv/bin/activate
pip install -e ./sdk
Add ./sdk
as a development dependency:
poetry add -e --group=dev ./sdk
Install the Python SDK from the generated ./sdk
directory, as shown below:
pip install -e ./sdk
Update pyproject.toml
to allow direct references, and add a local dependency:
[project]
name = "main"
version = "0.0.0"
[tool.hatch.envs.dev]
dependencies = [
"dagger-io @ {root:uri}/sdk",
]
[tool.hatch.metadata]
allow-direct-references = true
Confirm it was installed:
hatch run dev:pip list
For other package managers, check their documentation on how to accomplish the same.
If you place the virtual environment (.venv
) inside the module, don't forget to add it to .gitignore
and to "exclude"
in dagger.json
to avoid uploading those files to the runtime container unnecessarily.
It's important to install the SDK in editable mode (the -e
in the pip install
and poetry add
commands) so you don't have to reinstall it after a dagger develop
. However, it's always recommended to reinstall the SDK after upgrading Dagger to cover possible dependency changes.
When opening the generated dagger/src/index.ts
in an IDE, most IDEs will automatically recognize the @dagger.io/dagger
package, so long as the tsconfig.json
file has a path configured on it.
For Dagger modules initialized using dagger init
, the default template is already configured this way:
"experimentalDecorators": true,
"paths": {
"@dagger.io/dagger": ["./sdk"]
}
This configuration doesn't require separate installation of the dependency to enable type-hinting or other IDE features.