static bool IsMatchAt (TextEditor editor, int offset, string abbrevWord)
		{
			if (offset + abbrevWord.Length >= editor.Length)
				return false;
			if (offset > 0 && IsIdentifierPart (editor.GetCharAt (offset - 1)))
				return false;
			if (offset + abbrevWord.Length < editor.Length && !IsIdentifierPart (editor.GetCharAt (offset + abbrevWord.Length)))
				return false;
			return editor.GetTextAt (offset, abbrevWord.Length) == abbrevWord;
		}
		public static Task<RefactoringSymbolInfo> GetSymbolInfoAsync (DocumentContext document, TextEditor editor, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (editor.IsSomethingSelected) {
				var selectionRange = editor.SelectionRange;
				if (editor.GetTextAt (selectionRange).Any (ch => !char.IsLetterOrDigit (ch) && ch !='_')) {
					return Task.FromResult (RefactoringSymbolInfo.Empty);
				}
				return GetSymbolInfoAsync (document, selectionRange.Offset, cancellationToken);
			}
			return GetSymbolInfoAsync (document, editor.CaretOffset, cancellationToken);
		}
		public override async Task<TooltipItem> GetItem (TextEditor editor, DocumentContext ctx, int offset, CancellationToken token = default(CancellationToken))
		{
			if (offset >= editor.Length)
				return null;

			if (!DebuggingService.IsDebugging || DebuggingService.IsRunning)
				return null;

			StackFrame frame = DebuggingService.CurrentFrame;
			if (frame == null)
				return null;

			var ed = CompileErrorTooltipProvider.GetExtensibleTextEditor (editor);
			if (ed == null)
				return null;
			string expression = null;
			int startOffset;

			if (ed.IsSomethingSelected && offset >= ed.SelectionRange.Offset && offset <= ed.SelectionRange.EndOffset) {
				startOffset = ed.SelectionRange.Offset;
				expression = ed.SelectedText;
			} else {
				var doc = ctx;
				if (doc == null || doc.ParsedDocument == null)
					return null;

				var resolver = doc.GetContent<IDebuggerExpressionResolver> ();
				var data = doc.GetContent<SourceEditorView> ();

				if (resolver != null) {
					var result = await resolver.ResolveExpressionAsync (editor, doc, offset, token);
					expression = result.Text;
					startOffset = result.Span.Start;
				} else {
					int endOffset = data.GetTextEditorData ().FindCurrentWordEnd (offset);
					startOffset = data.GetTextEditorData ().FindCurrentWordStart (offset);

					expression = editor.GetTextAt (startOffset, endOffset - startOffset);
				}
			}
			
			if (string.IsNullOrEmpty (expression))
				return null;

			var options = DebuggingService.DebuggerSession.EvaluationOptions.Clone ();
			options.AllowMethodEvaluation = true;
			options.AllowTargetInvoke = true;

			var val = frame.GetExpressionValue (expression, options);

			if (val == null || val.IsUnknown || val.IsNotSupported)
				return null;
			
			val.Name = expression;
			
			return new TooltipItem (val, startOffset, expression.Length);
		}
Exemple #4
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;
                }
            }