simrat39 / symbols-outline.nvim

A tree like view for symbols in Neovim using the Language Server Protocol. Supports all your favourite languages.
MIT License
1.85k stars 101 forks source link

Question: what's the best way to auto-open when buffer is opened? #188

Open Integralist opened 2 years ago

Integralist commented 2 years ago

👋🏻

I'm trying to figure out the best way to trigger SymbolsOutlineOpen so that we automatically open the symbols sidebar whenever a buffer is opened or entered.

I'm trying something like the following within an lsp on_attach but it's not working:

  vim.api.nvim_create_autocmd({ "BufEnter" }, {
    group = vim.api.nvim_create_augroup("SharedLspSymbolsSidebar", { clear = true }),
    pattern = "*",
    callback = function()
      require("symbols-outline").open_outline()
    end
  })
gennaro-tedesco commented 2 years ago

I'm trying something like the following within an lsp on_attach but it's not working:

Are you defining such autocommand within the attach? If so, then the autocommand is defined only when LSP is attached, thereby not executed at attach. It should however work if you define it generally (why exactly are you defining it on attach by the way?).

Integralist commented 2 years ago

why exactly are you defining it on attach by the way?

So my thinking was that this plugin was only useful when I have an LSP server running on a file, otherwise nothing would happen.

Since seeing your suggestion I tried running :lua require("symbols-outline").open_outline() on an empty buffer and it didn't complain or error, so I guess it wouldn't matter too much if it's a more general autocommand.

UPDATE: I tried your suggestion and it didn't work for the first file I opened (as the LSP server hadn't started up by the time the 'BufEnter' was first triggered), but it did for the second file I opened (as the LSP server was started). The problem was that when the sidebar opened, the autocommand tried to execute open_outline inside the sidebar which caused an error.