Get relative path of the file for tasks in vscode

Deadly 提交于 2019-12-09 18:22:45

问题


I have a task defined in vscode's tasks.json file as following

{
    "version": "0.1.0",
    "tasks": [
        {
            "command": "gulp",
            "taskName": "eslint_task",
            "args": [
                "eslint",
                "--file",
                "${file}"
            ],
            "echoCommand": true
        }
    ]
}

The ${file} is providing me the absolute path (starting from /Volumes in macOS) of the file on which I run this command. Is there any way I can get the relative path (Path starting from the workspace folder) of the same file instead?

I already checked the official documentation for tasks, but couldn't find any list of arguments there.


回答1:


Found the answer. I just need to use ${relativeFile} instead of ${file}.

Here's the list of placeholder I have found -

  • ${workspaceRoot}: workspace root folder
  • ${file}: path of saved file
  • ${relativeFile}: relative path of saved file
  • ${fileBasename}: saved file's basename
  • ${fileDirname}: directory name of saved file
  • ${fileExtname}: extension (including .) of saved file
  • ${fileBasenameNoExt}: saved file's basename without extension
  • ${cwd}:current working directory

Source: Taken from here.



来源:https://stackoverflow.com/questions/43365124/get-relative-path-of-the-file-for-tasks-in-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!