Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect symbol range from documentSymbol #2898

Open
stevearc opened this issue May 8, 2022 · 5 comments
Open

Incorrect symbol range from documentSymbol #2898

stevearc opened this issue May 8, 2022 · 5 comments
Labels
component: ghcide level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@stevearc
Copy link

stevearc commented May 8, 2022

Your environment

Which OS do you use: Ubuntu, though this has also been seen on MacOS

Which LSP client (editor/plugin) do you use: Neovim builtin

Describe your project (alternative: link to the project): Repros in minimal project, detailed below

Steps to reproduce

  • cabal init to create a new project
  • Open the Main.hs file
  • Send a textDocument/documentSymbol request

Main.hs:

module Main where

main :: IO ()
main = putStrLn "Hello, Haskell!"

Expected behaviour

Data returned should match the file

Actual behaviour

{ {
    children = { {
        kind = 12,
        name = "main",
        range = {
          end = {
            character = 33,
            line = 3
          },
          start = {
            character = 0,
            line = 3
          }
        },
        selectionRange = {
          end = {
            character = 33,
            line = 3
          },
          start = {
            character = 0,
            line = 3
          }
        }
      } },
    kind = 1,
    name = "Main",
    range = {
      end = {
        character = 0,
        line = 2147483647
      },
      start = {
        character = 0,
        line = 0
      }
    },
    selectionRange = {
      end = {
        character = 11,
        line = 0
      },
      start = {
        character = 7,
        line = 0
      }
    }
  } }

The line = 2147483647 is the problem. It was causing issues with a plugin I wrote because I wasn't being defensive when processing the line numbers.
stevearc/aerial.nvim#101

Include debug information

@stevearc stevearc added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels May 8, 2022
@michaelpj
Copy link
Collaborator

I don't really know why we do this instead of giving the right end position, but here's the culprit: https://github.com/haskell/haskell-language-server/blob/master/ghcide/src/Development/IDE/LSP/Outline.hs#L52

@michaelpj
Copy link
Collaborator

A priori it doesn't seem like it should be too hard to just give an accurate end to the module. Good first issue, perhaps. At least if it's hard we could find out why and document it.

@michaelpj michaelpj added the level: easy The issue is suited for beginners label May 8, 2022
@coltenwebb
Copy link
Contributor

I'll try taking a look at this- it seems like range should be equal to selectionRange, at least for this example. I'll see if something breaks when doing this

@coltenwebb
Copy link
Contributor

So the reason selectionRange != range is that all the children of a given DocumentSymbol need to be sub-spans of the parent's range for editor tools like document outline to work. So range really does need to span the whole file.

Getting an accurate end to the module isn't straightforward. GHC doesn't give a span for the whole module with ParsedModule. It's returning an empty source string from ModSummary for some reason too, so I'm unable to count the lines that way.

Loading the file directly and counting the lines seems unnecessarily slow/hacky. Maybe someone can chime in on whether they know of ways this is done elsewhere in the codebase?

@michaelpj
Copy link
Collaborator

Can we make an upstream GHC issue about the module source span? That seems like something which we might reasonably expect GHC to do.

Possible dirty hack: the end position of the module is the maximum over the end positions of all the module's child elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide level: easy The issue is suited for beginners type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

4 participants