vim-projectionist icon indicating copy to clipboard operation
vim-projectionist copied to clipboard

Support for multiple file extensions in patterns

Open hauleth opened this issue 7 years ago • 16 comments

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?

hauleth avatar Apr 24 '18 12:04 hauleth

I'm also interested in this use case. Did anyone figured out if it is possible to do that today?

josemarluedke avatar May 07 '18 21:05 josemarluedke

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 avatar May 07 '18 21:05 tpope

@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.

hauleth avatar May 08 '18 00:05 hauleth

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"
  }
}

hovsater avatar Jun 10 '19 19:06 hovsater

Luckily "alternate": ["src/{}.test.js", "src/{}.test.jsx"] handles that case just fine.

tpope avatar Jun 11 '19 05:06 tpope

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?

hovsater avatar Jun 11 '19 05:06 hovsater

Correct, you'll still need a top level src/*.jsx key.

tpope avatar Jun 11 '19 05:06 tpope

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.

hovsater avatar Jun 11 '19 05:06 hovsater

Correct. This is less of a priority because, frankly, it's an obnoxious naming scheme. It'll trip up a lot more than Projectionist.

tpope avatar Jun 11 '19 06:06 tpope

Yeah, I thought so. Appreciate the quick responses. 🙂

hovsater avatar Jun 11 '19 06:06 hovsater

Out of curiosity what more than Projectionist might have problem with that naming scheme? This pattern is especially common in Go (almost exclusively used).

hovsater avatar Jun 11 '19 06:06 hovsater

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.

tpope avatar Jun 13 '19 18:06 tpope

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",
  },

lougreenwood avatar Dec 21 '21 12:12 lougreenwood

Unfortunately the only solution to this is to repeat yourself, with 2 sections.

tpope avatar Dec 21 '21 18:12 tpope

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? 🙂

lougreenwood avatar Dec 21 '21 20:12 lougreenwood

Make me a small example project using .projections.json and I'll try to figure out what's going wrong.

tpope avatar Dec 21 '21 21:12 tpope