Search code examples
ideneovimtreesitter

Is there a way to use the language server to make neovim show the path to the current symbol?


When editing or diffing a large json file, I'd love to see the path to the current node (the symbol under the cursor) like VS Code provides. In fact every good IDE does this, but they don't all have JSON support.

In VS and VS Code, the path to the current symbol is shown at the top of the window:

json document annotated with path to cursor

In a programming language, this display might be "MyNamespace -> MyClass -> constructor()".

Is there a way to make nvim do this with the language server or tree-sitter? I'd like to add it to the status line, or maybe in the ctrl+g display. The point of a language server is to do analysis independent of which language. Can this be done in a language independent way?

(Note: I already know about Vim JsonPath and it works well except being slow on large files. I'm interested in knowing if a language server can let nvim do this for every file type, not treating every language separately and finding a plugin for each.)


Solution

  • I made some research and I see 2 options for now:

    • using this navic plugin, it claims to use lsp server information to get data about current context.

    • tinkering with nvim-treesitter#statusline function check it out