Skip to content

'Go To Definition' does not work with partial classes. #53

Closed
MrClyfar opened this Issue Mar 30, 2011 · 14 comments

8 participants

@MrClyfar

If step bindings are declared in a partial class, for example:

StepsGiven.cs:

[Binding]

public partial class Steps {}

StepsWhen.cs

public partial class Steps {}

StepsThen.css

public partial class Steps {}

The 'Go To Definition' feature is unable to locate step bindings which are in StepsWhen.cs or StepsThen.cs.

@object
object commented Apr 28, 2011

I performed some tests on this, and it looks like "Go To Definition" only works when a partial class definition has "Binding" attribute. With partial classes attributes can only be assigned once - this assignment will be shared with all other partial definitions. But SpecFlow detects only the one with this attribute and ignores others (which is of course a bug).

@ghost
ghost commented Jun 21, 2011

I have a very similar problem to this, that might (and might not) be related to this bug: "Go to definition" doesn't work for external steps (defined in other assemblies than the feature file) either. It doesn't matter if I use a regex or regular string match. If I move the step class files to the same assembly, it works.

@ghost
ghost commented Oct 1, 2011

@lycken

Have you added the external assemblies to your SpecFlow configuration file as mentioned in the documentation? Check out the "Default Configuration" section. Apparently, you have to add a <stepAssemblies> tag in which you list all your assemblies.

SpecFlow Configuration Documentation

After going through the code real quick it seems like it first looks for the method in the current assembly and after that goes through each assembly defined in the configuration file.

Try adding them to your configuration file and report your findings :)

@Haemoglobin

We also have this issue (the "go to definition" not working when steps defined in partial classes) - is this planned to be fixed?

Thanks

@ghost Unknown added a commit that referenced this issue Oct 5, 2011
raytheon Add support for "Go To Definition" in partial classes (Issue #53)
Currently SpecFlow only supports the "Go To Definition" for full(?) classes (non-partial classes) because it only looks at classes which are marked with the [Binding] attribute. This change extends the search to partial classes by first finding all classes marked with [Binding] then checking to see whether any of these are partial classes. If so, those partial classes are assumed to be binding classes and are scanned as well.
fdc1030
@ghost
ghost commented Oct 5, 2011

Here's something that might work. The last commit adds support for partial classes. It basically works like this:

  1. Get all classes marked with the [Binding] attribute
  2. Of these classes, get all partial classes
  3. Merge the two sets
  4. Scan the combined set of classes for the steps

The original example given by MrClyfar seems to work fine so far.

Looking forward to hearing your comments :)

@Haemoglobin

Thanks raytheon, hopefully your change gets pulled in!

@gasparnagy
Collaborator

cool, thx. merged now. will be included in 1.8

@gasparnagy gasparnagy closed this Oct 17, 2011
@GulinSS
GulinSS commented Jan 23, 2013

not works in 1.9.1

1
2

@Elufimov

Do you try [Given(@"нажавший на строку "(.*)"")] ? =)
And where is [Binding]? Do you define it in another part of the partial class?

@GulinSS
GulinSS commented Jan 23, 2013

I tried, but no luck.
Yes, I defined it in another part of the partial.

@GulinSS
GulinSS commented Jan 23, 2013
[Binding]
public partial class UnknownSteps
{
  // lalala more more russian-english code :-)
}
@gasparnagy gasparnagy reopened this Mar 8, 2013
@gasparnagy
Collaborator

fixed the regression issue. 1.9.2 will contain the fix

@gasparnagy gasparnagy closed this Mar 13, 2013
@rafaelromao

I'm having this issue, using VS2013 and SpecFlow IDE Integration 1.9.3.1. I'm using 4 partial classes and applied [Binding] in the first one. The tests run fine, but the Go To Definition does no work for the steps defined in the other 3 parts of the class. It says the step was not found and presents a suggestion of step template.

@mattmiller85

We're having the same issue with 1.9.3.1 and VS 2013 that @rafaelromao describes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.