Shopify / ruby-lsp

An opinionated language server for Ruby
https://shopify.github.io/ruby-lsp/
MIT License
1.52k stars 144 forks source link

Minitest spec code lenses break when describe contains interpolation #1605

Open Earlopain opened 6 months ago

Earlopain commented 6 months ago

Description

There's a bit more to this but overall this is the gist of it.

describe pushes to the group_id_stack. If a describe can't be handled a code lens will not be created, which in turn means that it inside of that describe block references a group that doesn't exist (that at least is my current understanding of why this happens).

You can reproduce this with the following snippet:

describe Foo do
  describe "string_#{interpolation}" do
    it "does_something"
  end

  it "it_level_one"
end

image The green button is still there for some reason, but the other code lens that would in theory work does not get displayed.

The following should also not break, however I'm not sure how many codelenses it should actually display. One for describe Foo and the bottommost it for sure. Ideally for the describe with a normal string and its testcase as well but the first one might be simpler to implement as a first pass.

describe Foo do
  describe "string_#{interpolation}" do
    it "does_something"

    describe "normal_string" do
      it "does_something_else"
    end
  end

  it "it_level_one"
end
vinistock commented 6 months ago

Thank you for the bug report!

I think we might be able to fix this by using a more elaborate regex when interpolation is present. For example, if we have

describe "something #{var} other thing" do
end

We could push something <dynamic reference> other thing to the stack to ensure we maintain the structure properly. And for running it, we could turn the dynamic references into match all regexes, something like /something .* other thing/, which would I think is enough to match them.

Earlopain commented 6 months ago

Oh, that's a great idea. I will implement this