LanguageServer.jl icon indicating copy to clipboard operation
LanguageServer.jl copied to clipboard

Use loose_refs in for_each_ref

Open pfitzseb opened this issue 2 years ago • 2 comments

This is generally closer to what people expect when talking about references. Before: image

After: image

pfitzseb avatar Jun 17 '22 13:06 pfitzseb

Is the idea that we no longer follow scoping rules? I always assume that this command gives me the same list I would get from the rename refactoring, which presumably follows scoping rules? So not sure I’m a fan of this change :) Do we have evidence that the current implementation is confusing a lot of users?

davidanthoff avatar Jun 20 '22 10:06 davidanthoff

This change also affects refactoring.

The issue with the current implementation is that we don't correctly follow Julia's scoping rules. You'd end up going from

function ff()
    x = 0
    while true
        y = sin(x)
        x = y
        while true
            y = sin(x)
            x = y
        end
        x = 2y
    end
end

to e.g.

function ff()
    x = 0
    while true
        yyy = sin(x)
        x = yyy
        while true
            y = sin(x)
            x = y
        end
        x = 2y
    end
end

which changes the meaning of the code -- the inner loop doesn't update the outer loop's y (now yyy) after all. With this change you'd get

function ff()
    x = 0
    while true
        yyy = sin(x)
        x = yyy
        while true
            yyy = sin(x)
            x = yyy
        end
        x = 2yyy
    end
end

instead. Basically, the difference between .refs and loose_refs is that the latter is more correct for soft scopes.

pfitzseb avatar Jun 20 '22 10:06 pfitzseb