Sublime Forum

Process/task management solution

#1

Hey,

One issue I seem to struggle a lot with in Sublime is running builds and managing their processes. For simple stuff, build systems work fine. It gets problematic when I need to run multiple processes at once (e.g. server and clients).

What I always end up doing is not using sublime for builds at all, and just alt+tabbing into a terminal window to manage all of that externally. This is always a pain that I thought I’d just have to live with for not using a full IDE.

…but then I learned about Jetbrains Fleet and played around with it. While I don’t expect it to break my ST addiction, I found that it actually has a really simple and elegant solution to this problem that would work well for most projects.

Basically, you just define the tasks you want to run declaratively in a json file in your project folder, such as:

{
    "configurations": [
        {
            "type": "command",
            "allowParallelRun": false,
            "name": "Compile Server",
            "program": "cmake",
            "args": ["--build", "build/linux", "--target", "server"],
        },
        {
            "type": "command",
            "allowParallelRun": false,
            "dependsOn": ["Compile Server"],
            "name": "Run Server",
            "program": "build/linux/server",
            "args": ["--listen-port=1234"],
        },
        {
            "type": "command",
            "allowParallelRun": false,
            "name": "Compile Client",
            "program": "cmake",
            "args": ["--build", "build/linux", "--target", "client"],
        },
        {
            "type": "command",
            "allowParallelRun": true,
            "dependsOn": ["Compile Client"],
            "name": "Run Client",
            "program": "build/linux/client",
            "args": ["--server-port=1234"],
        },
    ]
}

Note how you can declare dependencies between tasks, so that e.g. “Run Server” will automatically run “Build Server”, and will abort if the build failed. Also, the allowParallelRun attribute lets you control which tasks can be run simultaneously. Since it’s false for the server above, trying to run that task while it’s already running will display a prompt telling you that it needs to be killed first.

Then, when you press the run button in the UI/activate the keyboard shortcut, you get a quick panel-like thing that asks you to pick a run configuration:

Then, you get a dedicated panel for managing these tasks, including the ability to kill/restart them, and to see their output in dedicated tabs:

This is conceptually pretty simple, but I’m not sure this would be easy to implement as a ST plugin. The UI at least seems like it’d be hard, and might involve some complicated hacks to implement. The (amazing) debugger plugin goes to great lengths to implement a fancy UI within the limitations of ST, and I suspect something similar would be needed to accomplish this.

Or maybe there’s a better way to deal with this problem in ST that I’m not aware of? I’d be curious to learn about alternative workflows people are using.

0 Likes

#2

Maybe Run Task is something which could help you out. It doesn’t support dependencies, but IIRC it can run multiple background tasks.

0 Likes

#3

Thanks for the reply,

Unfortunately, that doesn’t seem like it does what I need. Running tasks is the easy part, but managing them is what I’m struggling with. I’ve actually experimented with a couple of different (awkward) solutions to this problem, such as custom build system plugins for very specific project setups (like for O3DE), and even a clunky custom plugin which can send instructions to a command server running in a separate terminal window via sockets.

That all works, but it’s a lot of effort to build and maintain these things, and whenever I find myself fiddling with them, it makes me think that there should be an easier way to do it.

0 Likes

#4

I don’t see why it shouldn’t be possible to run multiple build systems with a dedicated outputpanel for each and a quick panel to switch between them.

It would however require a plugin with a management layer to resolve dependencies and call them in required order.

Someone would need to find the time to implement something like that however. That’s true.

What I also found recently is the Taskfile plugin, which is a frontend for Task runner. Haven’t looked into its possibilities with regards to chaining different tasks together. A task definition would however “just” require a Taskfile in project root in YAML style.

0 Likes

#5

Hadn’t heard about Taskfile before, I might have to look into that some day.

I just had an idea for this though. Instead of using a quick panel or output panel, this could be implemented using just ephemeral tabs. For example:

Process output will be piped into the view buffers, and closing a tab can be used to kill the process. As a bonus, this lets you easily save the output buffer if you want, and would avoid having to do hacky stuff.

The main issue I see with this would be that it could interfere with the existing view layout, especially weird scenarios involving Origami. I can imagine it getting confused and wreaking havoc on your workspace. Maybe it could spawn into its own separate window to prevent that, but that comes with its own annoyances…

edit: also, it would be annoying since there’s no easy way to hide them. You can drag the view to take up less vertical space, but they’ll always be there until you close them.

0 Likes

#6

The Debugger plugin does support a really basic task implementation but I haven’t gotten around to adding support for something like dependsOn if you wanted to add that.

The end goal for the Debugger package is to allow basically the same functionality as vscode including the tasks stuff since without it there is no way to build stuff before a debug session

1 Like

#7

Interesting idea, I haven’t dug into your plugin, but that seems like a better idea than what I was working on. Shortly after I made the above post, I spent some time playing around with sublime and did make a generic task manager plugin that does what I need, but dropped it after struggling to create a decent interface to it.

The closest thing to a usable interface I made was a virtual file thing that creates files in a tmp folder and adds them to the sidebar, with the idea being that you could open them to view stdout/err, delete them to kill the process, etc. I ran into issues with sublime though, since there doesn’t seem to be a delete callback, streaming process output into a tab wasn’t working well, and trying to reach feature parity with the output panel would’ve been a lot of work (e.g. error parsing + annotations).

Maybe I’ll look into extending the debugger plugin this weekend, or at least release what I made in case someone else with more plugin dev experience wants to give it a try.

0 Likes