Skip to content

@nesteruk /gist:1474476
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Highlighting on 2nd line in every document
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.