Skip to main content

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.

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
tip

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.

When working with multiple inter-dependent Dagger modules, it can be challenging to navigate between Dagger Functions defined in different modules. Source-maps offer a solution to this problem, by allowing developers to directly click through or navigate to type declarations in their IDE.

The Go SDK automatically attaches source-maps to the module code. These are a record of the filename, the line number, and the column number that a type declaration corresponds to in the source code. The SDK analyzes the source code, and outputs these (as line comments of the form ./path/to/filename:line) when creating the type definitions during module initialization.

Most popular IDEs support source-maps, either natively or with an external plugin, such as the Open file plugin for Visual Studio Code.