Skip to content

Help message about variable's type is broken when source file has unsaved edits #32

@dszoboszlay

Description

@dszoboszlay

Describe the bug

Hovering over a variable shows type information about the variable. However, if the source file has unsaved edits that moved the variable's declaration around, the help message is rendered incorrectly.

To Reproduce**

Write a module with this function in it and save it:

test(<<X:32>>) ->
  X + 1.

Hovering over X in the X = 1 expression displays the tooltip X :: number().

Now insert a space in the previous line before X, but do not save the document:

test(<< X:32>>) ->
  X + 1.

Hovering over X in the X = 1 expression now gives the tooltip :: number().

Expected behavior

Unsaved edits that only move the declaration around shouldn't impact the help message.

Actual behavior

It looks like the variable's name is taken from the same position where it was declared in the saved file, even though it may now be moved around. E.g. adding some space before a variable with a long name will chop off characters from the end of its name, and deleting white space from before the variable will chop off characters from the beginning of its name.

Interestingly, renaming the variable would display the type help with the correct variable name, and no compilation errors are reported until the file is saved. For example with this unsaved edit:

test(<<Y:32>>) ->
  X + 1.

Context

  • ELP Version (output of elp version): elp 1.1.0+build-2024-04-29
  • Editor used: VS Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingprio-mid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions