void OnEditKeyPress(object s, Gtk.KeyPressEventArgs args)
        {
            Gtk.Entry entry = (Gtk.Entry)s;

            if (currentCompletionData != null)
            {
                KeyActions ka;
                bool       ret = CompletionWindowManager.PreProcessKeyEvent(args.Event.Key, (char)args.Event.Key, args.Event.State, out ka);
                CompletionWindowManager.PostProcessKeyEvent(ka);
                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(c, dataList, this, ctx, OnCompletionWindowClosed);
                    }
                    else
                    {
                        currentCompletionData = null;
                    }
                }
            });
        }
 public DebugCompletionDataList(Mono.Debugging.Client.CompletionData data)
 {
     IsSorted = false;
     foreach (CompletionItem it in data.Items)
     {
         Add(new DebugCompletionData(it));
     }
 }
 void OnEndEditing()
 {
     editing = false;
     editEntry.KeyPressEvent -= OnEditKeyPress;
     CompletionWindowManager.HideWindow();
     currentCompletionData = null;
     if (EndEditing != null)
     {
         EndEditing(this, EventArgs.Empty);
     }
 }
示例#4
0
		public virtual CompletionData GetExpressionCompletionData (EvaluationContext ctx, string exp)
		{
			int i;
			if (exp.Length == 0)
				return null;

			if (exp [exp.Length - 1] == '.') {
				exp = exp.Substring (0, exp.Length - 1);
				i = 0;
				while (i < exp.Length) {
					ValueReference vr = null;
					try {
						vr = ctx.Evaluator.Evaluate (ctx, exp.Substring (i), null);
						if (vr != null) {
							CompletionData data = new CompletionData ();
							foreach (ValueReference cv in vr.GetChildReferences (ctx.Options))
								data.Items.Add (new CompletionItem (cv.Name, cv.Flags));
							data.ExpressionLenght = 0;
							return data;
						}
					} catch (Exception ex) {
						ctx.WriteDebuggerError (ex);
					}
					i++;
				}
				return null;
			}
			
			i = exp.Length - 1;
			bool lastWastLetter = false;
			while (i >= 0) {
				char c = exp [i--];
				if (!char.IsLetterOrDigit (c) && c != '_')
					break;
				lastWastLetter = !char.IsDigit (c);
			}
			if (lastWastLetter) {
				string partialWord = exp.Substring (i+1);
				
				CompletionData data = new CompletionData ();
				data.ExpressionLenght = partialWord.Length;
				
				// Local variables
				
				foreach (ValueReference vc in GetLocalVariables (ctx))
					if (vc.Name.StartsWith (partialWord))
						data.Items.Add (new CompletionItem (vc.Name, vc.Flags));
				
				// Parameters
				
				foreach (ValueReference vc in GetParameters (ctx))
					if (vc.Name.StartsWith (partialWord))
						data.Items.Add (new CompletionItem (vc.Name, vc.Flags));
				
				// Members
				
				ValueReference thisobj = GetThisReference (ctx);
				
				if (thisobj != null)
					data.Items.Add (new CompletionItem ("this", ObjectValueFlags.Field | ObjectValueFlags.ReadOnly));

				object type = GetEnclosingType (ctx);
				
				foreach (ValueReference vc in GetMembers (ctx, null, type, thisobj != null ? thisobj.Value : null))
					if (vc.Name.StartsWith (partialWord))
						data.Items.Add (new CompletionItem (vc.Name, vc.Flags));
				
				if (data.Items.Count > 0)
					return data;
			}
			return null;
		}
        public virtual CompletionData GetExpressionCompletionData(EvaluationContext ctx, string expr)
        {
            if (string.IsNullOrEmpty (expr))
                return null;

            if (expr[expr.Length - 1] == '.') {
                try {
                    var vr = ctx.Evaluator.Evaluate (ctx, expr.Substring (0, expr.Length - 1), null);
                    if (vr != null)
                        return GetMemberCompletionData (ctx, vr);

                    // FIXME: handle types and namespaces...
                } catch (Exception ex) {
                    ctx.WriteDebuggerError (ex);
                }

                return null;
            }

            bool lastWastLetter = false;
            int i = expr.Length - 1;

            while (i >= 0) {
                char c = expr[i--];
                if (!char.IsLetterOrDigit (c) && c != '_')
                    break;

                lastWastLetter = !char.IsDigit (c);
            }

            if (lastWastLetter) {
                string partialWord = expr.Substring (i+1);

                CompletionData data = new CompletionData ();
                data.ExpressionLength = partialWord.Length;

                // Local variables

                foreach (ValueReference vc in GetLocalVariables (ctx))
                    if (vc.Name.StartsWith (partialWord, StringComparison.InvariantCulture))
                        data.Items.Add (new CompletionItem (vc.Name, vc.Flags));

                // Parameters

                foreach (ValueReference vc in GetParameters (ctx))
                    if (vc.Name.StartsWith (partialWord, StringComparison.InvariantCulture))
                        data.Items.Add (new CompletionItem (vc.Name, vc.Flags));

                // Members

                ValueReference thisobj = GetThisReference (ctx);

                if (thisobj != null)
                    data.Items.Add (new CompletionItem ("this", ObjectValueFlags.Field | ObjectValueFlags.ReadOnly));

                object type = GetEnclosingType (ctx);

                foreach (ValueReference vc in GetMembers (ctx, null, type, thisobj != null ? thisobj.Value : null))
                    if (vc.Name.StartsWith (partialWord, StringComparison.InvariantCulture))
                        data.Items.Add (new CompletionItem (vc.Name, vc.Flags));

                if (data.Items.Count > 0)
                    return data;
            }

            return null;
        }
        protected virtual CompletionData GetMemberCompletionData(EvaluationContext ctx, ValueReference vr)
        {
            var data = new CompletionData ();

            foreach (ValueReference cv in vr.GetChildReferences (ctx.Options))
                data.Items.Add (new CompletionItem (cv.Name, cv.Flags));

            data.ExpressionLength = 0;

            return data;
        }
示例#7
0
		public CompletionData GetExpressionCompletionData (int frameIndex, string exp)
		{
			SelectFrame (frameIndex);
			
			bool pointer = exp.EndsWith ("->");
			int i;
			
			if (pointer || exp.EndsWith (".")) {
				exp = exp.Substring (0, exp.Length - (pointer ? 2 : 1));
				i = 0;
				while (i < exp.Length) {
					ObjectValue val = CreateVarObject (exp);
					if (!val.IsUnknown && !val.IsError) {
						CompletionData data = new CompletionData ();
						foreach (ObjectValue cv in val.GetAllChildren ())
							data.Items.Add (new CompletionItem (cv.Name, cv.Flags));
						data.ExpressionLenght = 0;
						return data;
					}
					i++;
				}
				return null;
			}
			
			i = exp.Length - 1;
			bool lastWastLetter = false;
			while (i >= 0) {
				char c = exp [i--];
				if (!char.IsLetterOrDigit (c) && c != '_')
					break;
				lastWastLetter = !char.IsDigit (c);
			}
			
			if (lastWastLetter) {
				string partialWord = exp.Substring (i+1);
				
				CompletionData cdata = new CompletionData ();
				cdata.ExpressionLenght = partialWord.Length;
				
				// Local variables
				
				GdbCommandResult res = session.RunCommand ("-stack-list-locals", "0");
				foreach (ResultData data in res.GetObject ("locals")) {
					string name = data.GetValue ("name");
					if (name.StartsWith (partialWord))
						cdata.Items.Add (new CompletionItem (name, ObjectValueFlags.Variable));
				}
				
				// Parameters
				
				res = session.RunCommand ("-stack-list-arguments", "0", frameIndex.ToString (), frameIndex.ToString ());
				foreach (ResultData data in res.GetObject ("stack-args").GetObject (0).GetObject ("frame").GetObject ("args")) {
					string name = data.GetValue ("name");
					if (name.StartsWith (partialWord))
						cdata.Items.Add (new CompletionItem (name, ObjectValueFlags.Parameter));
				}
				
				if (cdata.Items.Count > 0)
					return cdata;
			}			
			return null;
		}
        public async Task <CompletionData> GetExpressionCompletionDataAsync(string exp, StackFrame frame, CancellationToken token)
        {
            var location = frame.SourceLocation;

            if (document == null)
            {
                return(null);
            }
            var solution     = document.Project.Solution;
            var textSnapshot = textBuffer.CurrentSnapshot;
            var text         = textSnapshot.GetText(new Span(0, textSnapshot.Length));
            var insertOffset = await GetAdjustedContextPointAsync(textSnapshot.GetLineFromLineNumber (location.EndLine - 1).Start.Position + location.EndColumn - 1, document, token).ConfigureAwait(false);

            text = text.Insert(insertOffset, ";" + exp + ";");
            insertOffset++;            //advance for 1 which represents `;` before expression
            var newTextBuffer = PlatformCatalog.Instance.TextBufferFactoryService.CreateTextBuffer(text, textBuffer.ContentType);
            var snapshot      = newTextBuffer.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, newTextBuffer.AsTextContainer());
            foreach (var link in document.GetLinkedDocumentIds())
            {
                forkedWorkspace.OpenDocument(link, newTextBuffer.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);
        }
 void OnCompletionWindowClosed()
 {
     currentCompletionData = null;
 }