OlegGulevskyy / better-ts-errors.nvim

MIT License
117 stars 7 forks source link

feat: add filetype to popup buffer #16

Closed RayGuo-ergou closed 4 months ago

RayGuo-ergou commented 4 months ago

📃 Summary

Add filetype option to popup buffer so can do things like press q to quit.

The previous PR pointed the wrong branch, sorry!

📸 Preview

OlegGulevskyy commented 4 months ago

Hey there, Thanks for your PR, much appreciated! I am not sure though how does this work? I tried your changes and it does not close on q for me. Moreover, in the documentation of nui.popup options, buf_options contain this:

buf_options = {
  modifiable = false,
  readonly = true,
},

I don't see much mentioning of filetype. I don't its API so maybe I am missing something, but might you give more context about this?

RayGuo-ergou commented 4 months ago

Hi sorry for the unclear description.

The document for buf_options here: https://github.com/MunifTanjim/nui.nvim/blob/322978c734866996274467de084a95e4f9b5e0b1/lua/nui/tree/README.md?plain=1#L112-L128

so it includes all options can be fine in :h options.

I am not sure though how does this work? I tried your changes and it does not close on q for me

Set the file type would help to create autocmd for the popup. e.g. the autocmd to close with q

vim.api.nvim_create_autocmd('FileType', {
  group = augroup('close_with_q'),
  pattern = {
  'typescript-errors',
  ...otherFileTypes,
  },
  callback = function(event)
    vim.bo[event.buf].buflisted = false
    vim.keymap.set('n', 'q', '<cmd>close<cr>', { buffer = event.buf, silent = true })
  end,
})
OlegGulevskyy commented 4 months ago

ah, I see! thanks for explanation it would probably make sense allowing user pass their own file type, but it is a great start I think!

thanks for the PR, much appreciated!