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

bug: lazy load by ft will run function twice #228

Closed
3 tasks done
glepnir opened this issue Dec 29, 2022 · 9 comments · Fixed by #197
Closed
3 tasks done

bug: lazy load by ft will run function twice #228

glepnir opened this issue Dec 29, 2022 · 9 comments · Fixed by #197
Labels
bug Something isn't working

Comments

@glepnir
Copy link

glepnir commented Dec 29, 2022

Did you check docs and existing issues?

  • I have read all the lazy docs
  • I have searched the existing issues of lazy
  • I have searched the exsiting issues of the plugin I have a problem with

Neovim version (nvim -v)

NVIM v0.9.0-dev-576+g05b6dd6e5-dirty

Operating system/version

Macos 13.0.1

Describe the bug

if the plugin has FileType event and the plugin lazyload by ft , the event callback will run twice.

Steps To Reproduce

  lazy.setup({

    {
      'plugin-name',
      dev = true,
      ft = { 'lua' },
      config = function()
        vim.api.nvim_create_autocmd('FileType',{
          pattern = 'lua',
          callback = function()
            print('hello')
          end
        })
      end,
    },

Expected Behavior

print hello once.

Repro

no need
@glepnir glepnir added the bug Something isn't working label Dec 29, 2022
@folke
Copy link
Owner

folke commented Dec 29, 2022

That is correct. This is needed for some plugins that depend on the FileType event to do something. Like if you want to lazyload vimtex on ft=tex.

@folke folke closed this as completed Dec 29, 2022
@glepnir
Copy link
Author

glepnir commented Dec 29, 2022

  lazy.setup({

    {
      'nvim-lspconfig',
      dev = true,
      ft = { 'lua' },
      config = function()
          sumneko lua config here
        })
      end,
    },
``

open lua file  `FileType` will run twice.  that mean the start client function run twice. 

@folke folke reopened this Dec 29, 2022
@glepnir
Copy link
Author

glepnir commented Dec 29, 2022

although I can add a patch in nvim-lspconfig. but a little wired. what do you think about this behavior?

@folke
Copy link
Owner

folke commented Dec 29, 2022

I didn't read your comment well. it shouldn't fire twice I think. I'm looking into it to see what's causing that

@folke folke closed this as completed in 7de662d Dec 29, 2022
@folke
Copy link
Owner

folke commented Dec 29, 2022

Should be fixed now!

@glepnir
Copy link
Author

glepnir commented Dec 30, 2022

hmm did you test that. the hello not print , open a lua file. it should print hello once.

  lazy.setup({

    {
      'plugin-name',
      dev = true,
      ft = { 'lua' },
      config = function()
        vim.api.nvim_create_autocmd('FileType',{
          pattern = 'lua',
          callback = function()
            print('hello')
          end
        })
      end,
    },

@glepnir
Copy link
Author

glepnir commented Dec 30, 2022

nvm. looks like works fine.

@glepnir
Copy link
Author

glepnir commented Apr 28, 2023

looks like this is broken ? I don't get this work after i upgrade . still use before code snippets . open a lua file hello not printed.

    {
      'plugin-name',
      dev = true,
      ft = { 'lua' },
      config = function()
        vim.api.nvim_create_autocmd('FileType',{
          pattern = 'lua',
          callback = function()
            print('hello')
          end
        })
      end,
    },

@glepnir
Copy link
Author

glepnir commented Apr 28, 2023

Oh autocmd pr of ii14 has been merged .so maybe related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants