how to remove highlightings?
Hello everybody!
I have a problem with one of my custom highlightings:
What I am trying to do is to detect when multiple type declarations appear
in a single file.
The detection works fine, the error highlightings show up properly.
For example, when I declare two structs in a file, let's say
struct A {}
struct B {}
then A and B will be highlighted with an error.
The problem arises when I remove one of the two declarations. Then the error
highlighting stays
at the remaining one. Interestingly, if I modify the name of the remaining
struct, the error highlighting
disappears and does not show up again.
So the question is: How do I remove prior highlightings from the editor?
My understanding of the R# OpenAPI is the following (please correct me if
I got something wrong or if something is missing):
- The DaemonStageProcessResult.Highlightings array only carries new highlightings
that will
be added to the editor.
- The DaemonStageProcessResult.RehighlightedRanges holds TextRanges that
are used to remove
old highlightings from the editor (well, that's what I am trying to do...)
- The RehighlightedRanges.FullyRehighlighted flag is just a shortcut for
specifying a TextRange in the
above array which spans the whole IDocument.
The IDaemonStageProcess.Execute() method gets called properly, also my implementation
correctly
detects wether a multiple type declaration situation has occured or not.
I tried nealry all possible combinations of filling a DaemonStageProcessResult
object:
DaemonStageProcessResult.Highlightings = { null | [] | }
DaemonStageProcessResult.RehighlightedRanges = { null | [] | [TextRange(0,100)
| }
DaemonStageProcessResult.FullyRehighlighted = { true | false }
Nothing seems to work. What am I doing wrong?
Thank you!
Sincerely
Matthias Schwinn
Please sign in to leave a comment.
At your custom highlighting stage, you have to say that entrire file was
re-highlighted (DaemonStageProcessResult.FullyRehighlighted = true). Thus
other highlightings (which are not returned in DaemonStageProcessResult)
will be removed
--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Matthias Schwinn" <dev@pikantos.de> wrote in message
news:cd765b8e057a8c8ca1ad0858700@news.jetbrains.com...
>
>
>
>
>
>
>
>
>
>
>
Hi!
Yes, I understand that setting the FullyRehighlighted property to true should remove all prior highlightings.
Unfortunately, it does not work. I do not know why.
Here is an example of what happens when I use my plugin.
First, I open a C# source file in the editor:
>>> Program.cs <<<
namespace Test
{
public delegate void test();
public delegate void test2();
}
>>> end <<<
test and test2 properly get highlighted with an error. See attached msgbox_1.png for details on the DaemonStageProcessResult
object I return.
Then, I remove the declaration of test2:
>>> Program.cs <<<
namespace Test
{
public delegate void test();
}
>>> end <<<
The error highlighting remains at test. FullyRehighlighted was set to true and the Highlightings array was empty. See attached msgbox_2.png for detais.
Finally, I rename 'test' to 'Test':
>>> Program.cs <<<
namespace Test
{
public delegate void Test();
}
>>> end <<<
Now the error highlighting has disappeared. However, the returned DaemonStageProcessResult object matches the one returned at the previous step (see msgbox_2.png). I can spot no difference between the two.
This is the code that shows the message box:
>>>>>>>>
StringBuilder sb;
sb = new StringBuilder();
sb.Append(process.ProjectFile.Name);
sb.Append("\n");
sb.Append("FullRehighlightingRequired = " + process.FullRehighlightingRequired);
sb.Append("\n");
sb.Append("FullyRehighlighted = " + result.FullyRehighlighted);
sb.Append("\n");
foreach (IHighlighting highlighting in result.Highlightings)
{
sb.Append("Highlighting = " + highlighting.ToString());
sb.Append("\n");
}
MessageBox.Show(sb.ToString());
<<<<<<<<
BTW, is there a better way than this for dumping information (eg. writing to the R# log file) ?
I noticed that the IDaemonStageProcess.Execute() method gets called up to 13 times when I open the file and 2-4 times each time I remove a line that contains a type declaration. Does this indicate some error? At present, I do not honor the IDaemonProcess.InterruptFlag, perhaps this causes problems.
Thanks for your help!
Sincerely
Matthias Schwinn
Attachment not added (general error): "msgbox_2.PNG"
Attachment(s):
msgbox_1.PNG
1) With ghost highlightings - I'll investigate this shortly
2) IDaemonStageProcess.Execute() should be called once per every
highlighting run
Please could you send me the sources of your daemon stage so I could check
what happens?
--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Matthias Schwinn" <dev@pikantos.de> wrote in message
news:cd765b8e057e8c8ca26e5080a10@news.jetbrains.com...
Hi!
Yes, I understand that setting the FullyRehighlighted property to true
should remove all prior highlightings.
Unfortunately, it does not work. I do not know why.
Here is an example of what happens when I use my plugin.
First, I open a C# source file in the editor:
>>> Program.cs <<<
namespace Test
{
public delegate void test();
public delegate void test2();
}
>>> end <<<
test and test2 properly get highlighted with an error. See attached
msgbox_1.png for details on the DaemonStageProcessResult
object I return.
Then, I remove the declaration of test2:
>>> Program.cs <<<
namespace Test
{
public delegate void test();
}
>>> end <<<
The error highlighting remains at test. FullyRehighlighted was set to true
and the Highlightings array was empty. See attached msgbox_2.png for detais.
Finally, I rename 'test' to 'Test':
>>> Program.cs <<<
namespace Test
{
public delegate void Test();
}
>>> end <<<
Now the error highlighting has disappeared. However, the returned
DaemonStageProcessResult object matches the one returned at the previous
step (see msgbox_2.png). I can spot no difference between the two.
This is the code that shows the message box:
>>>>>>>>
StringBuilder sb;
sb = new StringBuilder();
sb.Append(process.ProjectFile.Name);
sb.Append("\n");
sb.Append("FullRehighlightingRequired = " +
process.FullRehighlightingRequired);
sb.Append("\n");
sb.Append("FullyRehighlighted = " + result.FullyRehighlighted);
sb.Append("\n");
foreach (IHighlighting highlighting in result.Highlightings)
{
sb.Append("Highlighting = " + highlighting.ToString());
sb.Append("\n");
}
MessageBox.Show(sb.ToString());
<<<<<<<<
BTW, is there a better way than this for dumping information (eg. writing to
the R# log file) ?
I noticed that the IDaemonStageProcess.Execute() method gets called up to 13
times when I open the file and 2-4 times each time I remove a line that
contains a type declaration. Does this indicate some error? At present, I do
not honor the IDaemonProcess.InterruptFlag, perhaps this causes problems.
Thanks for your help!
Sincerely
Matthias Schwinn
Thanks four your help!
Please find attached the source codes of my plugin.
I am using ReSharper 2.0 #259 with VS 2005.
Attachment not added (general error): "src.zip"
The problem is in the following line:
public sealed class SingleTypePerFileStage : IDaemonStage
{
public Key Key
{
get
{
return new Key("BTB_ReSharper_PlugIn.SingleTypePerFileStage");
}
}
}
Since the uniqueness of the key is computed by the key instance (but not the
key name), Re-highlighting cannot remove previous error.
Please memorize the key in the static field, and return it then
--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Matthias Schwinn" <dev@pikantos.de> wrote in message
news:cd765b8e05878c8ca3ae38069b0@news.jetbrains.com...
Thanks four your help!
Please find attached the source codes of my plugin.
I am using ReSharper 2.0 #259 with VS 2005.
Great, now the highlightings work just fine!
I did not think about the stage key at all...
BTW, with the proper stage key the IDaemonStageProcess.Execute() gets called
exactly once per highlighting process, just as it should.
Thanks!