Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Highlighting on 2nd line in every document

View gist:1474476
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
using System;
using System.Collections.Generic;
using System.Diagnostics;
using JetBrains.Annotations;
using JetBrains.Application.Progress;
using JetBrains.Application.Settings;
using JetBrains.DocumentModel;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.Util;
using JetBrains.Util.dataStructures.TypedIntrinsics;
 
namespace ByLinePluginTest
{
[DaemonStage()]
public class TheStage : IDaemonStage
{
public IDaemonStageProcess CreateProcess([NotNull] IDaemonProcess process, IContextBoundSettingsStore settings, DaemonProcessKind processKind)
{
if (process == null) throw new ArgumentNullException("process");
 
return new TheProcess(process);
}
 
public ErrorStripeRequest NeedsErrorStripe(IPsiSourceFile sourceFile, IContextBoundSettingsStore settingsStore)
{
return ErrorStripeRequest.STRIPE_AND_ERRORS;
}
}
 
public class TheProcess : IDaemonStageProcess
{
private readonly IDaemonProcess process;
 
public TheProcess(IDaemonProcess process)
{
this.process = process;
}
 
public void Execute(Action<DaemonStageResult> commiter)
{
var mgr = PsiManager.GetInstance(process.Solution);
var file = mgr.GetPsiFile<CSharpLanguage>(process.SourceFile) as ICSharpFile;
if (file == null) return;
 
var processor = new HighlightSecondLine(process);
file.ProcessDescendants(processor);
 
if (process.InterruptFlag) throw new ProcessCancelledException();
 
commiter(new DaemonStageResult(processor.Highlightings));
}
 
public IDaemonProcess DaemonProcess
{
get { return process; }
}
}
 
public class HighlightSecondLine : IRecursiveElementProcessor
{
private readonly IDaemonProcess process;
public ICollection<HighlightingInfo> Highlightings = new List<HighlightingInfo>();
 
public HighlightSecondLine(IDaemonProcess process)
{
this.process = process;
}
 
public bool InteriorShouldBeProcessed(ITreeNode element)
{
return false;
}
 
public void ProcessBeforeInterior(ITreeNode element)
{
 
}
 
public void ProcessAfterInterior(ITreeNode element)
{
var warning = new TheHighlighting("danger!");
var line = (Int32<DocLine>)1;
var document = process.Document;
var textRange = new TextRange(document.GetLineStartOffset(line),
document.GetLineEndOffsetNoLineBreak(line));
var docRange = new DocumentRange(document, textRange);
Highlightings.Add(new HighlightingInfo(docRange, warning));
}
 
public bool ProcessingIsFinished
{
get { return process.InterruptFlag; }
}
}
 
[StaticSeverityHighlighting(Severity.WARNING, "CSharpInfo", ColorOnStripeName = "Red")]
public class TheHighlighting : IHighlighting
{
private readonly string message;
 
public TheHighlighting(string message)
{
this.message = message;
}
 
public bool IsValid()
{
return true;
}
 
public string ToolTip
{
get { return message; }
}
 
public string ErrorStripeToolTip
{
get { return message; }
}
 
public int NavigationOffsetPatch
{
get { return 0; }
}
}
}
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.