Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parenths don't auto close in swift files with swift string interpolation #84

Closed
sainttttt opened this issue May 30, 2024 · 5 comments
Closed

Comments

@sainttttt
Copy link

sainttttt commented May 30, 2024

It seems that if there is a string with swift string interpolation, this causes the plugin to break for parenths. The string interpolation syntax of swift is like this:

var name = "Dr. Meow"
var foo = "Your name is \(name)"

Here is a video of it breaking
https://streamable.com/zplv0x

Any help would be appreciated. Thanks!

@sainttttt sainttttt changed the title Parenths don't auto close in swift files with swift Parenths don't auto close in swift files with swift string interpolation May 30, 2024
@altermo
Copy link
Owner

altermo commented May 30, 2024

Fixed (813e1b3)

(Needs swift-treesitter-parser to detect and ignore the contents of the string)

@altermo altermo closed this as completed May 30, 2024
@sainttttt
Copy link
Author

sainttttt commented May 30, 2024

Is there any way to not use swift-treesitter-parser? I have it disabled because it makes my editor lag a lot in insert mode for swift files. The plugin lexima is able to do the autocomplete correctly for these swift files and it doesn't use treesitter, so it must be possible somehow.

@altermo
Copy link
Owner

altermo commented May 30, 2024

No (technically yes but it's a lot of work).

By the way, when you say disabled, do you mean the highlighting part, or is it that you don't have the parser installed? Because ultimate-autopair only needs the parser and doesn't rely on highlighting.
Know what, try using this config for nvim-treesitter and try using it for a while (report back to me if the editor still lags too much):

require'nvim-treesitter.configs'.setup({
    ensure_installed = {'swift'},
    highlight={enable=true, disable={'swift'}},
})

@sainttttt
Copy link
Author

sainttttt commented May 30, 2024

Yeah it's still slow even with the highlighting turned off unfortunately. I have to totally uninstall it for it to become fast again. There's a lag every time I enter into command mode when I have treesitter-swift installed, even with the syntax highlighting off :(

Is there a way maybe to disable multi line autoclose for certain filetypes (Which I think is what is causing this problem)?

So basically just give it the stock autoclose for a file with no syntax but disable multi line matching

Edit: So I checked out this thread alex-pinkus/tree-sitter-swift#240 and figured out that disabling treesitter indent for swift fixed the lag issue, versus disabling the syntax highlight which didn't fix it. It's mostly good now! Leaving this comment in case someone else needs it I guess!

@altermo
Copy link
Owner

altermo commented May 30, 2024

To disable multiline on specific filetype you can:

require('ultimate-autopair').setup{
    multiline=function ()
        return vim.o.filetype~='swift'
    end
}

Another solution to this is to get the highlighting (using :Inspect) and create a condition based on it:

require('ultimate-autopair').setup{
  config_internal_pairs={
    {'(',')',cond=function (fn,o)
      if fn.get_ft()~='swift' then return true end
      return vim.fn.synIDattr(vim.fn.synID(o.row,o.col,1),'name')~='swiftInterpolation'
    end},
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants