formulahendry / formulahendry/vscode-code-runner

[Feature request] Allow maps to match relative paths or parent directories

Open
#1,255 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
2.4k
Forks
351
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
I use a tool that extracts code from fenced code blocks in Markdown files, so that users can combine code and documentation together in a single file. Currently, `executorMapByGlob` cannot distinguish Markdown files with the same name when they are located in different directories. For example:

```
.
├── 📁 foo
│ └── 📝 README.md
└── 📁 bar
└── 📝 README.md
```

Of course, `README.md` isn't usually executable. So, in general, it also isn't possible to enable execution on the above, while preventing code-runner from being able to execute the ordinary documentation-only `README.md`.

**Describe the solution you'd like**
It would be great to either enhance `executorMapByGlob` to support parent directories (up to the project root, i.e., the parent directory of `.vscode`). Alternatively, add another configuration key — similar to what exists with `executorMapByFileExtension` — that allows mapping by relative file path (with or without globbing). For example:

```jsonc
{
//
// Current mapping options
//
"code-runner.executorMap": {
"javascript": "node"
},
"code-runner.executorMapByGlob": {
"pom.xml": "cd $dir && mvn clean package"
},
"code-runner.executorMapByFileExtension": {
".vbs": "cscript //Nologo"
},
//
// 1. Add mapping by path option "code-runner.executorMapByPath"
// - Absolute paths could be rooted at:
// - project root (parent dir of ".vscode")
// - or the path specified via "code-runner.cwd"
// - Relative paths might cause conflict
// - resolve as you do with conflicts from "executorMapByGlob"
//
"code-runner.executorMapByPath": {
"/a/path/to/file.ext": "foo", // absolute paths /a, /b are relative to
"/b/path/to/file.ext": "bar", // project root or "code-runner.cwd"
"path/to/file.ext": "baz" // conflicts with previous 2 mappings ^
},
//
// 2. Or extend current "code-runner.executorMapByGlob"
// to eval match against parent directories as well
// - Supports absolute/relative paths as in option 1. above
//
"code-runner.executorMapByGlob": {
"/*/path/to/file.ext": "foo", // glob does not cross path sep boundaries
"/path/to/*.ext": "bar", // no conflict: "path" is not in subdir
"**/path/to/*.ext": "baz", // conflicts with previous 2 entries ^
"path/to/*.ext": "quux" // identical to previous
}
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.