Esempio n. 1
0
        public void UpdateParser(System.Object obj)
        {
            string text = editor.doc.GetRawText();

            if (!Directory.Exists(Path.GetDirectoryName(tmpFileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(tmpFileName));
            }
            try {
                System.IO.StreamWriter fileStream = new System.IO.StreamWriter(tmpFileName);
                fileStream.Write(text);
                fileStream.Close();
            }
            catch (System.Exception) {
            }

            CompilationUnit project = new CompilationUnit("");

            project.AddFile(tmpFileName);

            try {
                project.Parse();
            }
            catch (System.Exception) {
            }

            errors = new List <ErrorDef>();

            foreach (Error error in project.Errors)
            {
                if (error.Code != "SYNERR")
                {
                    continue;
                }
                ErrorDef def = new ErrorDef();
                def.line        = error.Line - 1;
                def.column      = error.Column - 1;
                def.description = error.Description;
                def.type        = ErrorType.Error;
                errors.Add(def);

                if (def.description == "scolon expected")
                {
                    def.description = "';' expected.";
                }
                if (def.description == "lbrace expected")
                {
                    def.description = "'{' expected.";
                }
                if (def.description == "rbrace expected")
                {
                    def.description = "'}' expected.";
                }
            }

            wantsParserUpdate = false;
        }
Esempio n. 2
0
        public bool OnPreRenderLine(UIDELine line)
        {
            if (line == null)
            {
                return(false);
            }
            ErrorDef errorDef = null;

            for (int i = 0; i < errors.Count; i++)
            {
                if (errors[i] != null && errors[i].line == line.index)
                {
                    errorDef = errors[i];
                }
            }
            if (errorDef != null)
            {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x = editor.doc.scroll.x;
                float columnOffset   = line.GetScreenPosition(errorDef.column) * editor.charSize.x;
                float lineEnd        = line.GetScreenPosition(line.rawText.Length) * editor.charSize.x;
                float highlightLegth = lineEnd - columnOffset;

                logLineRect.x     += columnOffset;
                logLineRect.width  = highlightLegth;
                logLineRect.height = editor.charSize.y;
                logLineRect.y      = (line.index) * editor.charSize.y;

                if (logLineRect.Contains(Event.current.mousePosition))
                {
                    mouseOverError      = errorDef;
                    mouseOverRect       = logLineRect;
                    mouseOverRect.width = Mathf.Clamp(mouseOverRect.width, 100.0f, editor.actualTextAreaRect.width);
                }

                Rect underlineRect = logLineRect;
                underlineRect.height = errorUnderlineTex.height;
                underlineRect.y     += editor.charSize.y;
                underlineRect.y     -= underlineRect.height;

                Rect underlineUVRect = underlineRect;
                underlineUVRect.x      = 0;
                underlineUVRect.y      = 0;
                underlineUVRect.height = 1;

                underlineUVRect.width = underlineUVRect.width / (float)errorUnderlineTex.width;

                Color color = editor.editorWindow.theme.errorUnderlineColor;

                GUI.color = color;
                GUI.DrawTextureWithTexCoords(underlineRect, errorUnderlineTex, underlineUVRect);
                GUI.color = Color.white;
            }
            return(false);
        }
Esempio n. 3
0
 public override void OnTextEditorUpdate()
 {
     if (wantsParserUpdate && editor.editorWindow.time - lastParseTime > reparseDelay)
     {
         if (!UIDEThreadPool.IsRegistered("InlineErrorHighlighter_Parse"))
         {
             wantsParserUpdate = false;
             lastParseTime     = editor.editorWindow.time;
             UIDEThreadPool.RegisterThread("InlineErrorHighlighter_Parse", UpdateParser);
         }
     }
     mouseOverError = null;
 }
        public bool OnPreRenderLine(UIDELine line)
        {
            if (line == null) return false;
            ErrorDef errorDef = null;
            for (int i = 0; i < errors.Count; i++) {
                if (errors[i] != null && errors[i].line == line.index) {
                    errorDef = errors[i];
                }
            }
            if (errorDef != null) {
                Rect logLineRect = editor.actualTextAreaRect;
                logLineRect.x = editor.doc.scroll.x;
                float columnOffset = line.GetScreenPosition(errorDef.column)*editor.charSize.x;
                float lineEnd = line.GetScreenPosition(line.rawText.Length)*editor.charSize.x;
                float highlightLegth = lineEnd-columnOffset;

                logLineRect.x += columnOffset;
                logLineRect.width = highlightLegth;
                logLineRect.height = editor.charSize.y;
                logLineRect.y = (line.index)*editor.charSize.y;

                if (logLineRect.Contains(Event.current.mousePosition)) {
                    mouseOverError = errorDef;
                    mouseOverRect = logLineRect;
                    mouseOverRect.width = Mathf.Clamp(mouseOverRect.width,100.0f,editor.actualTextAreaRect.width);
                }

                Rect underlineRect = logLineRect;
                underlineRect.height = errorUnderlineTex.height;
                underlineRect.y += editor.charSize.y;
                underlineRect.y -= underlineRect.height;

                Rect underlineUVRect = underlineRect;
                underlineUVRect.x = 0;
                underlineUVRect.y = 0;
                underlineUVRect.height = 1;

                underlineUVRect.width = underlineUVRect.width/(float)errorUnderlineTex.width;

                Color color = editor.editorWindow.theme.errorUnderlineColor;

                GUI.color = color;
                GUI.DrawTextureWithTexCoords(underlineRect,errorUnderlineTex,underlineUVRect);
                GUI.color = Color.white;
            }
            return false;
        }
        public void UpdateParser(System.Object obj)
        {
            string text = editor.doc.GetRawText();

            if (!Directory.Exists(Path.GetDirectoryName(tmpFileName))) {
                Directory.CreateDirectory(Path.GetDirectoryName(tmpFileName));
            }
            try {
                System.IO.StreamWriter fileStream = new System.IO.StreamWriter(tmpFileName);
                fileStream.Write(text);
                fileStream.Close();
            }
            catch (System.Exception) {

            }

            CompilationUnit project = new CompilationUnit("");

            project.AddFile(tmpFileName);

            try {
                project.Parse();
            }
            catch (System.Exception) {

            }

            errors = new List<ErrorDef>();

            foreach (Error error in project.Errors) {
                if(error.Code != "SYNERR") continue;
                ErrorDef def = new ErrorDef();
                def.line = error.Line-1;
                def.column = error.Column-1;
                def.description = error.Description;
                def.type = ErrorType.Error;
                errors.Add(def);

                if (def.description == "scolon expected") {
                    def.description = "';' expected.";
                }
                if (def.description == "lbrace expected") {
                    def.description = "'{' expected.";
                }
                if (def.description == "rbrace expected") {
                    def.description = "'}' expected.";
                }
            }

            wantsParserUpdate = false;
        }
 public override void OnTextEditorUpdate()
 {
     if (wantsParserUpdate && editor.editorWindow.time-lastParseTime > reparseDelay) {
         if (!UIDEThreadPool.IsRegistered("InlineErrorHighlighter_Parse")) {
             wantsParserUpdate = false;
             lastParseTime = editor.editorWindow.time;
             UIDEThreadPool.RegisterThread("InlineErrorHighlighter_Parse",UpdateParser);
         }
     }
     mouseOverError = null;
 }