Support for multiple file extensions in patterns
I couldn't find if this is supported but what I am trying to achieve is to provide common support for files with ex and exs extensions. I have tried *.ex|*.exs, *.{ex,exs}, *.exs? and none of these works. Is there any way to support such cases?
I'm also interested in this use case. Did anyone figured out if it is possible to do that today?
It's not currently possible. My intended solution was to provide an additional projection for each extension. The repetition can be annoying but it's usually possible to mitigate with VimL.
Share your use cases here, and I can start thinking about potential enhancements to handle this. I'm reluctant to complicate the format, but I realize this is a very common use case.
@tpope for me it is to simplify configuration when using Projectionist with Makery which greatly extends built-in :make support. So with such I could write:
{
"*.ex|*.exs": {
"makery": {
"make": { "compiler": "mix" },
"test": { "compiler": "exunit" },
"lint": { "compiler": "credo" }
}
}
}
And it would simply simplify and streamline my configuration.
I just stumbled upon this myself, @tpope. My use case is a Node/JavaScript (React) project. Here is an example of how things might look:
src/
db.js
db.test.js
ui/
Component.jsx
Component.test.jsx
The following projection works but only for .js files.
{
"src/*.js": {
"alternate": "src/{}.test.js",
"type": "source"
},
"src/*.test.js": {
"alternate": "src/{}.js",
"type": "test"
}
}
Ideally, I'd like to do the following:
{
"src/*.js": {
"alternate": "src/{}.test.jsx?",
"type": "source"
},
"src/*.test.js": {
"alternate": "src/{}.jsx?",
"type": "test"
}
}
Luckily "alternate": ["src/{}.test.js", "src/{}.test.jsx"] handles that case just fine.
That wouldn’t work if I’m in a test and want to switch to a component that has a .jsx extension. Or would it? Also, I’d assume :Esource wouldn’t find .jsx files?
Correct, you'll still need a top level src/*.jsx key.
Gotcha. Thanks! 🙂 while we’re at it, it’s not possible make the source-projection not match the test files? src/*.js match both implementation and test files. Usually tests are scoped by their own directory but in this project they live beside the implementation.
Correct. This is less of a priority because, frankly, it's an obnoxious naming scheme. It'll trip up a lot more than Projectionist.
Yeah, I thought so. Appreciate the quick responses. 🙂
Out of curiosity what more than Projectionist might have problem with that naming scheme? This pattern is especially common in Go (almost exclusively used).
Just that I can't even do things like ls src/*.js to see implementation files, I have to do ls src/*.js|grep -v test, and even that has false positives, so I have to actually do ls src/*.js|grep -v '\.test\.js$'. I am on principle against any naming scheme with a description that includes "but".
On the other hand, if you want to say that a test file is just a special kind of source file, then it does kind of make sense. Of course, that also means that they're also :Esource files.
I'm an EmberJS developer and I'd like to define a projection for either a .js or .ts file (the project is part way through a migration to typescript) to allow switching to a template file. Is this an example use case which fits the criteria of this issue?
e.g something like:
"app/components/*.{js,ts}": {
"type": "component",
"alternate": "app/components/{}.hbs",
},
Unfortunately the only solution to this is to repeat yourself, with 2 sections.
Thanks, I have the following repeated sections, I can successfully jump from some-component.ts or some-component.js to the associated templates with :Etemplate.
However, when attempting to jump back from a template with :Ecomponent, if the original component is a js a file, a new empty buffer is generated for a ts (aka it doesn't land in the expected original js file).
If the original component is in ts, jumping back from the template to the component works as expected:
["app/components/*.ts"] = {
type = "component",
alternate = {
"app/components/{}.hbs",
"app/components/{}.stories.js",
"tests/integration/{}-test.js",
}
},
["app/components/*.js"] = {
type = "component",
alternate = {
"app/components/{}.hbs",
"app/components/{}.stories.js",
"tests/integration/{}-test.js",
}
},
["app/components/*.hbs"] = {
type = "template",
alternate = {
"app/components/{}.ts",
"app/components/{}.js",
"app/components/{}.stories.js",
"tests/integration/{}-test.js",
}
}
Any suggestions? 🙂
Make me a small example project using .projections.json and I'll try to figure out what's going wrong.