Odin in Zed

What is Odin?

Odin is a general-purpose programming language with distinct typing built for high performance, modern systems and data-oriented programming. Odin is the C alternative for the Joy of Programming.

Odin Programming Language website

What is Zed?

Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter. It’s also open source.

Zed website

How to write and run Odin programs in Zed?

The following instructions describe how to use Zed code editor and its tasks feature to easily run programs written in Odin from within the editor.

Note: I am using Zed installed in Ubuntu.

  1. Install the Odin extension to enable Odin language support (syntax highlighting, code completion, etc.)

  2. Create .zed folder in your projects folder.

  3. Create tasks.json file in the .zed folder. s

  4. Add the following configuration to tasks.json:

    [
      {
        "label": "Run",
        "command": "odin run .",
        "reveal": "never"
      }
    ]
    

    Note: The last line ("reveal": "never") is optional but it allows to keep focus in the editor. Technically, there is a dedicated setting "hide" that should hide the terminal tab after the task finishes but it does not seam to work properly. The only drawback of using the "reveal": "never" setting is that the “Run” tab will not get focus if there are other terminal tabs already opened.

  5. [Optional] You can add different tasks like build, debug, test, etc. to the tasks.json. See the tasks docs for more details. Below is an example for the excelent hot reload flow by Karl Zylinski.

    [
      {
        "label": "Hot Reload",
        "command": "./build_hot_reload.sh",
        "reveal": "never",
        "hide": "always"
      },
      {
        "label": "Run",
        "command": "./game.bin",
        "reveal": "never",
        "hide": "always"
      },
      {
        "label": "Build Debug",
        "command": "./build_debug.sh"
      },
      {
        "label": "Build Release",
        "command": "./build_release.sh"
      }
    ]
    
  6. Restart Zed. Without this step, some of the settings do not work as expected.

  7. Now you can run the task using one of the following ways:

    1. “task: spawn” (alt-shift-t) command from the command palette (F1, ctrl-shift-p or : in vim mode). screenshot screenshot
    2. alt-p to re-run the last task.
    3. You can also create a custom key bindings and assign different keys for each task:
      {
        "context": "Workspace",
        "bindings": {
          "shift-f10": ["task::Spawn", { "task_name": "Hot Reload" }],
          "ctrl-shift-r": ["task::Spawn", { "task_name": "Run" }]
        }
      }
      
      Again, you must restart Zed (or at least reload project) to fully apply the changes.

Enjoy coding in Odin in Zed!

mqdr


2024-07-28