-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Suggestion: Search for Optional Method Parameter Usage #325
Comments
Well, I expand your situation to the following code snippet: void Foo(int required, string optional = "", bool optional2 = false) { }
// Example when searching for `optional2` usage
void A() {
Foo(25); // Not a match, because optionals are not specified
}
void B() {
Foo(25, "bar"); // Not a match, because it is not the searched optional
}
void C() {
Foo(25, "bar", true); //Match! We searched for optional2
}
void D() {
Foo(25, optional2: true); //Also Match! Named optional parameter we searched for.
} When changing the default values of |
You are right. I am sorry, I did not explain it correctly. Yes, both cases are actually valid and useful, and thus there should be 2 distinct searches:
|
Thank you for the suggestion on case 1. Yes, I have tried it, but it is a pretty bad experience and prone to errors, as you may accidentally confirm signature change even though you did not want to. I would much prefer to have a pinnable (like all Codist's popups) list of all found parameter usages with their assigned values provided - either direcvtly or in a tooltip. So I can then go one-by-one in that list and revioew such cases. |
Well, I understood. |
Wow! You are so fast! This looks great!!! The only addition I would like to see is that perhaps it could be adjusted slightly with modifier keys (similar to how it is already done with other find symbol commands), such that there are options to display just: parameters with explicit value provided OR parameters that use default values (with the 3rd option being with no modifier keys that displays both cases) |
Please test the new beta which includes this feature. The keyboard modifier alteration will be added to the next beta. |
BTW, I am feeling good for this feature as well :) |
Unfortunately VS crashed on the first try:
|
Please try the new beta. |
Still crashes:
|
Please try the new beta. |
Now it did not crash :) I will keep on using it and let you know if I encounter any issues. Thank you for such a great work! I also really like how you aligned the call sites that all belong to the same method! Really useful! |
So far seems to be working great! Thanks so much for all your work! |
Thank you very much for sharing your idea and the feedback. |
Just noticed that when searching for default assignments only (via Shift), it incorrectly shows the same list as when searching for all assignments, but lists the value as default for all of them (also incorrectly). Explicit assignments work fine. |
Please use the new beta which fixes the above problem. |
Just found another issue: Apparently it does not find any usages of a parameter if that usage is in Attribute constructor: public sealed class MyAttribute : Attribute {
public MyAttribute(string testarg = "") { } // Usage of testarg is not found at all
}
[MyAttribute("test")]
bool Foo; |
No, it does not. |
The new beta has implemented finding argument assignments in attributes. |
Thanks so much for your work! This actually is pretty important for me as I have lots of cases where enums have attributes with complex constructors, so it is quite useful! However there is a minor issue with the latest version. While it finds all instances of parameter usage, the value that is displayed in the list on the right is often incorrect. In particular, if the parameter is optional and is not provided at the call site, but, because the "call site" is in the attributes, the So, given: public sealed class MyAttr : Attribute {
public MyAttr(string requiredarg, bool optionalarg = false) { }
public int PropertyName {get; set;}
}
Enum Foo {
[MyAttr("foostring", PropertyName = 77)]
MyValue = 0,
} The usages of |
You are right. The 77 is in the same "slot". |
Thank you for a quick fix! This works great now! |
Got another VS crash when tried using the functionality:
|
It is a bug. |
The Codist's Find Symbol functions are really useful. However one item is missing. It would be really nice to be able to find usage of optional method parameters by their callers, supporting both positional and named usages:
It is often very needed to perform such a search when changing the default values of optional parameters or when refactoring code and changing method signatures.
The text was updated successfully, but these errors were encountered: