Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

visual studio code - How to set up a task to run a tool on a selection of text?

I wrote a tool to do some processing on an input plain text file. I would like to use this tool from a task in VSCode sending as input a selection of this plain text file being edited in VSCode.

My input plain text file would be like:

This is a first line
This is line number two
This is the third one
etc...

So, there is a EOL at the end of every line. I would then select some of these lines and send them to the tool for processing via the task

I was thinking something along the lines:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run tool on selection",
            "type": "shell",
            "command": "echo ${selectedText} > tmpFile.txt; mytool.exe tmpFile.txt ",
        }
    ]
}

... but obviously this didn't work: myFile has not been created and I seem to also have problems echo-ing new lines. I also don't know whether there is a way of doing this without dumping the selection to a temp file. Can anyone help me set this up correctly? Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...