p00f / clangd_extensions.nvim

Clangd's off-spec features for neovim's LSP client. Use https://sr.ht/~p00f/clangd_extensions.nvim instead
MIT License
485 stars 18 forks source link

feat(type_hierarchy): add localization func #39

Closed hongxuchen closed 1 year ago

hongxuchen commented 1 year ago

This commit adds the localization functionality for the items of ClangdTypeHierarchy created buffer. Major changes:

An implementation for https://github.com/p00f/clangd_extensions.nvim/issues/36

p00f commented 1 year ago

Thanks a lot for your work on this, the implementation is otherwise nice

p00f commented 1 year ago

I pushed to your branch, I hope you don't mind

hongxuchen commented 1 year ago

I pushed to your branch, I hope you don't mind

That's all right to me.

But to be honest, I prefer to keep vim.bo.bufhidden = "hide" for the created buffer for reuse purpose. When vim.bo.bufhidden = "wipe", the buffer will no longer be available whenever jumped to other buffers; and if we'd like to see another parent/child type, we have to invoke ClangdTypeHierarchy once more, which is somewhat annoying. Is it possible to provide a setup option for this?

p00f commented 1 year ago

we have to invoke ClangdTypeHierarchy once more,

You can bind it to a key if you use it frequently (maybe in on_attach so it only works in clangd-attached buffers)

p00f commented 1 year ago

If you want to keep the buffer then you need to use another window for the gd buffer (making it three windows) because we change the window options for the type hierarchy window

hongxuchen commented 1 year ago

we have to invoke ClangdTypeHierarchy once more,

You can bind it to a key if you use it frequently (maybe in on_attach so it only works in clangd-attached buffers)

I have a keymap for ClangdTypeHierarchy. But I think this is still a bit inconvenient with.

hongxuchen commented 1 year ago

If you want to keep the buffer then you need to use another window for the gd buffer (making it three windows) because we change the window options for the type hierarchy window

Oh, I realized that window options were not correctly restored in my commit.

p00f commented 1 year ago

Hmm ok, but what about the multiple windows problem?

What if we reuse the source code window from which :ClangdTypeHierarchy was invoked?

I installed vscode to see what they do, they keep the type hierarchy window open and open another "tab" (like vim buffers) so I guess doing the above is fine?

p00f commented 1 year ago

This way we can keep bufhidden=wipe because the type hierarchy window stays

Can you try the latest commit I pushed?

hongxuchen commented 1 year ago

This way we can keep bufhidden=wipe because the type hierarchy window stays

Can you try the latest commit I pushed?

Yes, your solution is elegant!

p00f commented 1 year ago

Ok, I'll squash and merge. Thanks for your contribution!

p00f commented 1 year ago

Manually rebased main on top of this branch

hongxuchen commented 1 year ago

One more thing I'm not quite sure, do we need to clean up _G.type_pos_mappings? If many different ClangdTypeHierarchy buffers have been opened, whether or not they are wiped out, this may cause memory bloat. This is an extreme case though.

Previously I was trying buffer-local variables, but it was not updated when passed as a function parameter.

p00f commented 1 year ago

I did this: https://git.sr.ht/~p00f/clangd_extensions.nvim/commit/6f16294efc16f09635ef8241d0699d2b9c0ee35b

hongxuchen commented 1 year ago

I did this: https://git.sr.ht/~p00f/clangd_extensions.nvim/commit/6f16294efc16f09635ef8241d0699d2b9c0ee35b

Great!

p00f commented 1 year ago

Can you also add a demo to the readme?

hongxuchen commented 1 year ago

Can you also add a demo to the readme?

I'd like to but I think it may not be a good choice since I use different colorscheme and font from yours, which may bring surprise. BTW, I guess llvm-project may be used for demo since there are many complicated inheritances.

p00f commented 1 year ago

https://github.com/p00f/clangd_extensions.nvim/assets/36493671/5598f8f1-04c1-43ec-b7fe-396ff5cab327

hongxuchen commented 1 year ago

https://github.com/p00f/clangd_extensions.nvim/assets/36493671/5598f8f1-04c1-43ec-b7fe-396ff5cab327

Fantastic!

hongxuchen commented 3 weeks ago

@p00f I noticed that there is an issue with current implementation: when the original window is closed (Ctrl-W_c for example), and the navigation from inside type hierarchy window with gd will report an invalid window id error like below:

E5108: Error executing lua: ...extensions.nvim/lua/clangd_extensions/type_hierarchy.lua:109: Invalid window id: 1365
stack traceback:
        [C]: in function 'nvim_set_current_win'
        ...extensions.nvim/lua/clangd_extensions/type_hierarchy.lua:109: in function <...extensions.nvim/lua/clangd_extensions/type_hierarchy.lua:104>
hongxuchen commented 3 weeks ago

Another issue is that it will report Buffer is not 'modifiable' when we repeatedly :ClangdTypeHierarchy on a Class/Struct (since the corresponding type hierarchy buffer is set unmodifiable).