Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
Created June 9, 2012 23:19
Show Gist options
  • Save DinisCruz/2903012 to your computer and use it in GitHub Desktop.
Save DinisCruz/2903012 to your computer and use it in GitHub Desktop.
O2 Script to show Roslyn Ast Error detection capabilities
//var topPanel = panel.clear().add_Panel();
var topPanel = "Simple AstTester".popupWindow(700,300);
var codeViewer = topPanel.title("Code").add_SourceCodeViewer();
var errorsList = topPanel.insert_Right(300,"AstTree Errors").add_TextArea();
Action<string> showErrors =
(newCode)=>{
codeViewer.editor().clearBookmarksAndMarkers();
var astTree = newCode.tree();
var errors = astTree.errors();
foreach(var error in errors)
{
var startLinePosition = error.Location
.GetLineSpan(true)
.StartLinePosition;
codeViewer.editor().setSelectedText(startLinePosition.Line +1,
startLinePosition.Character,
true);
}
errorsList.set_Text(astTree.errors_Details());
};
var code =
@"var a = 12;
this is an error
string b = 333;
aaaaaa-
class test
{
public methodWithNoReturnType()
{}
}";
codeViewer.onTextChange(showErrors)
.set_Text(code,".cs");
return "ok";
//O2Ref:O2_FluentSharp_Roslyn.dll
//O2Ref:Roslyn.Compilers.CSharp.dll
//O2Ref:Roslyn.Compilers.dll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment