Esempio n. 1
0
        public override void OnIdle(bool periodic)
        {
            // from IronPythonLanguage sample
            // this appears to be necessary to get a parse request with ParseReason = Check?
            SoalLanguageSource src = (SoalLanguageSource)GetSource(this.LastActiveTextView);

            if (src != null && src.LastParseTime >= Int32.MaxValue >> 12)
            {
                src.LastParseTime = 0;
            }
            base.OnIdle(periodic);
        }
Esempio n. 2
0
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            try
            {
                SoalLanguageSource source = (SoalLanguageSource)this.GetSource(req.FileName);
                switch (req.Reason)
                {
                case ParseReason.Check:
                    // This is where you perform your syntax highlighting.
                    // Parse entire source as given in req.Text.
                    // Store results in the AuthoringScope object.
                    string fileName    = Path.GetFileName(req.FileName);
                    string inputDir    = Path.GetDirectoryName(req.FileName);
                    var    compilation = new MetaDslx.Languages.Soal.Compilation.SoalCompiler(req.Text, "", inputDir, null, req.FileName);
                    compilation.Compile();
                    foreach (var diagnostic in compilation.GetDiagnostics())
                    {
                        var      diagSpan = diagnostic.Location.GetMappedLineSpan();
                        TextSpan span     = new TextSpan();
                        span.iStartLine  = diagSpan.StartLinePosition.Line;
                        span.iEndLine    = diagSpan.EndLinePosition.Line;
                        span.iStartIndex = diagSpan.StartLinePosition.Character;
                        span.iEndIndex   = diagSpan.EndLinePosition.Character;
                        Severity severity = Severity.Error;
                        switch (diagnostic.Severity)
                        {
                        case MetaDslx.Compiler.Diagnostics.DiagnosticSeverity.Error:
                            severity = Severity.Error;
                            break;

                        case MetaDslx.Compiler.Diagnostics.DiagnosticSeverity.Warning:
                            severity = Severity.Warning;
                            break;

                        case MetaDslx.Compiler.Diagnostics.DiagnosticSeverity.Info:
                            severity = Severity.Hint;
                            break;
                        }
                        string msg = Compiler.Diagnostics.DiagnosticFormatter.Instance.Format(diagnostic);
                        req.Sink.AddError(req.FileName, msg, span, severity);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                req.Sink.AddError(req.FileName, "Error while parsing source: " + ex.ToString(), new TextSpan(), Severity.Error);
            }
            return(new SoalLanguageAuthoringScope());
        }