Code Monkey home page Code Monkey logo

Comments (10)

kaka-ruto avatar kaka-ruto commented on May 29, 2024 1

Yes, you would do it this way

{
      pattern = 'src/some/(.*)/(.*).ext',
      target = 'test/a/%1/%2.spec.ext',
    },

from other.nvim.

rgroli avatar rgroli commented on May 29, 2024 1

Hi,

to be seable to sarch in subdirectories in the target you must use the recursive glob thing "**".
So basically this should work:

    {
	    pattern = "src/.*/(.*).ext",
	    target = "test/**/%1.spec.ext",
    },

and also the other way...

    {
	    pattern = "test/.*/(.*).spec.ext",
	    target = "src/**/%1.ext",
    },

Hope that helps 😄

from other.nvim.

rgroli avatar rgroli commented on May 29, 2024

exactly 😄 Closing this for now..

from other.nvim.

weilbith avatar weilbith commented on May 29, 2024

Hey 👋🏾
Thanks for the reply. 🙏🏾
But wouldn't that now match the first matching group of the pattern in the target too? Because that's what I have and it is not working. I would like to loosen the pattern and find more potential results. So I can specify fewer and less concrete targets.

Trying to describe this in some points:

  • I define a folder where source files are inside
  • I only care about the file name, the path "in-between" doesn't matter
  • I define a folder where all kind of test files are inside
  • in this folder I try to find a file with a matching name plus some additional stuff

Having the above pattern again:

pattern = 'src/.*/(.*).ext',
target = 'test/.*/%2.spec.ext',

I want these to match:
./src/foo/file.ext -> ./test/what/ever/else/file.spec.ext or ./test/poop/file.spec.ext
./src/bar/baz/file.ext -> ./test/file.ext or ./test/holy/shit/that/is/long/file.spec.ext

Was that better explained? 🙈

from other.nvim.

weilbith avatar weilbith commented on May 29, 2024

Nice. That helped. Thank you very much! 🙏🏾

from other.nvim.

weilbith avatar weilbith commented on May 29, 2024

A final question if I may ask: how can I make it case insensitive? 🙈
E.g. if the source file name would be FooBar.ext to also match fooBar.spec.ext.
A transformer does not do I guess.

from other.nvim.

rgroli avatar rgroli commented on May 29, 2024

Sure, but actually this should just work.. the search is case-insensitive..

from other.nvim.

weilbith avatar weilbith commented on May 29, 2024

But not the matching of the captured group right? Because it definitely doesn't work for me. And I thought that's also the reason for the transformers? 🤔

from other.nvim.

rgroli avatar rgroli commented on May 29, 2024

@weilbith okay, let's narrow this issue down.. 😄

I have the following config:

	mappings = {
		{
			pattern = "src/.*/(.*).ext",
			target = "test/**/%1.spec.ext",
		},
		{
			pattern = "test/.*/(.*).spec.ext",
			target = "src/**/%1.ext",
		},
	},

With this I am able to switch back and forth for the following files:

/fixtures/uppercase-lowercase/src/foo/file.ext  
/fixtures/uppercase-lowercase/test/what/ever/else/file.spec.ext

and also

/fixtures/uppercase-lowercase/src/foo/FooBar.ext
/fixtures/uppercase-lowercase/test/what/ever/else/fooBar.spec.ext

does this work for you?

The transformers are used to transform a captured group before it is used in the target (which is then searched with glob). Although the repo example shows the lowercase transformer, it's just to demonstrate an easy use case. I never needed to use this in real life. They are generally used to transform between camel to kebap or removing some suffixes or prefixes.

I am on a mac, where you don't need to care about case sensitivity in filepaths by default. Maybe that could be the problem? What system are you using?

from other.nvim.

weilbith avatar weilbith commented on May 29, 2024

Hey 👋🏾
Sorry, I was on vacation without my laptop and thereby couldn't try it out.
Now I did. Thanks for your exact example. I literally created exactly the folders and files you have described and also the exact mappings. And yes, this still doesn't work for me for the second case.

I am on a mac, where you don't need to care about case sensitivity in filepaths by default. Maybe that could be the problem? What system are you using?

Very interesting. I didn't know about that. I'm working with Linux. So that could be it. But I see you added a testcase for this. I guess your CI is not running with MacOS, right?

from other.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.