Feature Request: Highlight variables that implement IDisposable

Our developers always forget to put IDisposable objects in using() constructs. It would be a great help if R# could suggest putting such members into a using() construct, or at least highlight them in a different color, so the developers are warned visually. I noticed that a request like this has already been made several times, but it still seems not to be fulfilled in the latest version (4.0.755)

best regards
Urs

15 comments
Comment actions Permalink

Hello Urs,

It is a problem to detect such things correctly without false positives.
Consider the code like this:

var d = new SomeDisposable();
... code here ...
Register(d); // This stores d in a field and disposes later, when container
object gets disposed.
... code here ...

In the case above warning would be false positive and it will really annoy
everyone all over the code. Analysing data flow is in our plans, but not
for 4.0.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> Our developers always forget to put IDisposable objects in using()
IR> constructs. It would be a great help if R# could suggest putting
IR> such members into a using() construct, or at least highlight them in
IR> a different color, so the developers are warned visually. I noticed
IR> that a request like this has already been made several times, but it
IR> still seems not to be fulfilled in the latest version (4.0.755)
IR>
IR> best regards
IR> Urs




0
Comment actions Permalink

I love this idea. Currently, we can convert it to a using() blog, but I love the idea of telling the developer that it's disposable. I browsed thru the tracker, but didn't find anything covering exactly what you're talking about. You may want to add it. There was a close one, tho: . Take a look at that. You may simply want to add comments to it.

0
Comment actions Permalink

"Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
news:76a2bd0b1533ce8ca57df9674612f@news.intellij.net...

Hello Urs,

>

It is a problem to detect such things correctly without false positives.
Consider the code like this:

>

var d = new SomeDisposable();
... code here ...
Register(d); // This stores d in a field and disposes later, when
container object gets disposed.
... code here ...

>

In the case above warning would be false positive and it will really annoy
everyone all over the code. Analysing data flow is in our plans, but not


Perhaps a more generally-useful feature would be to highlight every place
where, if you clicked on it, a lightbulb would appear? Then, the IDisposable
would show up highlighted.

--
John


0
Comment actions Permalink

Hello,

Perhaps a more generally-useful feature would be to highlight every
place where, if you clicked on it, a lightbulb would appear? Then, the
IDisposable would show up highlighted.


This way, nearly all the file will be highlighted …


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0
Comment actions Permalink

It would be great if R# 4 could even do something as simple as colouring disposables slightly differently (darker, lighter, more or less saturated, whatever.) It would avoid all of the mega-engineering, false positives, etc. that the JetBrains folks are concerned about, while providing a simple visual cue to the developer when they are scanning through code.

Edited by: Jeremy Gray on Mar 25, 2008 4:20 AM

0
Comment actions Permalink

This is a great concept, but I wonder if disposable fields should always be highlighted or just if used outside an associated using? I am concerned about "color clutter" within the using block. Since the only usages outside a using would (should) be allocation or disposing, I think it makes sense to highlight these cases.

Highlighting the field declaration also makes sense.

Edited by: Brian Strelioff on Mar 24, 2008 8:36 PM

0
Comment actions Permalink

"Serge Baltic" <baltic@intellij.net> wrote in message
news:dc0986bfc279b8ca5bfb68799fe3@news.intellij.net...

Hello,

>
>> Perhaps a more generally-useful feature would be to highlight every
>> place where, if you clicked on it, a lightbulb would appear? Then, the
>> IDisposable would show up highlighted.
>

This way, nearly all the file will be highlighted .


Good point.

These aren't inspection suggestions, warnings or errors, but I'd still like
to be able to see them all at a glance.

My abstract reasoning is that here's something that ReSharper knows (or can
find out), and which it is not going to tell me unless I go click all over
the place! I'm looking for a substitute for clicking all over the place.
Instead, maybe there should be a "Show Me" menu with sub menus like,
"IDisposable not in a using", etc.
--
John


0
Comment actions Permalink

Hello Jeremy,

If only every ReSharper user could accept hints as just hints and not "ReSharper
suggests this or that. Why?". We had (and still have) massive discussions
about "var" hint. If we add more hints it could be complete mess for many
users.

However, something like "Highlight usages" but for some temporary analysis
looks like a good idea. Highlight disposables, highlight modified closure
in delegates, highlight variables which are initialized and used only once
(subject to inline), etc. We will think about it.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> It would be great if R# 4 could even do something as simple as
IR> colouring disposables slightly differently (darker, lighter, more or
IR> less saturated, whatever) than other fields, arguments, and
IR> variables. It would avoid all of the mega-engineering, false
IR> positives, etc. that the JetBrains folder are concerned about, while
IR> providing a simple visual cue to the developer when they are
IR> scanning through code.
IR>


0
Comment actions Permalink

That approach would also do quite nicely. Thanks for taking the general idea under consideration.

0
Comment actions Permalink

Whoa, I was away for a few days and didn't see the massive discussion my humble request sparked. For me, it would be sufficient to just see all the disposable variables in another color. R# already marks variables e.g. used as parameter variables with a light-yellow background, I could imaging having IDisposable variables with a light-red background or so. Nothing complicated such as context actions, code flow analysis is necessary, all I want is that developers see that this variable is "special" and it needs to be treated with special attention. It would also be a great help if I do code reviews of foreign code, so I quickly see if the developer uses all disposable variables appropriately.

I guess such a highlighting is not a big deal for R#, since it already has all the necessary information.

0
Comment actions Permalink

Hello Urs,

R

  1. already marks variables e.g. used as parameter variables with a light-yellow

background
Interesting, I don't know about such feature in our product. Could you please
explain what do you mean?

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


IR> R# already marks variables e.g. used as parameter variables with a
IR> light-yellow background
IR>


0
Comment actions Permalink

He's just talking about the standard token colors you can set via the
Options dialog (colors for static variables, local variables, parameters,
etc).

He's just asking for another option to specify "disposable variables" or
something like that.

I'm sure there are several new entries you could add to the text coloring
options that some users might find useful, along these lines... as long as
Resharper "knows" this stuff anyway.


"Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
news:76a2bd0b153cc98ca5d562be22dfa@news.intellij.net...

Hello Urs,

>
>> R# already marks variables e.g. used as parameter variables with a
>> light-yellow

background
Interesting, I don't know about such feature in our product. Could you
please explain what do you mean?

>

Sincerely,
Ilya Ryzhenkov

>

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

>
>

IR> R# already marks variables e.g. used as parameter variables with a
IR> light-yellow background
IR>


0
Comment actions Permalink

Hello Paul,

Ah, I see. So we should have color for disposable, locked on, serializable,
nhibernatable, altnettable and what other kinds of colors? :) This is not
just small feature, this is something we need to think out.

Sincerely,
Ilya Ryzhenkov

JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


PB> He's just talking about the standard token colors you can set via
PB> the Options dialog (colors for static variables, local variables,
PB> parameters, etc).
PB>
PB> He's just asking for another option to specify "disposable
PB> variables" or something like that.
PB>
PB> I'm sure there are several new entries you could add to the text
PB> coloring options that some users might find useful, along these
PB> lines... as long as Resharper "knows" this stuff anyway.
PB>
PB> "Ilya Ryzhenkov" <orangy@jetbrains.com> wrote in message
PB> news:76a2bd0b153cc98ca5d562be22dfa@news.intellij.net...
PB>
>> Hello Urs,
>>
>>> R# already marks variables e.g. used as parameter variables with a
>>> light-yellow
>>>
>> background
>> Interesting, I don't know about such feature in our product. Could
>> you
>> please explain what do you mean?
>> Sincerely,
>> Ilya Ryzhenkov
>> JetBrains, Inc
>> http://www.jetbrains.com
>> "Develop with pleasure!"
>> IR> R# already marks variables e.g. used as parameter variables with
>> a
>> IR> light-yellow background
>> IR>


0
Comment actions Permalink

I think there are mutiple features (or meta-features) here:

1) The ability to highlight variables/fields that implement/inherit something of interest (IDisposable)
2) The ability to highlight variables/fields used in a certain way (lock(), IDisposable used outside a using, ...)
3) The ability to specify semantic conditions for parameters (locked/unlocked, inside/outside a using, ...)

For 1), the most flexible approach is to allow the user to specify what they are interested in, and how to highlight it. This is probably doable in the 4.0 timeframe, but not enough of a win to hold up or risk 4.0.

For 2), the rules are fairly straight-forward, but the impact is not understood well-enough for the 4.0 timeframe. The feature could probably be hashed out with a few discussions, but implementation is not realistic for 4.0.

For 3), RS needs to cleanup the existing null/non-null specification before trying something similar for lock/using.

lock/using are defined concepts in C#, so I can see giving them much higher priority than Serializable, Hibernate, ..., but a generic (i.e. customizable) approach like 1) might handle things the best way as to simple highlighting.

0
Comment actions Permalink

Are you still planning to add this, in my view it would be a very useful feature.

0

Please sign in to leave a comment.