Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Tasks #1798

Merged
merged 36 commits into from
Jul 27, 2024
Merged

Run Tasks #1798

merged 36 commits into from
Jul 27, 2024

Conversation

tom-ludwig
Copy link
Member

@tom-ludwig tom-ludwig commented Jul 5, 2024

Description

This PR introduces the ability to run tasks within CodeEdit, utilizing a .codeedit folder to store task configurations. The goal is to enable users to create and manage tasks quickly and easily.

Simple Tasks Example:

{
  "tasks" : [
    {
      "command" : "go build",
      "name" : "build",
    }
  ]
}

Tasks with Environment Variables:

  "tasks" : [
    {
      "environmentVariables" : {
        "database" : "maps"
      },
      "target" : "Docker",
      "name" : "build",
      "command" : "go build",
      "workingDirectory" : "\/Users\/tommyludwig\/ScratchFolder\/task-tests"
    }
  ],

Key Structures Introduced:

  • CETask: Configuration for executing a task, including command and environment settings.
  • CEActiveTask: Represents a running task with output and status (running, stopped, failed, succeeded). CETask is injected into CEActiveTask with essential information such as full command and environment variables.
  • CETaskManager: Handles active tasks (run, renew, suspend, resume, terminate, interrupt).
  • CEWorkspaceSettings: Holds workspace-specific settings data. Distinct from CEWorkspaceSettingsManager, which handles workspace settings management (e.g., saving, loading).

Active Task States:

An active task can be:

  • notRunning: The task hasn't been interacted with yet.
  • stopped: The task is currently suspended(paused).
  • running: The task is actively running.
  • failed: The task finished with an error code.
  • finished: The task successfully completed.

Task Shell Options:

TaskShell provides various shells (e.g., bash, zsh, csh) for executing commands. Currently defaults to bash; future updates may include user settings for shell preference. Tasks are executed using executeCommandWithShell, utilizing a Swift Process to run commands within the user's environment plus additional variables from CETask. Output (stdout and stderr) is captured using a Pipe`.

Important

Reviewers, please pay close attention to the usage of classes vs. structs, as well as the naming conventions for classes, functions, and variables. Clear naming decisions now will save significant effort later.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

Screenshot 2024-07-05 at 4 00 06 PM Screenshot 2024-07-05 at 3 59 49 PM Screenshot 2024-07-05 at 3 59 19 PM Screenshot 2024-07-05 at 3 59 04 PM

Copy link
Collaborator

@thecoolwinter thecoolwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few visual bugs, and a few possible race conditions with the async methods in CEActiveTask.

CodeEdit/Features/Tasks/TaskManager.swift Outdated Show resolved Hide resolved
CodeEdit/Features/Tasks/TaskManager.swift Show resolved Hide resolved
CodeEdit/Features/Tasks/TaskManager.swift Outdated Show resolved Hide resolved
CodeEdit/Features/Tasks/Shell/TaskShell.swift Outdated Show resolved Hide resolved
CodeEdit/Features/Tasks/CEActiveTask.swift Outdated Show resolved Hide resolved
CodeEdit/Features/Tasks/CEActiveTask.swift Outdated Show resolved Hide resolved
CodeEdit/Features/Tasks/CEActiveTask.swift Outdated Show resolved Hide resolved
@tom-ludwig tom-ludwig requested a review from thecoolwinter July 12, 2024 11:00
Copy link
Collaborator

@thecoolwinter thecoolwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking very close to the finish line. Last thing, how should we handle tasks being removed? Right now they stay in the debugger area but I wonder if we should remove them.

Screenshot 2024-07-14 at 7 32 17 PM
Screenshot 2024-07-14 at 7 32 13 PM

And the bottom bar on this list needs a background:
Screenshot 2024-07-14 at 7 32 33 PM

@tom-ludwig
Copy link
Member Author

I’ve taken care of those issues. Over the past few days, I’ve been thinking about how to handle tasks when they get deleted. My initial thought was that active tasks shouldn’t be removed when the run configuration is deleted, as users would lose the task output. However, it might also be really confusing if the active task stays while the configuration disappears. So, I decided to delete the active task if the run configuration is deleted.

@tom-ludwig tom-ludwig requested a review from thecoolwinter July 18, 2024 10:58
thecoolwinter
thecoolwinter previously approved these changes Jul 18, 2024
Copy link
Collaborator

@thecoolwinter thecoolwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, I think that's a good decision for the deleted tasks.

Great work!

0xWDG
0xWDG previously approved these changes Jul 18, 2024
@0xWDG
Copy link
Collaborator

0xWDG commented Jul 18, 2024

Looks good, you have some conflicts, can you fix those please?

@thecoolwinter thecoolwinter dismissed stale reviews from 0xWDG and themself via 99f4828 July 27, 2024 16:47
@thecoolwinter
Copy link
Collaborator

Should be good to go!

@thecoolwinter thecoolwinter merged commit b2b4909 into main Jul 27, 2024
2 checks passed
@thecoolwinter thecoolwinter deleted the feat/268/tasks branch July 27, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Add code compiling support ✨ Tasks (Run scripts in the shell)
5 participants