Theos with Visual Studio Code


Since Visual Studio Code has gained popularity as a free and open-source text editor/IDE, I think it might be a good idea to share about how I use it to compile your Theos project.

In Visual Studio Code, you can write scripts called Tasks to run on your project folder in order to build and test your code. Below is the code for two tasks written to Build with Theos and Build & Install with Theos:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Build with Theos",
      "type": "shell",
      "command": "make",
      "problemMatcher": {
        "fileLocation": ["relative", "${workspaceFolder}"],
        "pattern": {
          "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
        }
      },
      "group": {
        "kind": "test",
        "isDefault": true,
      },
      "windows": {
        "options": {
          "shell": {
            "executable": "C:\\Windows\\System32\\bash.exe",
            "args": [
              "-i",
              "-c"
            ]
          }
        }
      }
    },
    {
      "label": "Build & Install with Theos",
      "type": "shell",
      "command": "make do",
      "problemMatcher": {
        "fileLocation": ["relative", "${workspaceFolder}"],
        "pattern": {
          "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
        }
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "windows": {
        "options": {
          "shell": {
            "executable": "C:\\Windows\\System32\\bash.exe",
            "args": [
              "-i",
              "-c"
            ]
          }
        }
      }
    },
    {
      "label": "Clean with Theos",
      "type": "shell",
      "command": "make clean",
      "windows": {
        "options": {
          "shell": {
            "executable": "C:\\Windows\\System32\\bash.exe",
            "args": [
              "-i",
              "-c"
            ]
          }
        }
      }
    }
  ]
}

On Windows, Theos is installed in WSL (see Theos installation guide), Theos commands need to be run with the bash executable.

With these tasks in place, you can write you code and build with the shortcut Ctrl+Shift+B without ever having to leave your editor!

What’s even cooler is that if there are errors during your build, Visual Studio Code will even pick them up!

theos_with_vscode

With the build scripts and an integrated terminal, Visual Studio Code can be the perfect IDE for your Theos projects. Happy coding!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.