Ejemplo n.º 1
0
        async void PopupCompletion(Entry entry)
        {
            try {
                char c = (char)Gdk.Keyval.ToUnicode(keyValue);
                if (currentCompletionData == null && IsCompletionChar(c))
                {
                    string expr = entry.Text.Substring(0, entry.CursorPosition);
                    cts.Cancel();
                    cts = new CancellationTokenSource();
                    if (valueTree.Frame == null)
                    {
                        return;
                    }
                    currentCompletionData = await DebuggingService.GetCompletionDataAsync(valueTree.Frame, expr, cts.Token);

                    if (currentCompletionData != null)
                    {
                        DebugCompletionDataList dataList = new DebugCompletionDataList(currentCompletionData);
                        ctx = ((ICompletionWidget)this).CreateCodeCompletionContext(expr.Length - currentCompletionData.ExpressionLength);
                        CompletionWindowManager.ShowWindow(null, c, dataList, this, ctx);
                    }
                }
            } catch (OperationCanceledException) {
            }
        }
        void OnEditKeyPress(object s, Gtk.KeyPressEventArgs args)
        {
            Gtk.Entry entry = (Gtk.Entry)s;

            if (currentCompletionData != null)
            {
                bool ret = CompletionWindowManager.PreProcessKeyEvent(args.Event.Key, (char)args.Event.Key, args.Event.State);
                CompletionWindowManager.PostProcessKeyEvent(args.Event.Key, (char)args.Event.Key, args.Event.State);
                args.RetVal = ret;
            }

            Gtk.Application.Invoke(delegate {
                char c = (char)Gdk.Keyval.ToUnicode(args.Event.KeyValue);
                if (currentCompletionData == null && IsCompletionChar(c))
                {
                    string exp            = entry.Text.Substring(0, entry.CursorPosition);
                    currentCompletionData = GetCompletionData(exp);
                    if (currentCompletionData != null)
                    {
                        DebugCompletionDataList dataList = new DebugCompletionDataList(currentCompletionData);
                        CodeCompletionContext ctx        = ((ICompletionWidget)this).CreateCodeCompletionContext(entry.CursorPosition - currentCompletionData.ExpressionLenght);
                        CompletionWindowManager.ShowWindow(null, c, dataList, this, ctx);
                    }
                    else
                    {
                        currentCompletionData = null;
                    }
                }
            });
        }
Ejemplo n.º 3
0
		void PopupCompletion ()
		{
			Gtk.Application.Invoke (delegate {
				char c = (char) Gdk.Keyval.ToUnicode (keyValue);
				if (currentCompletionData == null && IsCompletionChar (c)) {
					string expr = Buffer.GetText (TokenBegin, Cursor, false);
					currentCompletionData = GetCompletionData (expr);
					if (currentCompletionData != null) {
						DebugCompletionDataList dataList = new DebugCompletionDataList (currentCompletionData);
						ctx = ((ICompletionWidget) this).CreateCodeCompletionContext (expr.Length - currentCompletionData.ExpressionLength);
						CompletionWindowManager.ShowWindow (null, c, dataList, this, ctx);
					} else {
						currentCompletionData = null;
					}
				}
			});
		}
Ejemplo n.º 4
0
        void PopupCompletion()
        {
            char c = (char)Gdk.Keyval.ToUnicode(keyValue);

            if (currentCompletionData == null && IsCompletionChar(c))
            {
                string expr = Buffer.GetText(TokenBegin, Cursor, false);
                currentCompletionData = GetCompletionData(expr);
                if (currentCompletionData != null)
                {
                    DebugCompletionDataList dataList = new DebugCompletionDataList(currentCompletionData);
                    ctx = ((ICompletionWidget)this).CreateCodeCompletionContext(expr.Length - currentCompletionData.ExpressionLength);
                    CompletionWindowManager.ShowWindow(null, c, dataList, this, ctx);
                }
                else
                {
                    currentCompletionData = null;
                }
            }
        }
        void PopupCompletion(Entry entry)
        {
            char c = (char)Gdk.Keyval.ToUnicode(keyValue);

            if (currentCompletionData == null && IsCompletionChar(c))
            {
                string expr = entry.Text.Substring(0, entry.CursorPosition);
                currentCompletionData = GetCompletionData(expr);
                if (currentCompletionData != null)
                {
                    DebugCompletionDataList dataList = new DebugCompletionDataList(currentCompletionData);
                    ctx = ((ICompletionWidget)this).CreateCodeCompletionContext(expr.Length - currentCompletionData.ExpressionLength);
                    CompletionWindowManager.ShowWindow(null, c, dataList, this, ctx);
                }
                else
                {
                    currentCompletionData = null;
                }
            }
        }
Ejemplo n.º 6
0
		void OnCompletionWindowClosed (object sender, EventArgs e)
		{
			currentCompletionData = null;
		}
 void HandleCompletionWindowClosed(object sender, EventArgs e)
 {
     currentCompletionData = null;
 }
		void OnEditKeyPress (object s, Gtk.KeyPressEventArgs args)
		{
			Gtk.Entry entry = (Gtk.Entry)s;
			
			if (currentCompletionData != null) {
				bool ret = CompletionWindowManager.PreProcessKeyEvent (args.Event.Key, (char)args.Event.Key, args.Event.State);
				CompletionWindowManager.PostProcessKeyEvent (args.Event.Key, (char)args.Event.Key, args.Event.State);
				args.RetVal = ret;
			}
			
			Gtk.Application.Invoke (delegate {
				char c = (char)Gdk.Keyval.ToUnicode (args.Event.KeyValue);
				if (currentCompletionData == null && IsCompletionChar (c)) {
					string exp = entry.Text.Substring (0, entry.CursorPosition);
					currentCompletionData = GetCompletionData (exp);
					if (currentCompletionData != null) {
						DebugCompletionDataList dataList = new DebugCompletionDataList (currentCompletionData);
						CodeCompletionContext ctx = ((ICompletionWidget)this).CreateCodeCompletionContext (entry.CursorPosition - currentCompletionData.ExpressionLenght);
						CompletionWindowManager.ShowWindow (null, c, dataList, this, ctx);
					} else
						currentCompletionData = null;
				}
			});
		}
		private void HandleCompletionWindowClosed (object sender, EventArgs e)
		{
			currentCompletionData = null;
		}
Ejemplo n.º 10
0
		void PopupCompletion (Entry entry)
		{
			Application.Invoke (delegate {
				char c = (char) Gdk.Keyval.ToUnicode (keyValue);
				if (currentCompletionData == null && IsCompletionChar (c)) {
					string exp = entry.Text.Substring (0, entry.CursorPosition);
					currentCompletionData = GetCompletionData (exp);
					if (currentCompletionData != null) {
						DebugCompletionDataList dataList = new DebugCompletionDataList (currentCompletionData);
						ctx = ((ICompletionWidget) this).CreateCodeCompletionContext (entry.CursorPosition - currentCompletionData.ExpressionLength);
						CompletionWindowManager.ShowWindow (null, c, dataList, this, ctx);
					} else {
						currentCompletionData = null;
					}
				}
			});
		}
		void OnEditKeyPress (object sender, KeyPressEventArgs args)
		{
			if (currentCompletionData != null) {
				char keyChar = (char)args.Event.Key;
				if ((args.Event.Key == Gdk.Key.Down || args.Event.Key == Gdk.Key.Up)) {
					keyChar = '\0';
				}
				var retVal = CompletionWindowManager.PreProcessKeyEvent (args.Event.Key, keyChar, args.Event.State);
				CompletionWindowManager.PostProcessKeyEvent (args.Event.Key, keyChar, args.Event.State);
				args.RetVal = retVal;
			}
			
			Application.Invoke (delegate {
				char c = (char)Gdk.Keyval.ToUnicode (args.Event.KeyValue);
				if (currentCompletionData == null && IsCompletionChar (c)) {
					string exp = entry.Text.Substring (0, entry.CursorPosition);
					currentCompletionData = GetCompletionData (exp);
					if (currentCompletionData != null) {
						DebugCompletionDataList dataList = new DebugCompletionDataList (currentCompletionData);
						CodeCompletionContext ctx = ((ICompletionWidget)this).CreateCodeCompletionContext (entry.CursorPosition - currentCompletionData.ExpressionLength);
						CompletionWindowManager.ShowWindow (null, c, dataList, this, ctx);
					}
				}
			});
		}
        public async Task <Mono.Debugging.Client.CompletionData> GetExpressionCompletionData(string exp, Mono.Debugging.Client.StackFrame frame, CancellationToken token)
        {
            var location = frame.SourceLocation;
            var document = DocumentContext.AnalysisDocument;

            if (document == null)
            {
                return(null);
            }
            var solution         = DocumentContext.RoslynWorkspace.CurrentSolution;
            var originalSnapshot = Editor.TextView.TextBuffer.CurrentSnapshot;
            var text             = originalSnapshot.GetText(new Span(0, originalSnapshot.Length));
            var insertOffset     = GetAdjustedContextPoint(originalSnapshot.GetLineFromLineNumber(location.EndLine - 1).Start.Position + location.EndColumn - 1, document);

            text = text.Insert(insertOffset, ";" + exp + ";");
            insertOffset++;            //advance for 1 which represents `;` before expression
            var textBuffer = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer(text, Editor.TextView.TextBuffer.ContentType);
            var snapshot   = textBuffer.CurrentSnapshot;

            try {
                //Workaround Mono bug: https://github.com/mono/mono/issues/8700
                snapshot.AsText();
            } catch (Exception) {
            }

            // Fork the solution using this new primary buffer for the document and all of its linked documents.
            var forkedSolution = solution.WithDocumentText(document.Id, snapshot.AsText(), PreservationMode.PreserveIdentity);

            foreach (var link in document.GetLinkedDocumentIds())
            {
                forkedSolution = forkedSolution.WithDocumentText(link, snapshot.AsText(), PreservationMode.PreserveIdentity);
            }

            // Put it into a new workspace, and open it and its related documents
            // with the projection buffer as the text.
            var forkedWorkspace = new DebuggerIntelliSenseWorkspace(forkedSolution);

            forkedWorkspace.OpenDocument(document.Id, textBuffer.AsTextContainer());
            foreach (var link in document.GetLinkedDocumentIds())
            {
                forkedWorkspace.OpenDocument(link, textBuffer.AsTextContainer());
            }
            var cs                = forkedWorkspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService <CompletionService> ();
            var trigger           = new CompletionTrigger(CompletionTriggerKind.Invoke, '\0');
            var roslynCompletions = await cs.GetCompletionsAsync(forkedWorkspace.CurrentSolution.GetDocument(document.Id), insertOffset + exp.Length, trigger, cancellationToken : token).ConfigureAwait(false);

            if (roslynCompletions == null)
            {
                return(null);
            }
            var result = new Mono.Debugging.Client.CompletionData();

            foreach (var roslynCompletion in roslynCompletions.Items)
            {
                if (roslynCompletion.Tags.Contains(WellKnownTags.Snippet))
                {
                    continue;
                }
                result.Items.Add(new Mono.Debugging.Client.CompletionItem(roslynCompletion.DisplayText, RoslynTagsToDebuggerFlags(roslynCompletion.Tags)));
            }
            result.ExpressionLength = roslynCompletions.Span.Length;
            return(result);
        }