Theia: 'Run Selected Text' is not working when a task is stopped

Created on 12 Mar 2020  ·  10Comments  ·  Source: eclipse-theia/theia

Description

'Run Selected Text' action is not working when current terminal widget is completed task widget.

Reproduction Steps

  1. Run any task
  2. Stop the task
  3. Select a command and use Run Selected Text action

runSelected

OS and Theia version:
Ubuntu 18.04.1
Theia: ced3f90a3b1ebf6fcfaf5a62e082dcdfa1f0304c

Diagnostics:
I guess Run Selected Text action tries to use stopped task as current terminal widget.

bug help wanted tasks terminal

Most helpful comment

terminal.kind will be introduced in https://github.com/eclipse-theia/theia/pull/7260. After it merged, this PR should be fixable by respecting only user terminals.

All 10 comments

I did some investigation, and found an intesting behavior in vs code: "Run Selected text" simply echos the selected text in the current terminal which has one task actively running, instead of running the selected text as a command (See the attached GIF). Is it the correct behavior ?

In my opninion, the "selected text" should always be run in an interactive terminal, no exceptions. If there is a task running in the current terminal, we should find an interactive terminal, or create an interactive terminal to execute the selected text as a command.

What do you think? @RomanNikitenko @vince-fugnitto @akosyakov @eclipse-theia/task-extension

Peek 2020-03-16 22-41

In my opinion, the "selected text" should always be run in an interactive terminal, no exceptions.

I agree, I find it odd that vscode would use a busy terminal to display output of “run selected text”. In my opinion, the output would be lost in all the noise of a task which is currently under execution. I think we should opt for the simplest solution which is to look for an idle interactive terminal to run the text or create a terminal if none exist.

In my opninion, the "selected text" should always be run in an interactive terminal, no exceptions. If there is a task running in the current terminal, we should find an interactive terminal, or create an interactive terminal to execute the selected text as a command.

Agree.
For 'Run Selected Text' we should use:

  • an idle terminal, if it exists
  • create a terminal if it does not exist

would this solution work for you?

  • "Run selected text" runs the selected string as a command in interactive terminals
  • If no terminals are interactive, run it in a new interactive terminal. Please note, in the GIF below, the terminal that ran "long running task" wasn't an interactive terminal and therefore we created a new one.

Peek 2020-03-17 21-41

What it a definition of the idle terminal If i don't know about tasks?

What it a definition of the idle terminal If i don't know about tasks?

@akosyakov
as you know, "idle" is not a property of the terminal. so we have no idea if a terminal is idle.

that's why I proposed the solution of "only running selected text in an interactive terminal"

and we could use terminalWidget.hasRunningProcesses() to check if an interactive terminal is busy.

What do you think?

and we could use terminalWidget.hasRunningProcesses() to check if an interactive terminal is busy.

Terminal which does not run any task also has a running process (shell). How is it related to terminal be interactive? How do you define terminal interactive? That it can accept a user input? How could you check that a terminal process can accept a user input?

  • I don't really think terminal can tell a user whether it is interactive or not. Whether script running in a terminal can accept user input or not it is a property of a script, not a terminal process. And since terminals are only operating process streams it is abstracted away from concrete scripts. I would say it is responsibility of a terminal client to know whether something running in the terminal is interactive or not, i.e. a task can be interactive.
  • I am not sure what interactive is correct term even for tasks. How do you know whether a concrete task needs user input or not?
  • So if we cannot use interactive, we are back to idle/busy concept. For this concept similarly as for interactive we cannot know it for terminal, but for a task is more clear. A task is either still running or finished.
  • We have busy concept already for other widgets in Theia: monaco editors and trees. In the editor the peek widget can be busy for example while resolving references and in the tree a concrete node while it is resolving child nodes. In both cases there is API allowing to change busy state, so maybe we add something similar to terminal:
export interface TerminalWidget {
   busy: boolean;
   readonly onDidChangeBusy: Event<boolean>;
}
  • Whenever a task extension is running a task in the terminal it should set busy state and then it is done remove it.
  • Having busy state we can implement this issue following such logic:

    • if the current terminal is not busy, run command in it

    • it it is busy, create a new terminal

    • I don't think revealing some random hidden terminal to run a task is a good idea.

  • I think https://github.com/eclipse-theia/theia/issues/7323#issuecomment-601060436 is most appropriate.

Or maybe we can introduce something like TerminalType with System and User kind, defaults to User. System kind means that a terminal was created by a product for some reasons and cannot be used to run random user scripts, e.g. for tasks. Then for this issue we will check whether a current terminal is User terminal and if not create a new User terminal. In both cases terminals can be interactive, i.e. if a task requires some input from a user.

I actually like it more, since it looks like terminals running task should disallow running a random user program and busy won't help with it. But System kind can resolve both issues.

terminal.kind will be introduced in https://github.com/eclipse-theia/theia/pull/7260. After it merged, this PR should be fixable by respecting only user terminals.

Was this page helpful?
0 / 5 - 0 ratings