Skip to content

Sometimes textDocument/documentSymbol reports function nestedness incorrectly #606

Description

@snezhniylis

For the following example

local root = {
  inner_function = function ()
    -- local any_variable = 1
    local function function_inside_function()
    end
  end
}

the server incorrectly identifies function_inside_function as inner_function's neighbor:

{
  {
    name = "root",
    detail = "local {inner_function}",
    kind = 13,
    range = { end = { character = 1, line = 6 }, start = { character = 6, line = 0 } },
    selectionRange = { end = { character = 10, line = 0 }, start = { character = 6, line = 0 } },
    children = {
      {
        name = "inner_function",
        detail = "function ()",
        kind = 12,
        range = { end = { character = 5, line = 5 }, start = { character = 2, line = 1 } },
        selectionRange = { end = { character = 16, line = 1 }, start = { character = 2, line = 1 } }
      },
      {
        name = "function_inside_function",
        detail = "function ()",
        kind = 12,
        range = { end = { character = 7, line = 4 }, start = { character = 10, line = 3 } },
        selectionRange = { end = { character = 43, line = 3 }, start = { character = 19, line = 3 } }
      }
    }
  }
}

But if you will uncomment any_variable, function_inside_function will be correctly identified as an inner_function's child:

{
  {
    name = "root",
    detail = "local {inner_function}",
    kind = 13,
    range = { end = { character = 1, line = 6 }, start = { character = 6, line = 0 } },
    selectionRange = { end = { character = 10, line = 0 }, start = { character = 6, line = 0 } },
    children = {
      {
        name = "inner_function",
        detail = "function ()",
        kind = 12,
        range = { end = { character = 5, line = 5 }, start = { character = 2, line = 1 } },
        selectionRange = { end = { character = 16, line = 1 }, start = { character = 2, line = 1 } },
        children = {
          {
            name = "any_variable",
            detail = "local number = 1",
            kind = 13,
            range = { end = { character = 26, line = 2 }, start = { character = 10, line = 2 } },
            selectionRange = { end = { character = 22, line = 2 }, start = { character = 10, line = 2 } }
          },
          {
            name = "function_inside_function",
            detail = "function ()",
            kind = 12,
            range = { end = { character = 7, line = 4 }, start = { character = 10, line = 3 } },
            selectionRange = { end = { character = 43, line = 3 }, start = { character = 19, line = 3 } }
          }
        }
      }
    }
  }
}

Environment:

  • OS: Arch Linux
  • Client: Neovim (built-in LSP client)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions