public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
        {
            int           caretLineNumber = editor.Caret.Line;
            int           caretColumn     = editor.Caret.Column;
            IDocumentLine caretLine       = editor.Document.GetLine(caretLineNumber);
            string        lineText        = caretLine.Text;

            if (!lineText.Trim().StartsWith("///", StringComparison.Ordinal) &&
                !lineText.Trim().StartsWith("'''", StringComparison.Ordinal))
            {
                return(null);
            }

            DefaultCompletionItemList list = new DefaultCompletionItemList();

            foreach (string[] tag in commentTags)
            {
                list.Items.Add(new DefaultCompletionItem(tag[0])
                {
                    Description = tag[1]
                });
            }
            list.SortItems();
            return(list);
        }
		public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
		{
			DefaultCompletionItemList list = new DefaultCompletionItemList();
			foreach (string text in this.texts) {
				list.Items.Add(new DefaultCompletionItem(text) { Image = ClassBrowserIconService.GotoArrow });
			}
			list.SortItems();
			return list;
		}
		void AddTemplates(ITextEditor editor, DefaultCompletionItemList list)
		{
			if (list == null)
				return;
			List<ICompletionItem> snippets = editor.GetSnippets().ToList();
			snippets.RemoveAll(item => !FitsToContext(item, list.Items));
			list.Items.RemoveAll(item => item.Image == ClassBrowserIconService.Keyword && snippets.Exists(i => i.Text == item.Text));
			list.Items.AddRange(snippets);
			list.SortItems();
		}
        public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
        {
            CompletionInfo result = context.GetCompletionItems(
                editor.FileName,
                editor.Caret.Offset - 1,
                editor.Document.Text,
                memberCompletion);

            var itemList = new DefaultCompletionItemList();
            itemList.Items.AddRange(result.entries.Select(entry => new TypeScriptCompletionItem(entry)));
            return itemList;
        }
Esempio n. 5
0
        void AddTemplates(ITextEditor editor, DefaultCompletionItemList list)
        {
            if (list == null)
            {
                return;
            }
            List <ICompletionItem> snippets = editor.GetSnippets().ToList();

            snippets.RemoveAll(item => !FitsToContext(item, list.Items));
            list.Items.RemoveAll(item => item.Image == ClassBrowserIconService.Keyword && snippets.Exists(i => i.Text == item.Text));
            list.Items.AddRange(snippets);
            list.SortItems();
        }
        internal static ICompletionItemList GenerateCompletionList(IList<string> texts, IList<string> descriptions = null, IList<IImage> images = null)
        {
            var list = new DefaultCompletionItemList();
            for(int i = 0; i < texts.Count; ++i){
                var item = new DefaultCompletionItem(texts[i]);
                item.Description = (descriptions != null) ? descriptions[i] : "";
                item.Image = (images != null) ? images[i] : null;
                list.Items.Add(item);
            }

            list.SortItems();
            return list;
        }
Esempio n. 7
0
        public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
        {
            DefaultCompletionItemList list = new DefaultCompletionItemList();

            foreach (string text in this.texts)
            {
                list.Items.Add(new DefaultCompletionItem(text)
                {
                    Image = ClassBrowserIconService.GotoArrow
                });
            }
            list.SortItems();
            return(list);
        }
        public static DefaultCompletionItemList ConvertCompletionData(DefaultCompletionItemList result, List <ICompletionEntry> arr, ExpressionContext context)
        {
            if (arr == null)
            {
                return(result);
            }

            Dictionary <string, CodeCompletionItem> methodItems = new Dictionary <string, CodeCompletionItem>();

            foreach (ICompletionEntry o in arr)
            {
                if (context != null && !context.ShowEntry(o))
                {
                    continue;
                }

                IMethod method = o as IMethod;
                if (method != null)
                {
                    CodeCompletionItem codeItem;
                    if (methodItems.TryGetValue(method.Name, out codeItem))
                    {
                        codeItem.Overloads++;
                        continue;
                    }
                }

                ICompletionItem item = CreateCompletionItem(o, context);
                if (item != null)
                {
                    result.Items.Add(item);
                    CodeCompletionItem codeItem = item as CodeCompletionItem;
                    if (method != null && codeItem != null)
                    {
                        methodItems[method.Name] = codeItem;
                    }
                }
            }

            // Suggested entry (List<int> a = new => suggest List<int>).
            if (context.SuggestedItem is SuggestedCodeCompletionItem)
            {
                result.SuggestedItem = (SuggestedCodeCompletionItem)context.SuggestedItem;
                result.Items.Insert(0, result.SuggestedItem);
            }
            return(result);
        }
Esempio n. 9
0
		/// <summary>
		/// Starts the command
		/// </summary>
		public override void Run()
		{
			ITextEditor editor = SD.GetActiveViewContentService<ITextEditor>();
			if (editor == null)
				return;
			
			CodeSnippetGroup group = SnippetManager.Instance.FindGroup(Path.GetExtension(editor.FileName));
			
			if (group == null)
				return;
			
			DefaultCompletionItemList list = new DefaultCompletionItemList();
			
			list.Items.AddRange(group.Snippets.Where(i => i.HasSelection).Select(item => item.CreateCompletionItem(editor)));
			
			new CodeSnippetCompletionWindow(editor, list).Show();
		}
Esempio n. 10
0
		/// <summary>
		/// Starts the command
		/// </summary>
		public override void Run()
		{
			ICodeEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ICodeEditorProvider;
			
			if (provider == null)
				return;
			
			CodeSnippetGroup group = SnippetManager.Instance.FindGroup(Path.GetExtension(provider.TextEditor.FileName));
			
			if (group == null)
				return;
			
			DefaultCompletionItemList list = new DefaultCompletionItemList();
			
			list.Items.AddRange(group.Snippets.Where(i => i.HasSelection).Select(item => item.CreateCompletionItem(provider.TextEditor)));
			
			new CodeSnippetCompletionWindow(provider.TextEditor, list).Show();
		}
		public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
		{
			int caretLineNumber = editor.Caret.Line;
			int caretColumn     = editor.Caret.Column;
			IDocumentLine caretLine = editor.Document.GetLine(caretLineNumber);
			string lineText = caretLine.Text;
			if (!lineText.Trim().StartsWith("///", StringComparison.Ordinal)
			    && !lineText.Trim().StartsWith("'''", StringComparison.Ordinal)) 
			{
				return null;
			}
			
			DefaultCompletionItemList list = new DefaultCompletionItemList();
			foreach (string[] tag in commentTags) {
				list.Items.Add(new DefaultCompletionItem(tag[0]) { Description = tag[1] });
			}
			list.SortItems();
			return list;
		}
		public ICompletionItemList GenerateCompletionList(ITextEditor editor)
		{
			CompletionInfo result = context.GetCompletionItems(
				editor.FileName,
				editor.Caret.Offset,
				editor.Document.Text,
				memberCompletion);
			
			var itemList = new DefaultCompletionItemList();
			if (result != null) {
				
				var completionDetailsProvider = new CompletionEntryDetailsProvider(
					context,
					editor.FileName,
					editor.Caret.Offset);
				
				itemList.Items.AddRange(result.entries.Select(entry => new TypeScriptCompletionItem(entry, completionDetailsProvider)));
				itemList.SortItems();
			}
			return itemList;
		}
Esempio n. 13
0
 protected override void InitializeCompletionItemList(DefaultCompletionItemList list)
 {
     base.InitializeCompletionItemList(list);
     list.PreselectionLength = preselectionLength;
 }
		bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace)
		{
			var completionContext = CSharpCompletionContext.Get(editor);
			if (completionContext == null)
				return false;
			
			var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret));
			CSharpCompletionEngine cce = new CSharpCompletionEngine(
				editor.Document,
				completionContext.CompletionContextProvider,
				completionFactory,
				completionContext.ProjectContent,
				completionContext.TypeResolveContextAtCaret
			);
			
			cce.FormattingPolicy = FormattingOptionsFactory.CreateSharpDevelop();
			cce.EolMarker = DocumentUtilities.GetLineTerminator(editor.Document, editor.Caret.Line);
			cce.IndentString = editor.Options.IndentationString;
			
			int startPos, triggerWordLength;
			IEnumerable<ICompletionData> completionData;
			if (ctrlSpace) {
				if (!cce.TryGetCompletionWord(editor.Caret.Offset, out startPos, out triggerWordLength)) {
					startPos = editor.Caret.Offset;
					triggerWordLength = 0;
				}
				completionData = cce.GetCompletionData(startPos, true);
				completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
			} else {
				startPos = editor.Caret.Offset;
				if (char.IsLetterOrDigit (completionChar) || completionChar == '_') {
					if (startPos > 1 && char.IsLetterOrDigit (editor.Document.GetCharAt (startPos - 2)))
						return false;
					completionData = cce.GetCompletionData(startPos, false);
					startPos--;
					triggerWordLength = 1;
				} else {
					completionData = cce.GetCompletionData(startPos, false);
					triggerWordLength = 0;
				}
			}
			
			DefaultCompletionItemList list = new DefaultCompletionItemList();
			list.Items.AddRange(completionData.Cast<ICompletionItem>());
			if (list.Items.Count > 0) {
				list.SortItems();
				list.PreselectionLength = editor.Caret.Offset - startPos;
				list.PostselectionLength = Math.Max(0, startPos + triggerWordLength - editor.Caret.Offset);
				list.SuggestedItem = list.Items.FirstOrDefault(i => i.Text == cce.DefaultCompletionString);
				editor.ShowCompletionWindow(list);
				return true;
			}
			
			if (!ctrlSpace) {
				// Method Insight
				var pce = new CSharpParameterCompletionEngine(
					editor.Document,
					completionContext.CompletionContextProvider,
					completionFactory,
					completionContext.ProjectContent,
					completionContext.TypeResolveContextAtCaret
				);
				var newInsight = pce.GetParameterDataProvider(editor.Caret.Offset, completionChar) as CSharpMethodInsight;
				if (newInsight != null && newInsight.items.Count > 0) {
					newInsight.UpdateHighlightedParameter(pce);
					newInsight.Show();
					return true;
				}
			}
			return false;
		}
		void AddClosingTagCompletion(XamlContext context, DefaultCompletionItemList list, XamlAstResolver resolver)
		{
			if (context.ParentElement != null && !context.InRoot) {
				ResolveResult rr = resolver.ResolveElement(context.ParentElement);
				TypeResolveResult trr = rr as TypeResolveResult;
				MemberResolveResult mrr = rr as MemberResolveResult;

				if (trr != null) {
					if (trr.IsError) return;
					list.Items.Add(new XamlCompletionItem("/" + context.ParentElement.Name, trr.Type.GetDefinition()));
				} else if (mrr != null) {
					if (mrr.IsError) return;
					list.Items.Add(new XamlCompletionItem("/" + context.ParentElement.Name, mrr.Member));
				}
			}
		}
		public static DefaultCompletionItemList ConvertCompletionData(DefaultCompletionItemList result, List<ICompletionEntry> arr, ExpressionContext context)
		{
			if (arr == null)
				return result;
			
			Dictionary<string, CodeCompletionItem> methodItems = new Dictionary<string, CodeCompletionItem>();
			foreach (ICompletionEntry o in arr) {
				if (context != null && !context.ShowEntry(o))
					continue;
				
				IMethod method = o as IMethod;
				if (method != null) {
					CodeCompletionItem codeItem;
					if (methodItems.TryGetValue(method.Name, out codeItem)) {
						codeItem.Overloads++;
						continue;
					}
				}
				
				ICompletionItem item = CreateCompletionItem(o, context);
				if (item != null) {
					result.Items.Add(item);
					CodeCompletionItem codeItem = item as CodeCompletionItem;
					if (method != null && codeItem != null) {
						methodItems[method.Name] = codeItem;
					}
				}
			}
			
			// Suggested entry (List<int> a = new => suggest List<int>).
			if (context.SuggestedItem is SuggestedCodeCompletionItem) {
				result.SuggestedItem = (SuggestedCodeCompletionItem)context.SuggestedItem;
				result.Items.Insert(0, result.SuggestedItem);
			}
			return result;
		}
		protected virtual void InitializeCompletionItemList(DefaultCompletionItemList list)
		{
			list.SortItems();
		}
		public override ICompletionItemList GenerateCompletionList(ITextEditor editor)
		{
			DefaultCompletionItemList result = new DefaultCompletionItemList();
			result.InsertSpace = true;
			
			// delegate {  }
			result.Items.Add(new DelegateCompletionItem("delegate {  };", 3,
			                                           "${res:CSharpBinding.InsertAnonymousMethod}"));

			CSharpAmbience ambience = new CSharpAmbience();
			// get eventHandler type name incl. type argument list
			ambience.ConversionFlags = ConversionFlags.ShowParameterNames | ConversionFlags.ShowTypeParameterList | ConversionFlags.UseFullyQualifiedTypeNames;
			string eventHandlerFullyQualifiedTypeName = ambience.Convert(resolvedReturnType);
			ambience.ConversionFlags = ConversionFlags.ShowParameterNames | ConversionFlags.ShowTypeParameterList;
			string eventHandlerTypeName = ambience.Convert(resolvedReturnType);
			
			// retrieve Invoke method from resolvedReturnType instead of resolvedClass to get a method where
			// type arguments are substituted.
			IMethod invoke = resolvedReturnType.GetMethods().Find(delegate(IMethod m) { return m.Name == "Invoke"; });
			StringBuilder parameterString = new StringBuilder();
			if (invoke != null) {
				
				// build the parameter string
				for (int i = 0; i < invoke.Parameters.Count; ++i) {
					if (i > 0) {
						parameterString.Append(", ");
					}
					
					parameterString.Append(ambience.Convert(invoke.Parameters[i]));
				}
				
				// delegate(object sender, EventArgs e) {  };
				StringBuilder anonMethodWithParametersBuilder =
					new StringBuilder("delegate(").Append(parameterString.ToString()).Append(") {  };");
				result.Items.Add(new DelegateCompletionItem(anonMethodWithParametersBuilder.ToString(), 3,
				                                            "${res:CSharpBinding.InsertAnonymousMethodWithParameters}"));

				// new EventHandler(ClassName_EventName);
				IClass callingClass = resolveResult.CallingClass;
				bool inStatic = false;
				if (resolveResult.CallingMember != null)
					inStatic = resolveResult.CallingMember.IsStatic;
				
				// ...build the new handler name...
				string newHandlerName = BuildHandlerName();
				if (newHandlerName == null) {
					MemberResolveResult mrr = resolveResult as MemberResolveResult;
					IEvent eventMember = (mrr != null ? mrr.ResolvedMember as IEvent : null);
					newHandlerName =
						((callingClass != null) ? callingClass.Name : "callingClass")
						+ "_"
						+ ((eventMember != null) ? eventMember.Name : "eventMember");
				}

				// ...build the completion text...
				StringBuilder newHandlerTextBuilder = new StringBuilder("new ").Append(eventHandlerTypeName).Append("(");
				newHandlerTextBuilder.Append(newHandlerName).Append(");");

				// ...build the optional new method text...
				StringBuilder newHandlerCodeBuilder = new StringBuilder();
				newHandlerCodeBuilder.AppendLine().AppendLine();
				if (inStatic)
					newHandlerCodeBuilder.Append("static ");
				newHandlerCodeBuilder.Append(ambience.Convert(invoke.ReturnType)).Append(" ").Append(newHandlerName);
				newHandlerCodeBuilder.Append("(").Append(parameterString.ToString()).AppendLine(")");
				newHandlerCodeBuilder.AppendLine("{");
				newHandlerCodeBuilder.AppendLine("throw new NotImplementedException();");
				newHandlerCodeBuilder.Append("}");

				// ...and add it to the completionData.
				result.Items.Add(new NewEventHandlerCompletionItem(
					newHandlerTextBuilder.ToString(),
					2+newHandlerName.Length,
					newHandlerName.Length,
					"new " + eventHandlerFullyQualifiedTypeName + 
					"(" + newHandlerName + StringParser.Parse(")\n${res:CSharpBinding.GenerateNewHandlerInstructions}\n")
					+ CodeCompletionItem.ConvertDocumentation(resolvedClass.Documentation),
					resolveResult,
					newHandlerCodeBuilder.ToString()
				));
				
				if (callingClass != null) {
					foreach (IMethod method in callingClass.DefaultReturnType.GetMethods()) {
						if (inStatic && !method.IsStatic)
							continue;
						if (!method.IsAccessible(callingClass, true))
							continue;
						if (method.Parameters.Count != invoke.Parameters.Count)
							continue;
						// check return type compatibility:
						if (!MemberLookupHelper.ConversionExists(method.ReturnType, invoke.ReturnType))
							continue;
						bool ok = true;
						for (int i = 0; i < invoke.Parameters.Count; i++) {
							if (!MemberLookupHelper.ConversionExists(invoke.Parameters[i].ReturnType, method.Parameters[i].ReturnType)) {
								ok = false;
								break;
							}
						}
						if (ok) {
							result.Items.Add(new CodeCompletionItem(method));
						}
					}
				}
			}
			result.SortItems();
			return result;
		}
		bool ShowCompletion(ITextEditor editor, char completionChar, bool ctrlSpace)
		{
			CSharpCompletionContext completionContext;
			if (fileContent == null) {
				completionContext = CSharpCompletionContext.Get(editor);
			} else {
				completionContext = CSharpCompletionContext.Get(editor, context, currentLocation, fileContent);
			}
			if (completionContext == null)
				return false;
			
			int caretOffset;
			if (fileContent == null) {
				caretOffset = editor.Caret.Offset;
				currentLocation = editor.Caret.Location;
			} else {
				caretOffset = completionContext.Document.GetOffset(currentLocation);
			}
			
			var completionFactory = new CSharpCompletionDataFactory(completionContext, new CSharpResolver(completionContext.TypeResolveContextAtCaret));
			
			CSharpCompletionEngine cce = new CSharpCompletionEngine(
				completionContext.Document,
				completionContext.CompletionContextProvider,
				completionFactory,
				completionContext.ProjectContent,
				completionContext.TypeResolveContextAtCaret
			);
			var formattingOptions = CSharpFormattingPolicies.Instance.GetProjectOptions(completionContext.Compilation.GetProject());
			cce.FormattingPolicy = formattingOptions.OptionsContainer.GetEffectiveOptions();
			cce.EolMarker = DocumentUtilities.GetLineTerminator(completionContext.Document, currentLocation.Line);
			
			cce.IndentString = editor.Options.IndentationString;
			int startPos, triggerWordLength;
			IEnumerable<ICompletionData> completionData;
			if (ctrlSpace) {
				if (!cce.TryGetCompletionWord(caretOffset, out startPos, out triggerWordLength)) {
					startPos = caretOffset;
					triggerWordLength = 0;
				}
				completionData = cce.GetCompletionData(startPos, true);
				completionData = completionData.Concat(cce.GetImportCompletionData(startPos));
			} else {
				startPos = caretOffset;
				if (char.IsLetterOrDigit (completionChar) || completionChar == '_') {
					if (!CodeCompletionOptions.CompleteWhenTyping) return false;
					if (startPos > 1 && char.IsLetterOrDigit (completionContext.Document.GetCharAt (startPos - 2)))
						return false;
					completionData = cce.GetCompletionData(startPos, false);
					startPos--;
					triggerWordLength = 1;
				} else {
					completionData = cce.GetCompletionData(startPos, false);
					triggerWordLength = 0;
				}
			}
			
			DefaultCompletionItemList list = new DefaultCompletionItemList();
			list.Items.AddRange(FilterAndAddTemplates(editor, completionData.Cast<ICompletionItem>().ToList()));
			if (list.Items.Count > 0 && (ctrlSpace || cce.AutoCompleteEmptyMatch)) {
				list.SortItems();
				list.PreselectionLength = caretOffset - startPos;
				list.PostselectionLength = Math.Max(0, startPos + triggerWordLength - caretOffset);
				list.SuggestedItem = list.Items.FirstOrDefault(i => i.Text == cce.DefaultCompletionString);
				editor.ShowCompletionWindow(list);
				return true;
			}
			
			if (CodeCompletionOptions.InsightEnabled && !ctrlSpace) {
				// Method Insight
				var pce = new CSharpParameterCompletionEngine(
					completionContext.Document,
					completionContext.CompletionContextProvider,
					completionFactory,
					completionContext.ProjectContent,
					completionContext.TypeResolveContextAtCaret
				);
				var newInsight = pce.GetParameterDataProvider(caretOffset, completionChar) as CSharpMethodInsight;
				if (newInsight != null && newInsight.items.Count > 0) {
					newInsight.UpdateHighlightedParameter(pce);
					newInsight.Show();
					return true;
				}
			}
			return false;
		}
 protected virtual void InitializeCompletionItemList(DefaultCompletionItemList list)
 {
     list.SortItems();
 }
        static ICompletionItemList AddTemplateCompletionItems(ITextEditor editor, ICompletionItemList list, char ch)
        {
            if(list == null) return null;

            if(ch == 'c' || ch == 'C'){
                var res = new DefaultCompletionItemList();
                res.Items.AddRange(list.Items);
                res.Items.Add(new CurveTemplateCompletionItem(editor));
                return res;
            }

            return null;
        }
		protected override void InitializeCompletionItemList(DefaultCompletionItemList list)
		{
			base.InitializeCompletionItemList(list);
			list.PreselectionLength = preselectionLength;
		}