piersolenski / telescope-import.nvim

Import modules with ease
186 stars 8 forks source link

Error with fish shell #17

Closed bujesse closed 8 months ago

bujesse commented 9 months ago

Fish shell considers $ inside double-quotes as a special character and thus needs to be escaped.

It produces this error:

image

There are 2 ways to fix this; either detect the current shell and apply an escaped version if fish, or allow users to override the default language settings.

I tried to do the second approach, but looking at the code, I think only the first matching filetype config gets returned; and the default built-in ones come first: https://github.com/piersolenski/telescope-import.nvim/blob/0270f1438c0ac91663146a73a213bfdc536a8cb5/lua/import/utils.lua#L52 https://github.com/piersolenski/telescope-import.nvim/blob/0270f1438c0ac91663146a73a213bfdc536a8cb5/lua/import/picker.lua#L12

I have this fixed locally by just prepending a backslash directly in the plugin code, but just wanted to raise this if others encounter this issue.

piersolenski commented 9 months ago

Hmm good catch 🎣!

What do you think about custom languages overwriting the defaults rather than extending them as a solution?

bujesse commented 9 months ago

I think all you have to do is change the order of the table merge so that user configs for a given language would take priority over the plug-in configuration.

And then maybe add something to the readme explaining this in case another fish user comes along.

I could create a PR if you like.

piersolenski commented 9 months ago

That'd be great, cheers!

collindutter commented 8 months ago

Wow what good timing, I just tried out the plugin and needed Fish support! For those coming later, here is an example config for making it work with Python:

      telescope.setup {
        extensions = {
          import = {
            insert_at_top = true,
            custom_languages = {
              {
                regex = [[(?m)^(?:from[ ]+(\S+)[ ]+)?import[ ]+(\S+)[ ]*\$]], -- Note the escaped $
                filetypes = { 'python' },
                extensions = { 'py' },
              },
            },
          },
        },
      }

Thanks for the awesome plugin @piersolenski, and thanks for the timely PR @bujesse!