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

Support $relativeDir as executorMap parameter #559

Open
Jiia opened this issue Nov 12, 2019 · 5 comments
Open

Support $relativeDir as executorMap parameter #559

Jiia opened this issue Nov 12, 2019 · 5 comments

Comments

@Jiia
Copy link

Jiia commented Nov 12, 2019

My project is running inside a docker container, and I'd like to create a custom execute command to run the file inside the container. However as there is no parameter for relative path I'm unable to build a command that would be able to locate the file inside the container.

The closest I can get is this:

docker-compose exec -T my-container bash -c 'php -f $fullFileName'

But that doesn't work since the path to the file is completely different inside the container.

Solution
Relative path parameter:

docker-compose exec -T my-container bash -c 'php -f /container/path/to/project/$relativeDir/$fileName'
@Jiia
Copy link
Author

Jiia commented Nov 13, 2019

Managed to work around it by setting fileDirectoryAsCwd to false and using realpath.

"code-runner.executorMap": {
    "php": "docker-compose exec -T --env codeRunnerFile=$(realpath --relative-to=${PWD} $fullFileName) my-container bash -c \"php -d display_errors=1 -d /container/path/toProject/\\${codeRunnerFile}\""
},
"code-runner.fileDirectoryAsCwd": false

@doggy8088
Copy link

doggy8088 commented Oct 29, 2020

In go, I need to execute go run . to the program. Hope @formulahendry can add this $relativeDir to Code Runner soon. Thanks!

My config now:

    "code-runner.cwd": "",
    "code-runner.fileDirectoryAsCwd": true,
    "code-runner.executorMap": {
        "go": "go run $dir"
    }

When Run Code:

g:\Projects\demo1\cmd>go run "g:\Projects\demo1\cmd\"
CreateFile g:\Projects\demo1\cmd": The filename, directory name, or volume label syntax is incorrect.

I'd like to have this:

go run .

When I change config to this:

    "code-runner.cwd": "",
    "code-runner.fileDirectoryAsCwd": true,
    "code-runner.executorMap": {
        "go": "go run $dirWithoutTrailingSlash"
    }

If I put main.go to the workspace root folder. I'll get this:

G:\Projects\demo1>go run "g:\Projects\demo1"
directory . outside available modules

I'd like to have this:

go run .

If I put main.go to any subfolder, I'll run correctly.

So the best way to have is:

Config like this, but relative path if based on cwd or relative to fileDirectoryAsCwd.

    "code-runner.cwd": "",
    "code-runner.fileDirectoryAsCwd": true,
    "code-runner.executorMap": {
        "go": "go run $relativeDirWithoutTrailingSlash"
    }

I hope to get this:

go run .

@benjaminpinto
Copy link

$relativeDir would be a great feature.

@palansher
Copy link

yes, I it is reaaly useful to imlement such vars as is in VS CODE:
${relativeFile} - the current opened file relative to workspaceFolder
${relativeFileDirname} - the current opened file's dirname relative to workspaceFolder

Workaround works, thank you!

@ldeng-ustc
Copy link

It seems that the addition of this variable is still a long way off, so I provide a temporary alternative.
For those who can use shell commands, one way to get the relative path is to use the realpath command, for example, $relativeDir can be replaced with the following command:

`realpath -s --relative-to=$workspaceRoot $dir`

For example, I use the following configuration to run cmake to generate executable files under build that have the same path structure as the source code:

    "code-runner.executorMap": {
        "cpp": "./build/`realpath -s --relative-to=$workspaceRoot $dir`/$fileNameWithoutExt",
    },

Of course, this does not look elegant, but at least it is an optional solution.

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

No branches or pull requests

5 participants