Code Monkey home page Code Monkey logo

Comments (9)

rgroli avatar rgroli commented on May 31, 2024 1

I will update the documentation about this. The characters which need to be escaped are:

( ) . % + - * ? [ ^ $

at least as far as I can tell according to this: https://www.lua.org/pil/20.2.html

When you're also using a capturing-group for the path part (like mentioned above) maybe you could get rid of escaping all together.

from other.nvim.

rgroli avatar rgroli commented on May 31, 2024 1

the string you're matching against already contains the escaping. Shouldn't it be?

vim.pretty_print( 
    ( 
      '/Users/ahmed/Some/deeply/nested/folder/structure/here/foo/bar/v10/some-folder/file.ts'
    ):match '/foo/bar/v10/some%-folder/(.*).ts$'
)

from other.nvim.

rgroli avatar rgroli commented on May 31, 2024 1

Ahh I see πŸ˜„
okay!strange enough it works nevertheless in my testcase. Anyway I updated the comment, thanks!

from other.nvim.

rgroli avatar rgroli commented on May 31, 2024

You're doing it right!

the thing is that in your case there is a "-" in the path. In lua you need to escape this with "%". So the working pattern would be:

require('other-nvim').setup {
  mappings = {
    {
      pattern = '/foo/bar/v10/some%-folder/(.*).ts$',
      target = '/foo/bar/v10/tests/some-folder/%1.test.ts',
    },
    {
      pattern = '/foo/bar/v10/tests/some%-folder/(.*).test.ts$',
      target = '/foo/bar/v10/some-folder/%1.ts',
    },
  },
}

I will update the documentation about this. Thank you for the hint!

Another thing you could do to optimize your pattern is making the "some-folder"-part dynamic too. Like that:

require('other-nvim').setup {
  mappings = {
    {
      pattern = '/foo/bar/v10/(.*)/(.*).ts$',
      target = '/foo/bar/v10/tests/%1/%2.test.ts',
    },
    {
      pattern = '/foo/bar/v10/tests/(.*)/(.*).test.ts$',
      target = '/foo/bar/v10/%1/%2.ts',
    },
  },
}

I haven't tested that - but it should work

from other.nvim.

ahmedelgabri avatar ahmedelgabri commented on May 31, 2024

the thing is that in your case there is a "-" in the path. In lua you need to escape this with "%"

I was sure it was something silly like this… πŸ˜„ thanks! do you have a list of characters that need to be escaped in lua? Or maybe a resource about this?

Because in my case the absolute URL contains a lot of folders with - so I assume I need to escape all of them? because it's still not working for me.

Maybe this should be baked in the plugin?

from other.nvim.

ahmedelgabri avatar ahmedelgabri commented on May 31, 2024

Not sure what I'm doing wrong but this still returns nil

vim.pretty_print(
  (
    '/Users/ahmed/Some/deeply/nested/folder/structure/here/foo/bar/v10/some%-folder/file.ts'
  ):match '/foo/bar/v10/some%-folder/(.*).ts$'
)

from other.nvim.

ahmedelgabri avatar ahmedelgabri commented on May 31, 2024

Thanks, it works now πŸ‘πŸΌ

I think your example here needs to be fixed, because I followed that one #4 (comment)

from other.nvim.

rgroli avatar rgroli commented on May 31, 2024

Great that it works now!

but honestly I don't know how to fix the example above. I just tried that with a directory structure that mimiks yours and it just works.

require('other-nvim').setup {
  mappings = {
    {
      pattern = '/foo/bar/v10/some%-folder/(.*).ts$',
      target = '/foo/bar/v10/tests/some%-folder/%1.test.ts',
    },
    {
      pattern = '/foo/bar/v10/tests/some%-folder/(.*).test.ts$',
      target = '/foo/bar/v10/some%-folder/%1.ts',
    },
  },
}

from other.nvim.

ahmedelgabri avatar ahmedelgabri commented on May 31, 2024

This is the only change needed, you escaped the - inside target while this is only needed inside pattern

require('other-nvim').setup {
  mappings = {
    {
      pattern = '/foo/bar/v10/some%-folder/(.*).ts$',
-      target = '/foo/bar/v10/tests/some%-folder/%1.test.ts',
+      target = '/foo/bar/v10/tests/some-folder/%1.test.ts',
    },
    {
      pattern = '/foo/bar/v10/tests/some%-folder/(.*).test.ts$',
-      target = '/foo/bar/v10/some%-folder/%1.ts',
+      target = '/foo/bar/v10/some-folder/%1.ts',
    },
  },
}

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.