Skip to content

Instantly share code, notes, and snippets.

@controlflow
Created June 19, 2017 22:58
Show Gist options
  • Save controlflow/ec9c89bea6ffdd371343172b55f3e872 to your computer and use it in GitHub Desktop.
Save controlflow/ec9c89bea6ffdd371343172b55f3e872 to your computer and use it in GitHub Desktop.
public void Run(ITreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
{
var warningDirective = element as IWarningDirective;
if (warningDirective != null)
{
var messageToken = "#warning directive";
var tokenNode = warningDirective.Message;
if (tokenNode != null) messageToken = tokenNode.GetText();
consumer.AddHighlighting(new WarningPPDirectiveWarning(warningDirective, messageToken));
return;
}
var errorDirective = element as IErrorDirective;
if (errorDirective != null)
{
var message = "#error directive";
var messageToken = errorDirective.Message;
if (messageToken != null) message = messageToken.GetText();
consumer.AddHighlighting(new ErrorPPDirectiveError(errorDirective, message));
return;
}
var invalidDirective = element as IPreprocessorErrorDirective;
if (invalidDirective != null)
{
consumer.AddHighlighting(new InvalidPPDirectiveError(invalidDirective));
return;
}
var startRegion = element as IStartRegion;
if (startRegion != null)
{
var daemonStageProcess = (CSharpDaemonStageProcessBase) consumer.Process;
var fileStructure = daemonStageProcess.FileStructure.NotNull();
if (fileStructure[startRegion] == null)
{
consumer.AddHighlighting(new UnmatchedRegionPPDirectiveError(startRegion));
return;
}
}
var endRegion = element as IEndRegion;
if (endRegion != null)
{
var daemonStageProcess = (CSharpDaemonStageProcessBase) consumer.Process;
var fileStructure = daemonStageProcess.FileStructure.NotNull();
if (fileStructure[endRegion] == null)
{
consumer.AddHighlighting(new UnmatchedRegionPPDirectiveError(endRegion));
return;
}
}
}
public void Run(ITreeNode element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
{
switch (element)
{
case IWarningDirective warningDirective:
{
var messageToken = "#warning directive";
var tokenNode = warningDirective.Message;
if (tokenNode != null) messageToken = tokenNode.GetText();
consumer.AddHighlighting(new WarningPPDirectiveWarning(warningDirective, messageToken));
return;
}
case IErrorDirective errorDirective:
{
var message = "#error directive";
var messageToken = errorDirective.Message;
if (messageToken != null) message = messageToken.GetText();
consumer.AddHighlighting(new ErrorPPDirectiveError(errorDirective, message));
return;
}
case IPreprocessorErrorDirective invalidDirective:
{
consumer.AddHighlighting(new InvalidPPDirectiveError(invalidDirective));
return;
}
case IStartRegion startRegion:
{
var daemonStageProcess = (CSharpDaemonStageProcessBase) consumer.Process;
var fileStructure = daemonStageProcess.FileStructure.NotNull();
if (fileStructure[startRegion] == null)
consumer.AddHighlighting(new UnmatchedRegionPPDirectiveError(startRegion));
return;
}
case IEndRegion endRegion:
{
var daemonStageProcess = (CSharpDaemonStageProcessBase) consumer.Process;
var fileStructure = daemonStageProcess.FileStructure.NotNull();
if (fileStructure[endRegion] == null)
consumer.AddHighlighting(new UnmatchedRegionPPDirectiveError(endRegion));
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment