Fixed: Error while calculating block spans #687
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thedefmodule
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 calledcurrent_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.