public override void Analyze (Document doc, LineSegment line, Chunk startChunk, int startOffset, int endOffset)
		{
			if (endOffset <= startOffset || startOffset >= doc.Length)
				return;
			
			string text = doc.GetTextAt (startOffset, endOffset - startOffset);
			int startColumn = startOffset - line.Offset;
			line.RemoveMarker (typeof(UrlMarker));
			foreach (System.Text.RegularExpressions.Match m in urlRegex.Matches (text)) {
				line.AddMarker (new UrlMarker (line, m.Value, UrlType.Url, syntax, startColumn + m.Index, startColumn + m.Index + m.Length));
			}
			foreach (System.Text.RegularExpressions.Match m in mailRegex.Matches (text)) {
				line.AddMarker (new UrlMarker (line, m.Value, UrlType.Email, syntax, startColumn + m.Index, startColumn + m.Index + m.Length));
			}
		}
		void IChunkMarker.ChangeForeColor (MonoTextEditor editor, Chunk chunk, ref Cairo.Color color)
		{
			if (Debugger.DebuggingService.IsDebugging)
				return;
			int markerStart = Segment.Offset;
			int markerEnd = Segment.EndOffset;
			if (chunk.EndOffset <= markerStart || markerEnd <= chunk.Offset) 
				return;
			var bgc = editor.ColorStyle.PlainText.Background;
			double alpha = 0.6;
			color = new Cairo.Color (
				color.R * alpha + bgc.R * (1.0 - alpha),
				color.G * alpha + bgc.G * (1.0 - alpha),
				color.B * alpha + bgc.B * (1.0 - alpha)
			);
		}
		void IChunkMarker.TransformChunks (List<Chunk> chunks)
		{
			int markerStart = Segment.Offset;
			int markerEnd = Segment.EndOffset;
			for (int i = 0; i < chunks.Count; i++) {
				var chunk = chunks [i];
				if (chunk.EndOffset < markerStart || markerEnd <= chunk.Offset) 
					continue;
				if (chunk.Offset == markerStart && chunk.EndOffset == markerEnd)
					return;
				if (chunk.Offset < markerStart && chunk.EndOffset > markerEnd) {
					var newChunk = new Chunk (chunk.Offset, markerStart - chunk.Offset, chunk.Style);
					chunks.Insert (i, newChunk);
					chunk.Offset += newChunk.Length;
					chunk.Length -= newChunk.Length;
					continue;
				}
			}
		}
Пример #4
0
		public override void Analyze (TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
		{
			if (endOffset <= startOffset || startOffset >= doc.TextLength || inUpdate)
				return;
			inUpdate = true;
			try {
				string text = doc.GetTextAt (startOffset, endOffset - startOffset);
				int startColumn = startOffset - line.Offset;
				var markers = new List <UrlMarker> (line.Markers.Where (m => m is UrlMarker).Cast<UrlMarker> ());
				markers.ForEach (m => doc.RemoveMarker (m, false));
				foreach (System.Text.RegularExpressions.Match m in UrlRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Url, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
				foreach (System.Text.RegularExpressions.Match m in MailRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Email, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
			} finally {
				inUpdate = false;
			}
		}
Пример #5
0
			public override void Analyze(TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
			{
				// Check line start
				int o = line.Offset;
				char c = '\0';
				for (; o < line.EndOffset && char.IsWhiteSpace(c = doc.GetCharAt(o)); o++) ;

				if (c != '-' && c != '#')
					return;

				DSyntax.Document = doc;
				var spanParser = new SpanParser(DSyntax, new CloneableStack<Span>());
				var chunkP = new ChunkParser(DSyntax, spanParser, Ide.IdeApp.Workbench.ActiveDocument.Editor.ColorStyle, line);

				var n = chunkP.GetChunks(startOffset, endOffset - startOffset);
				if (n == null)
					return;
				startChunk.Next = n;
				startChunk.Length = n.Offset - startChunk.Offset;
			}
Пример #6
0
		public override void Analyze (TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
		{
			if (endOffset <= startOffset || startOffset >= doc.TextLength || inUpdate)
				return;
			if (startChunk.Style != Highlighting.ColorScheme.CommentsSingleLineKey && startChunk.Style != Highlighting.ColorScheme.CommentsBlockKey)
				return;
			inUpdate = true;
			try {
				string text = doc.GetTextAt (startOffset, System.Math.Min (endOffset, doc.TextLength) - startOffset);
				int startColumn = startOffset - line.Offset;
				var markers = new List <UrlMarker> (line.Markers.OfType<UrlMarker> ());
				markers.ForEach (m => doc.RemoveMarker (m, false));
				foreach (System.Text.RegularExpressions.Match m in UrlRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Url, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
				foreach (System.Text.RegularExpressions.Match m in MailRegex.Matches (text)) {
					doc.AddMarker (line, new UrlMarker (doc, line, m.Value, UrlType.Email, syntax, startColumn + m.Index, startColumn + m.Index + m.Length), false);
				}
			} finally {
				inUpdate = false;
			}
		}
Пример #7
0
 public abstract void Analyze(Document doc, LineSegment line, Chunk startChunk, int startOffset, int endOffset);
Пример #8
0
			public ChunkDescriptor (DocumentLine line, int offset, int length, Chunk[] chunk) : base(line, offset, length)
			{
				this.Chunk = chunk;
			}
Пример #9
0
		void IChunkMarker.ChangeForeColor (MonoTextEditor editor, Chunk chunk, ref Cairo.Color color)
		{
			if (forground == null || editor == null) {
				return;
			}
			int markerStart = Segment.Offset;
			int markerEnd = Segment.EndOffset;
			if (chunk.EndOffset <= markerStart || markerEnd <= chunk.Offset) 
				return;
			color = forground(editor).Foreground;
		}
Пример #10
0
		public abstract void Analyze (TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset);
Пример #11
0
			protected override void AddRealChunk (Chunk chunk)
			{
				var parsedDocument = document != null ? document.ParsedDocument : null;
				if (parsedDocument != null && MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false)) {
					int endLoc = -1;
					string semanticStyle = GetSemanticStyle (parsedDocument, chunk, ref endLoc);
					if (semanticStyle != null) {
						if (endLoc < chunk.EndOffset) {
							base.AddRealChunk (new Chunk (chunk.Offset, endLoc - chunk.Offset, semanticStyle));
							AddRealChunk (new Chunk (endLoc, chunk.EndOffset - endLoc, chunk.Style));
							return;
						}
						chunk.Style = semanticStyle;
					}
				}
				
				base.AddRealChunk (chunk);
			}
Пример #12
0
			protected override string GetStyle (Chunk chunk)
			{
				if (spanParser.CurRule.Name == "Comment") {
					if (tags.Contains (doc.GetTextAt (chunk))) 
						return "comment.keyword.todo";
				}
				return base.GetStyle (chunk);
			}
Пример #13
0
			public ChunkDescriptor (LineSegment line, int offset, int length, Chunk chunk) : base(line, offset, length)
			{
				this.Chunk = chunk;
			}
Пример #14
0
			string GetSemanticStyle (ParsedDocument parsedDocument, Chunk chunk, ref int endOffset)
			{
				var unit = parsedDocument.LanguageAST as ICSharpCode.NRefactory.CSharp.CompilationUnit;
				if (unit == null)
					return null;
				
				var loc = doc.OffsetToLocation (chunk.Offset);
				if (contextualKeywords.Contains (wordbuilder.ToString ())) {
					var node = unit.GetNodeAt (loc.Line, loc.Column);
					if (node is Identifier) {
						switch (((Identifier)node).Name) {
						case "value":
							// highlight 'value' in property setters and event add/remove
							var n = node.Parent;
							while (n != null) {
								if (n is Accessor && n.Role != PropertyDeclaration.GetterRole)
									return null;
								n = n.Parent;
							}
							break;
						case "var": 
							if (node.Parent != null) {
								var vds = node.Parent.Parent as VariableDeclarationStatement;
								if (node.Parent.Parent is ForeachStatement && ((ForeachStatement)node.Parent.Parent).VariableType.StartLocation == node.StartLocation ||
									vds != null && node.StartLocation == vds.Type.StartLocation)
									return null;
							}
							break;
						}
					}
					if (node is CSharpTokenNode) 
						return null;
					endOffset = doc.LocationToOffset (node.EndLocation.Line, node.EndLocation.Column);
					return spanParser.CurSpan != null ? spanParser.CurSpan.Color : "text";
				} else {
					var type = unit.GetNodeAt<AstType> (loc.Line, loc.Column);
					if (type is SimpleType) {
						var st = (SimpleType)type;
						if (st.IdentifierToken.Contains (loc.Line, loc.Column) && unit.GetNodeAt<UsingDeclaration> (loc.Line, loc.Column) == null) {
							endOffset = doc.LocationToOffset (st.IdentifierToken.EndLocation.Line, st.IdentifierToken.EndLocation.Column);
							return "keyword.semantic.type";
						}
						return null;
					}
					if (type is ICSharpCode.NRefactory.CSharp.MemberType) {
						var mt = (ICSharpCode.NRefactory.CSharp.MemberType)type;
						if (mt.MemberNameToken.Contains (loc.Line, loc.Column) && unit.GetNodeAt<UsingDeclaration> (loc.Line, loc.Column) == null) {
							endOffset = doc.LocationToOffset (mt.MemberNameToken.EndLocation.Line, mt.MemberNameToken.EndLocation.Column);
							return "keyword.semantic.type";
						}
						return null;
					}
					
					var node = unit.GetNodeAt (loc.Line, loc.Column);
					if (node is Identifier) {
						if (node.Parent is TypeDeclaration && node.Role == TypeDeclaration.Roles.Identifier) {
							endOffset = doc.LocationToOffset (node.EndLocation.Line, node.EndLocation.Column);
							return "keyword.semantic.type";
						}
						
						if (node.Parent is VariableInitializer && node.Parent.Parent is FieldDeclaration || node.Parent is FixedVariableInitializer || node.Parent is EnumMemberDeclaration) {
							endOffset = doc.LocationToOffset (node.EndLocation.Line, node.EndLocation.Column);
							return "keyword.semantic.field";
						}
					}
					var identifierExpression = unit.GetNodeAt<IdentifierExpression> (loc.Line, loc.Column);
					if (identifierExpression != null) {
						var result = identifierExpression.ResolveExpression (document, resolver, loc);
						if (result is MemberResolveResult) {
							var member = ((MemberResolveResult)result).ResolvedMember;
							if (member is IField) {
								endOffset = doc.LocationToOffset (identifierExpression.EndLocation.Line, identifierExpression.EndLocation.Column);
								return "keyword.semantic.field";
							}
							if (member == null && result.ResolvedType != null && !string.IsNullOrEmpty (result.ResolvedType.FullName)) {
								endOffset = doc.LocationToOffset (identifierExpression.EndLocation.Line, identifierExpression.EndLocation.Column);
								return "keyword.semantic.type";
							}
						}
					}
					
					var memberReferenceExpression = unit.GetNodeAt<MemberReferenceExpression> (loc.Line, loc.Column);
					if (memberReferenceExpression != null) {
						if (!memberReferenceExpression.MemberNameToken.Contains (loc.Line, loc.Column)) 
							return null;
						
						var result = memberReferenceExpression.ResolveExpression (document, resolver, loc);
						if (result is MemberResolveResult) {
							var member = ((MemberResolveResult)result).ResolvedMember;
							if (member is IField) {
								endOffset = doc.LocationToOffset (memberReferenceExpression.MemberNameToken.EndLocation.Line, memberReferenceExpression.MemberNameToken.EndLocation.Column);
								return "keyword.semantic.field";
							}
							if (member == null && result.ResolvedType != null && !string.IsNullOrEmpty (result.ResolvedType.FullName)) {
								endOffset = doc.LocationToOffset (memberReferenceExpression.MemberNameToken.EndLocation.Line, memberReferenceExpression.MemberNameToken.EndLocation.Column);
								return "keyword.semantic.type";
							}
						}
					}
				}
				return null;
			}
		static void HighlightSegment (Chunk startChunk, Segment namePart, string style)
		{
			for (Chunk searchChunk = startChunk; searchChunk != null; searchChunk = searchChunk.Next) {
				if (!searchChunk.Contains (namePart))
					continue;
				if (searchChunk.Length == namePart.Length) {
					searchChunk.Style = style;
					break;
				}
				Chunk propertyChunk = new Chunk (namePart.Offset, namePart.Length, style);
				propertyChunk.Next = searchChunk.Next;
				searchChunk.Next = propertyChunk;
				if (searchChunk.EndOffset - propertyChunk.EndOffset > 0) {
					Chunk newChunk = new Chunk (propertyChunk.EndOffset, searchChunk.EndOffset - propertyChunk.EndOffset, searchChunk.Style);
					newChunk.Next = propertyChunk.Next;
					propertyChunk.Next = newChunk;
				}
				searchChunk.Length = namePart.Offset - searchChunk.Offset;
				break;
			}
		}
	//	string expression;
/*		IMember GetLanguageItem (Mono.TextEditor.Document document, LineSegment line, int offset, string expression)
		{
			string txt = document.Text;
			ExpressionResult expressionResult = new ExpressionResult (expression);
//			ExpressionResult expressionResult = expressionFinder.FindFullExpression (txt, offset);
			int lineNumber = document.OffsetToLineNumber (offset);
			expressionResult.Region = new DomRegion (lineNumber, offset - line.Offset, lineNumber, offset + expression.Length - line.Offset);
			expressionResult.ExpressionContext = ExpressionContext.IdentifierExpected;
			
			resolver = new NRefactoryResolver (ctx, doc.CompilationUnit, doc.TextEditor, document.FileName);
			ResolveResult result = resolver.Resolve (expressionResult, expressionResult.Region.Start);
			
			if (result is MemberResolveResult) 
				return ((MemberResolveResult)result).ResolvedMember;
			return null;
		}*/
		
		public override void Analyze (Mono.TextEditor.Document doc, LineSegment line, Chunk startChunk, int startOffset, int endOffset)
		{
			if (!MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false) || doc == null || line == null || startChunk == null)
				return;
			ctx = GetParserContext (doc);
			int lineNumber = doc.OffsetToLineNumber (line.Offset);
			ParsedDocument parsedDocument = ProjectDomService.GetParsedDocument (ctx, doc.FileName);
			ICompilationUnit unit = parsedDocument != null ? parsedDocument.CompilationUnit : null;
			if (unit == null)
				return;
			for (Chunk chunk = startChunk; chunk != null; chunk = chunk.Next) {
				if (chunk.Style != "text")
					continue;
				for (int i = chunk.Offset; i < chunk.EndOffset; i++) {
					char charBefore = i > 0 ? doc.GetCharAt (i - 1) : '}';
					if (Char.IsLetter (doc.GetCharAt (i)) && !Char.IsLetterOrDigit (charBefore)) {
					} else {
						continue;
					}
					
					int start = i;
					bool wasWhitespace = false;
					bool wasDot = false;
					int bracketCount = 0;
					while (start > 0) {
						char ch = doc.GetCharAt (start);
						if (ch == '\n' || ch == '\r')
							break;
						if (wasWhitespace && IsNamePart(ch)) {
							start++;
							if (start < chunk.Offset)
								start = Int32.MaxValue;
							break;
						}
						if (ch == '<') {
							bracketCount--;
							if (bracketCount < 0) {
								start++;
								break; 
							}
							start--;
							wasWhitespace = false;
							continue;
						}
						if (ch == '>') {
							if (wasWhitespace && !wasDot)
								break;
							bracketCount++;
							start--;
							wasWhitespace = false;
							continue;
						}
						if (!IsNamePart(ch) && !Char.IsWhiteSpace (ch) && ch != '.') {
							start++;
							break;
						}
						wasWhitespace = Char.IsWhiteSpace (ch);
						wasDot = ch == '.' || wasDot && wasWhitespace;
						start--;
					}
					
					int end = i;
					int genericCount = 0;
					wasWhitespace = false;
					List<Segment> nameSegments = new List<Segment> ();
					while (end < chunk.EndOffset) {
						char ch = doc.GetCharAt (end);
						if (wasWhitespace && IsNamePart(ch))
							break;
						if (ch == '<') {
							genericCount = 1;
							while (end < doc.Length) {
								ch = doc.GetCharAt (end);
								if (ch == ',')
									genericCount++;
								if (ch == '>') {
									nameSegments.Add (new Segment (end, 1));
									break;
								}
								end++;
							}
							break;
						}
						if (!IsNamePart(ch) && !Char.IsWhiteSpace (ch)) 
							break;
						wasWhitespace = Char.IsWhiteSpace (ch);
						end++;
					}
					if (start >= end) 
						continue;
					string typeString = doc.GetTextBetween (start, end);
					IReturnType returnType = NRefactoryResolver.ParseReturnType (new ExpressionResult (typeString));
						
					int nameEndOffset = start;
					for (; nameEndOffset < end; nameEndOffset++) {
						char ch = doc.GetCharAt (nameEndOffset);
						if (nameEndOffset >= i && ch == '<') {
							nameEndOffset++;
							break;
						}
					}
					nameSegments.Add (new Segment (i, nameEndOffset - i));

					int column = i - line.Offset;
					IType callingType = unit.GetTypeAt (lineNumber, column);
					List<IReturnType> genericParams = null;
					if (genericCount > 0) {
						genericParams = new List<IReturnType> ();
						for (int n = 0; n < genericCount; n++) 
							genericParams.Add (new DomReturnType ("A"));
					}
					
					IType type = null;
					if (ctx != null)
						type = ctx.SearchType ((MonoDevelop.Projects.Dom.INode)callingType ?? unit, returnType);
					if (type == null && unit != null && returnType != null)
						type = unit.GetType (returnType.FullName, returnType.GenericArguments.Count);
					if (ctx != null && type == null && returnType != null) {
						returnType.Name += "Attribute";
						type = ctx.SearchType ((MonoDevelop.Projects.Dom.INode)callingType ?? unit, returnType);
					}
					if (type != null)
						nameSegments.ForEach (segment => HighlightSegment (startChunk, segment, "keyword.semantic.type"));
				}
			}
		}
Пример #17
0
		public abstract void Analyze (Document doc, LineSegment line, Chunk startChunk, int startOffset, int endOffset);
Пример #18
0
 public override void Analyze(TextDocument doc, DocumentLine line, Chunk startChunk, int startOffset, int endOffset)
 {
     /*if (endOffset > startOffset && startOffset < doc.TextLength && !this.inUpdate)
     {
         this.inUpdate = true;
         try
         {
             string textAt = doc.GetTextAt (startOffset, Math.Min (endOffset, doc.TextLength) - startOffset);
             int num = startOffset - line.Offset;
             List<UrlMarker> list = new List<UrlMarker> ((from m in line.Markers
                 where m is UrlMarker
                 select m).Cast<UrlMarker> ());
             list.ForEach (delegate (UrlMarker m)
                 {
                     doc.RemoveMarker (m, false);
                 });
             IEnumerator enumerator = HighlightUrlSemanticRule.UrlRegex.Matches (textAt).GetEnumerator ();
             try
             {
                 while (enumerator.MoveNext ())
                 {
                     Match match = (Match)enumerator.get_Current ();
                     doc.AddMarker (line, new UrlMarker (doc, line, match.Value, UrlType.Url, this.syntax, num + match.Index, num + match.Index + match.Length), false);
                 }
             }
             finally
             {
                 IDisposable disposable;
                 if ((disposable = (enumerator as IDisposable)) != null)
                 {
                     disposable.Dispose ();
                 }
             }
             IEnumerator enumerator2 = HighlightUrlSemanticRule.MailRegex.Matches (textAt).GetEnumerator ();
             try
             {
                 while (enumerator2.MoveNext ())
                 {
                     Match match2 = (Match)enumerator2.get_Current ();
                     doc.AddMarker (line, new UrlMarker (doc, line, match2.Value, UrlType.Email, this.syntax, num + match2.Index, num + match2.Index + match2.Length), false);
                 }
             }
             finally
             {
                 IDisposable disposable2;
                 if ((disposable2 = (enumerator2 as IDisposable)) != null)
                 {
                     disposable2.Dispose ();
                 }
             }
         }
         finally
         {
             this.inUpdate = false;
         }
     }*/
 }
Пример #19
0
            public void ChangeForeColor(TextEditor editor, Chunk chunk, ref Cairo.Color color)
            {
                if (chunk.Length < 1)
                    return;

                switch (chunk.Style)
                {
                    case "Plain Text":
                    case "Plain Texta":
                        if (!hasEvaluatedBackgroundBrightness)
                        {
                            hasEvaluatedBackgroundBrightness = true;
                            IsDarkBackground = HslColor.Brightness(editor.ColorStyle.PlainText.Background) < 0.5;
                        }

                        color = DiffbasedHighlighting.GetColor(editor.GetTextAt(chunk).Trim());
                        if (IsDarkBackground)
                            color = new Cairo.Color(1.0 - color.R, 1.0 - color.G, 1.0 - color.B, color.A);
                        break;
                    case "String":
                        color = new Cairo.Color(0.8, 0, 0);
                        break;
                    default:
                        if (chunk.Style.StartsWith("Keyword"))
                            chunk.Style = "Plain Text";
                        break;
                }
            }
Пример #20
0
            protected override void AddRealChunk(Chunk chunk)
            {
                if (chunk.Style == "Plain Text")
                {
                    // Prevent 'Plain Text' chunk concatenation by giving following chunks a different style name.
                    if (a = !a)
                        chunk.Style = "Plain Texta";
                }

                base.AddRealChunk(chunk);
            }
Пример #21
0
            protected override void AddRealChunk(Chunk chunk)
            {
                if (spanParser.CurSpan != null && (spanParser.CurSpan.Rule == "Comment" || spanParser.CurSpan.Rule == "PreProcessorComment"))
                {
                    base.AddRealChunk(chunk);
                    return;
                }
                var syn = mode as DSyntaxMode;
                foreach (var m in syn.segmentMarkerTree.GetSegmentsAt(chunk.Offset))
                {
                    var tm = m as TypeIdSegmMarker;
                    if (tm != null && tm.IsVisible)
                    {
                        var endLoc = tm.EndOffset;
                        if (endLoc < chunk.EndOffset)
                        {
                            base.AddRealChunk(new Chunk(chunk.Offset, endLoc - chunk.Offset, tm.Style));
                            base.AddRealChunk(new Chunk(endLoc, chunk.EndOffset - endLoc, chunk.Style));
                            return;
                        }
                        chunk.Style = tm.Style;
                        break;
                    }
                }

                base.AddRealChunk(chunk);
            }