You would want to do that kind of checking within an IParser service for the syntax language. Then you'd report the errors within the IParseData object passed back by the IParser.Parse method as described in this documentation topic.
If you register the language services seen in our Getting Started #5 QuickStart, that adds a tagger that will watch for parse errors and render them as squiggles. Then another service will show quick info for the squiggles when hovered over.
I assume based on the code snippet above that you are using the C# language from our .NET Languages Add-on? If so, you'd probably need to unregister the default CSharpParser language service, write your own IParser class that "wraps" a CSharpParser, and register that as the language's parser instead. Your wrapper parser should call into the wrapped CSharpParser first for its IParseData results. Then run your validation routines after by examining the AST, etc. and add any errors into that parse data or a custom implementation of IParseData.