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

Enable use of snippet variables in workbench.action.terminal.sendSequence #66337

Closed
fbehrens opened this issue Jan 10, 2019 · 19 comments · Fixed by #67182
Closed

Enable use of snippet variables in workbench.action.terminal.sendSequence #66337

fbehrens opened this issue Jan 10, 2019 · 19 comments · Fixed by #67182
Assignees
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities terminal Integrated terminal issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@fbehrens
Copy link

Hi :)

I would love to be able to use task variables to send snippets of code to my terminal.

{ "key": "ctrl+shift+t",
  "command": "workbench.action.terminal.sendSequence", 
  "args": { "text": ". ${file}" } 

I am developing all the time interactively with editing a file and fiddling in a REPL (in integrated Terminal) alongside, where I have my environment loaded. I edit a function, I load the file from the REPL, and then test it interactively.

The difference to Tasks is that I have state in the REPL. This then can be used for different languages with a simple configuration.

I have written a Sublime Plugin for this feature,
and I will write a Extension, according to your response.

Thanks for reading, and keep up the good work

@vscodebot vscodebot bot added the terminal Integrated terminal issues label Jan 10, 2019
@Tyriar
Copy link
Member

Tyriar commented Jan 10, 2019

@alexr00 any tips on leveraging task code to resolve this?

@Tyriar Tyriar added help wanted Issues identified as good community contribution opportunities feature-request Request for new features or functionality labels Jan 10, 2019
@alexr00
Copy link
Member

alexr00 commented Jan 11, 2019

Let me make sure I understand the request:

  1. You set up your REPL with some state
  2. You run the command above using your keybinding which causes the file you want to test to be loaded into the REPL.
  3. You then want to run preset snippets of code in the REPL. This is the part where you want to use tasks variables to send preset code snippets to the REPL.

Is all that correct? If so, I think this can be accomplished with tasks in insiders.

There is now a third input type; command. #64362. I think you could use this to accomplish step three above by having a few different command input types that use the workbench.action.terminal.sendSequence command and has the snippet you want as an argument. You would need a separate task + command input variable for each snippet, I can't think of a way around that unless you write a simple extension.

You might need to make your task presentation reveal silent or never. I'm not sure how workbench.action.terminal.sendSequence will interact with the active terminal being one used by tasks.

@Tyriar
Copy link
Member

Tyriar commented Jan 11, 2019

@alexr00 the workbench.action.terminal.sendSequence commands lets you send data to any terminal (not just task ones), it basically lets users fake typing in without building an extension to do it. For example you could send ctrl+c or "ls" then enter. The request is just about supporting resolving the ${...} syntax as used within tasks in the workbench.action.terminal.sendSequence command.

The example keybinding:

{ "key": "ctrl+shift+t",
  "command": "workbench.action.terminal.sendSequence", 
  "args": { "text": ". ${file}" } 

Could be used to 'source' (run) the active file in the active terminal.

I mainly wanted to code pointer to where this variable resolution happens in tasks and/or debug so that a contributor could put a PR together and share the code.

@njkevlani
Copy link
Contributor

@Tyriar
I'd love to help by implementing this feature if you guys would want me to :)

I think we need to handle snippets in code of sendSequence itself or is there any other way round?

@Tyriar
Copy link
Member

Tyriar commented Jan 22, 2019

@njkevlani you'll probably need to call this IConfigurationResolverService.resolve similar to how it's called on the environment:

https://github.com/Microsoft/vscode/blob/ddd17d938ffcdc40158b845c9abc25dcc2978c7e/src/vs/workbench/parts/terminal/node/terminalEnvironment.ts#L84

And yes in the code for the sendSequence action.

@Tyriar Tyriar added the good first issue Issues identified as good for first-time contributors label Jan 22, 2019
@njkevlani
Copy link
Contributor

@fbehrens you wanna work over this or can I take it?

@fbehrens
Copy link
Author

fbehrens commented Jan 22, 2019

@njkevlani Great ! You can take it.

@Tyriar
Copy link
Member

Tyriar commented Jan 23, 2019

@njkevlani 👌

@njkevlani
Copy link
Contributor

This is a fairly simple task, and to implements this, I need to resolve (variables like ${file}, etc) the args.text before passing it to terminalInstance.sendText in SendSequenceTerminalCommand function.

I have a question,

To resolve a string I need to have an object of ConfigurationResolverService class or something that simply extends AbstractVariableResolverService.

How do I instantiate or pass such object to SendSequenceTerminalCommand function?

ping @Tyriar

@Tyriar
Copy link
Member

Tyriar commented Jan 26, 2019

@njkevlani
Copy link
Contributor

@Tyriar

That works for classes which extend Action, I could not find such usage for some class which extends Command.

Probably It is because how the Commands are registered:

https://github.com/Microsoft/vscode/blob/4fe1cdc4df003911507e53a06ccfb261f68bce18/src/vs/workbench/parts/terminal/electron-browser/terminal.contribution.ts#L515-L519

@Tyriar
Copy link
Member

Tyriar commented Jan 27, 2019

@njkevlani I think you should be able to convert it to an Action?

@njkevlani
Copy link
Contributor

@Tyriar I thought exactly the same!! But could not find an example of an Action that takes something like args. Will do it if you could give some pointer to such specs.

@Tyriar
Copy link
Member

Tyriar commented Jan 27, 2019

@njkevlani ah I see, I guess that's why it's a Command 😃

Looks like a ServicesAccessor is passed into runCommand, you should be able to grab the service off that like this:

https://github.com/Microsoft/vscode/blob/4fe1cdc4df003911507e53a06ccfb261f68bce18/src/vs/editor/browser/controller/coreCommands.ts#L1652-L1654

@njkevlani
Copy link
Contributor

njkevlani commented Jan 27, 2019

@Tyriar

It's working!!

Should auto completion be implemented? If yes, how do we kick in auto suggestions in keybinding.json?

@Tyriar
Copy link
Member

Tyriar commented Jan 27, 2019

@njkevlani great! I've never done that before so I'm not sure, also not sure if we support doing that in other keybindings (in which case it'd be a bunch of work). Let's do a PR without it to start with 😃

@fbehrens
Copy link
Author

fbehrens commented Feb 9, 2019

Works like a charm in insiders.

I have another edge case question concerning the feature, more about haw the task variables are resolved. Don't expect an answer, and hope it is OK to ask here.

On Windows ${file} is d:\scripts2\libwba\src\tools\environment.fs, but ${relativeFile} is src/tools/environment.fs . Is there a way to influence the path seperator (\ vs /) ?

@alexr00
Copy link
Member

alexr00 commented Feb 11, 2019

@fbehrens, no there isn't a way to influence the path separators. #38381 is the issue related to this.

@octref octref added the verification-needed Verification of issue is requested label Feb 25, 2019
@jrieken jrieken added the verified Verification succeeded label Feb 25, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality good first issue Issues identified as good for first-time contributors help wanted Issues identified as good community contribution opportunities terminal Integrated terminal issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants