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

Fixed: Error while calculating block spans #687

Merged
merged 5 commits into from
Apr 11, 2024
Merged

Conversation

scohen
Copy link
Collaborator

@scohen scohen commented Apr 5, 2024

While trying to enhance the indexing of protocol modules, I found a fairly serious bug with alias / import detection. When we'd encounter a block of code (usually starting with do), we used soureror's detection of start and end. The problem is that it starts that block before the do, so for example, defmodule MyModule do.. would start at the defmodule call.

This meant that the module we were defining starts at the defmodule call, so our current module detection would be off by almost an entire line. This caused errors when builidng module names for protocols and when people would do defmodule __MODULE__.Child do.

We were also making nonsensical module names like Elixir.__MODULE__ when we called current_module despite the fact that not all code is inside a module.

Now, module detection is character accurate and can fail, and some code had to have error detection added. For future reference, all calls to current_module(analysis, position) can now fail, so doing a hard pattern match on {:ok, module} will fail in contexts outside of a module.

@scohen scohen force-pushed the improved-scope-detection branch 2 times, most recently from b7cd931 to 9f67680 Compare April 8, 2024 23:50
@scohen scohen requested a review from Moosieus April 9, 2024 15:18
@scohen scohen changed the title Fixed: Error while calculating alias spans Fixed: Error while calculating block spans Apr 9, 2024
@scohen scohen force-pushed the improved-scope-detection branch from 8a266c1 to 460cad6 Compare April 9, 2024 15:51
scohen added 5 commits April 11, 2024 08:05
While trying to enhance the indexing of protocol modules, I found a
fairly serious bug with alias / import detection. When we'd encounter
a block of code (usually starting with do), we used soureror's
detection of start and end. The problem is that it starts that block
before the do, so for example, `defmodule MyModule do..` would start
at the `defmodule` call.

This meant that the module we were defining starts at the defmodule
call, so our current module detection would be off by almost an entire
line. This caused errors when builidng module names for protocols and
when people would do `defmodule __MODULE__.Child do`.

We were also making nonsensical module names like `Elixir.__MODULE__`
when we called `current_module` despite the fact that not all code is
inside a module.

Now, module detection is character accurate and can fail, and some
code had to have error detection added. For future reference, all
calls to `current_module(analysis, position)` can now fail, so doing a
hard pattern match on `{:ok, module}` will fail in contexts outside of
a module.
I was not correctly handling protocol module expansion in several
cases, namely in protocol implementations nested in a parent module.
Also fixed resolution of the current module inside the protocol, and
removed the expicit alias, which doesn't seem to exist in protocols.
@scohen scohen force-pushed the improved-scope-detection branch from dfcefa1 to 0e37d5a Compare April 11, 2024 15:07
@scohen scohen merged commit e16fc52 into main Apr 11, 2024
9 checks passed
@scohen scohen deleted the improved-scope-detection branch April 11, 2024 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants