stevearc / aerial.nvim

Neovim plugin for a code outline window
MIT License
1.55k stars 76 forks source link

bug: PHP Symbol Outline Not Hierarchical when using LSP #344

Closed taiwbi closed 4 months ago

taiwbi commented 4 months ago

Neovim version (nvim -v)

v0.9.5

Operating system/version

Fedora Linux 39

Output of :AerialInfo

Aerial Info
-----------
Filetype: php
Configured backends:
  lsp (supported) (attached)
  treesitter (supported)
  markdown (not supported) [Filetype is not markdown]
  man (not supported) [Filetype is not man]
Show symbols: all symbols

Describe the bug

I installed intelephense as my LSP server on Neovim, I have treesitter as well for my code highlighting. When aerial uses LSP for outlining the code, I don't see any indentation on symbols outline:

󰌗 MusaSpecialUsersListTable
 __construct
󰆧 get_columns
󰆧 column_default
󰀫 $item
󰀫 $column_name
󰀫 $wpdb
󰆧 get_sortable_columns
󰆧 prepare_items
󰀫 $wpdb
󰀫 $per_page
󰀫 $current_page
󰀫 $total_items
󰀫 $columns
󰀫 $hidden
󰀫 $sortable
󰀫 $order
󰀫 $orderby

However it's fine if I prioritize treesitter over lsp, it works fine. I don't want to do that because treesitter only shows functions and classes :(

󰌗 MusaSpecialUsersListTable
├ 󰆧 __construct
├ 󰆧 get_columns
├ 󰆧 column_default
├ 󰆧 get_sortable_columns
├ 󰆧 prepare_items
├ 󰆧 column_cb
├ 󰆧 column_user
├ 󰆧 get_bulk_actions
├ 󰆧 handle_row_actions
└ 󰆧 single_row
󰊕 musa_users_page
󰊕 musa_get_wp_users_callback
󰊕 musa_add_special_user_callback
󰊕 musa_users_inline_edit_callback

I though it might be LSP problem but intelephense works fine on other editors.

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

I use AstroNvim for my base setup so...

  1. Install AstroNvim
  2. Install intelephense LSP server, this is my custom config for intelephese:
      intelephense = function(opts)
        opts.root_dir = function() return vim.loop.cwd() end
        local key = io.open(os.getenv "HOME" .. "/intelephense/license", "rb")
        if not key then return opts end
        opts.init_options = { licenceKey = key:read "*all" }
        key:close()
        return opts
      end,
  3. Open a PHP file
  4. Open the aerial outline window or use the top heirline to see the position in code

Expected Behavior

It would be great if aerial shows the hierarchical of the symbols, like this:

󰌗 MusaSpecialUsersListTable
├  __construct
├ 󰆧 get_columns
├ 󰆧 column_default
│ ├ 󰀫 $item
│ ├ 󰀫 $column_name
│ └ 󰀫 $wpdb
├ 󰆧 get_sortable_columns
└  󰆧 prepare_items
  ├ 󰀫 $wpdb
  ├ 󰀫 $per_page
  ├ 󰀫 $current_page
  ├ 󰀫 $total_items
  ├ 󰀫 $columns
  ├ 󰀫 $hidden
  ├ 󰀫 $sortable
  ├ 󰀫 $order
  └ 󰀫 $orderby

Minimal example file

No response

Minimal init.lua

No response

Additional context

No response

stevearc commented 4 months ago

I am very skeptical that the LSP is returning items in a hierarchy, when LSP servers do that we display the symbols in a hierarchy.

First, double check that your LSP server is up-to-date, then run :LspInfo to confirm that only intelephense is attached to your buffer. Then, run the following code (preferably on a small sample file):

local bufnr = vim.api.nvim_get_current_buf()
local params = { textDocument = vim.lsp.util.make_text_document_params(bufnr) }
local client = vim.lsp.get_active_clients({ bufnr = bufnr })[1]
client.request("textDocument/documentSymbol", params, function(err, result, ctx, config)
    vim.print(result)
end, bufnr)

This should print some output (which you can see with :messages), which will allow us to see the raw data that the server is actually giving us.

taiwbi commented 4 months ago

I'm not really familiar with how LSP works but based on this output I think LSP is fine...

This is the code I tested it on with the aerial outline near:

Screenshot from 2024-02-21 13-07-42

And this is the output of the code:

{ {
    kind = 5,
    location = {
      range = {
        ["end"] = {
          character = 1,
          line = 30
        },
        start = {
          character = 6,
          line = 2
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "Calculator"
  }, {
    containerName = "Calculator",
    kind = 7,
    location = {
      range = {
        ["end"] = {
          character = 16,
          line = 5
        },
        start = {
          character = 9,
          line = 5
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "$result"
  }, {
    containerName = "Calculator",
    kind = 9,
    location = {
      range = {
        ["end"] = {
          character = 3,
          line = 11
        },
        start = {
          character = 18,
          line = 8
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "__construct"
  }, {
    containerName = "Calculator",
    kind = 6,
    location = {
      range = {
        ["end"] = {
          character = 3,
          line = 17
        },
        start = {
          character = 18,
          line = 14
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "add"
  }, {
    containerName = "add",
    kind = 13,
    location = {
      range = {
        ["end"] = {
          character = 26,
          line = 14
        },
        start = {
          character = 22,
          line = 14
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "$num"
  }, {
    containerName = "Calculator",
    kind = 6,
    location = {
      range = {
        ["end"] = {
          character = 3,
          line = 23
        },
        start = {
          character = 18,
          line = 20
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "subtract"
  }, {
    containerName = "subtract",
    kind = 13,
    location = {
      range = {
        ["end"] = {
          character = 31,
          line = 20
        },
        start = {
          character = 27,
          line = 20
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "$num"
  }, {
    containerName = "Calculator",
    kind = 6,
    location = {
      range = {
        ["end"] = {
          character = 3,
          line = 29
        },
        start = {
          character = 18,
          line = 26
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "getResult"
  }, {
    kind = 13,
    location = {
      range = {
        ["end"] = {
          character = 5,
          line = 33
        },
        start = {
          character = 0,
          line = 33
        }
      },
      uri = "file:///home/mahdi/Documents/aerial/main.php"
    },
    name = "$calc"
  } }
stevearc commented 4 months ago

This is using the deprecated SymbolInformation structure for the symbols, which cannot provide a hierarchy. From the spec:

SymbolInformation[] which is a flat list of all symbols found in a given text document. Then neither the symbol’s location range nor the symbol’s container name should be used to infer a hierarchy.

Allegedly Intelephense migrated off of that to DocumentSymbol in 2019 (source). You could try filing an issue with Intelephense asking if they could update their document symbol provider, but there's nothing aerial can do about this.

taiwbi commented 4 months ago

Oh, I thought the containerName in every single block is the parent of that symbol.

Anyway thank you so much for your response and the time you spent on this issue, I appreciate it so much.