Skip to content

Commit

Permalink
docs: Add multi-lang IDE integration page (#7378)
Browse files Browse the repository at this point in the history
* docs: Add multi-lang IDE integration page

Signed-off-by: Vikram Vaswani <vikram@dagger.io>

* Fix lint errors

Signed-off-by: Vikram Vaswani <vikram@dagger.io>

* Fix link

Signed-off-by: Vikram Vaswani <vikram@dagger.io>

* Add feedback

Signed-off-by: Vikram Vaswani <vikram@dagger.io>

* Update sidebar

Signed-off-by: Vikram Vaswani <vikram@dagger.io>

* Add feedback

Signed-off-by: Vikram Vaswani <vikram@dagger.io>

---------

Signed-off-by: Vikram Vaswani <vikram@dagger.io>
  • Loading branch information
vikram-dagger committed May 24, 2024
1 parent d0ab815 commit f1485c1
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 132 deletions.
37 changes: 0 additions & 37 deletions docs/current_docs/manuals/developer/go/562832-ide-integration.mdx

This file was deleted.

2 changes: 1 addition & 1 deletion docs/current_docs/manuals/developer/go/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ If you're just getting started, the learning path below will give you the essent
- Work with [secrets](../secrets.mdx)
- Call code from [other modules](../module-dependencies.mdx)
- [Handle errors](../error-handling.mdx) and [debug](./924957-debugging.mdx) your module
- Get [IDE support](./562832-ide-integration.mdx) for your module development
- Get [IDE support](../ide-integration.mdx) for your module development

Detailed [reference documentation for the Go SDK](https://pkg.go.dev/dagger.io/dagger) is also available.
128 changes: 128 additions & 0 deletions docs/current_docs/manuals/developer/ide-integration.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
slug: /manuals/developer/ide-integration
displayed_sidebar: "current"
toc_max_heading_level: 2
title: "IDE Integration"
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# 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.

<Tabs groupId="language">
<TabItem value="Go">
To get your IDE to recognize a Dagger Go module, [configure your `go.work` file](./go/882081-module-structure.mdx#go-workspaces) 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](https://go.dev/doc/tutorial/workspaces):

```shell
# 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:

```shell
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.
:::
</TabItem>
<TabItem value="Python">
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.

<Tabs groupId="pytools">
<TabItem value="pip">

Install the Python SDK in a [virtual environment](https://packaging.python.org/en/latest/tutorials/installing-packages/#creating-virtual-environments) from the generated `./sdk` directory, as shown below:

```shell
python -m venv .venv
source .venv/bin/activate
pip install -e ./sdk
```
</TabItem>
<TabItem value="Poetry">

Add `./sdk` as a development dependency:

```shell
poetry add -e --group=dev ./sdk
```
</TabItem>
<TabItem value="Hatch">

Install the Python SDK from the generated `./sdk` directory, as shown below:

```shell
pip install -e ./sdk
```

Update `pyproject.toml` to [allow direct references](https://hatch.pypa.io/latest/config/metadata/#allowing-direct-references), and add a [local](https://hatch.pypa.io/latest/config/dependency/#local) dependency:

```toml
[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:

```shell
hatch run dev:pip list
```
</TabItem>
</Tabs>

For other package managers, check their documentation on how to accomplish the same.

:::tip
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.
:::

:::note
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.
:::

</TabItem>
<TabItem value="TypeScript">

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:

```json
"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.


</TabItem>
</Tabs>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ dagger-io = {path = "sdk", develop = true}

## Other workflow tools

Dagger is agnostic to the tool used [in development](./742020-ide-integration.mdx). Similarly to Rye and Poetry, as long as the right standards are supported, Dagger should be able to use it too.
Dagger is agnostic to the tool used [in development](../ide-integration.mdx). Similarly to Rye and Poetry, as long as the right standards are supported, Dagger should be able to use it too.


[v11]: https://github.com/dagger/dagger/releases/tag/sdk%2Fpython%2Fv0.11.0
2 changes: 1 addition & 1 deletion docs/current_docs/manuals/developer/python/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ If you're just getting started, the learning path below will give you the essent
- Work with [secrets](../secrets.mdx)
- Call code from [other modules](../module-dependencies.mdx)
- [Handle errors](../error-handling.mdx) and [debug](./924959-debugging.mdx) your module
- Get [IDE support](./742020-ide-integration.mdx) for your module development
- Get [IDE support](../ide-integration.mdx) for your module development

Detailed [reference documentation for the Python SDK](https://dagger-io.readthedocs.org/) is also available.

This file was deleted.

2 changes: 1 addition & 1 deletion docs/current_docs/manuals/developer/typescript/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ If you're just getting started, the learning path below will give you the essent
- Work with [secrets](../secrets.mdx)
- Call code from [other modules](../module-dependencies.mdx)
- [Handle errors](../error-handling.mdx) and [debug](./372032-debugging.mdx) your module
- Get [IDE support](./629502-ide-integration.mdx) for your module development
- Get [IDE support](../ide-integration.mdx) for your module development

Detailed [reference documentation for the TypeScript SDK](../../../reference/typescript/modules.md) is also available.
6 changes: 6 additions & 0 deletions docs/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
to = "/manuals/developer/language-dependencies"
status = 301

[[redirects]]
# redirect developer manual language-specific IDE pages to multi-language IDE page
from = "/manuals/developer/:language/:docid/ide-integration"
to = "/manuals/developer/ide-integration"
status = 301

[[redirects]]
# redirect developer manual overview pages
from = "/manuals/developer/overview/:docid/*"
Expand Down
16 changes: 4 additions & 12 deletions docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ module.exports = {
"type": "doc",
"id": "manuals/developer/functions"
},
{
"type": "doc",
"id": "manuals/developer/ide-integration"
},
{
"type": "doc",
"id": "manuals/developer/secrets"
Expand Down Expand Up @@ -380,10 +384,6 @@ module.exports = {
"type": "doc",
"id": "manuals/developer/go/module-structure"
},
{
"type": "doc",
"id": "manuals/developer/go/ide-integration"
},
{
"type": "doc",
"id": "manuals/developer/go/debugging"
Expand Down Expand Up @@ -428,10 +428,6 @@ module.exports = {
"id": "manuals/developer/python/module-structure"
},

{
"type": "doc",
"id": "manuals/developer/python/ide-integration"
},
{
"type": "doc",
"id": "manuals/developer/python/debugging"
Expand Down Expand Up @@ -479,10 +475,6 @@ module.exports = {
"type": "doc",
"id": "manuals/developer/typescript/module-structure"
},
{
"type": "doc",
"id": "manuals/developer/typescript/ide-integration"
},
{
"type": "doc",
"id": "manuals/developer/typescript/debugging"
Expand Down

0 comments on commit f1485c1

Please sign in to comment.