Exemplo n.º 1
0
		protected void TestTextInsert(string file, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset)
		{
			int insertionPoint = file.IndexOf('|');
			
			if (insertionPoint < 0)
				Assert.Fail("insertionPoint not found in text!");
			
			this.textEditor.Document.Text = file.Replace("|", "");
			this.textEditor.Caret.Offset = insertionPoint;
			this.textEditor.CreateParseInformation();
			
			CompletionContext context = new CompletionContext() {
				Editor = this.textEditor,
				CompletionChar = completionChar,
				StartOffset = textEditor.Caret.Offset,
				EndOffset = textEditor.Caret.Offset
			};
			
			list.Complete(context, item);
			
			if (!context.CompletionCharHandled && context.CompletionChar != '\n')
				this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + "");
			
			string insertedText = this.textEditor.Document.GetText(insertionPoint, this.textEditor.Document.TextLength - file.Length + 1);
			
			Assert.AreEqual(expectedOutput, insertedText);
			Assert.AreEqual(insertionPoint + expectedOffset, textEditor.Caret.Offset);
		}
		public void Insert(CompletionContext context, ICompletionItem item)
		{
			if (item == null)
				throw new ArgumentNullException("item");
			
			if (!(item is OverrideCompletionItem))
				throw new ArgumentException("item is not an OverrideCompletionItem");
			
			OverrideCompletionItem completionItem = item as OverrideCompletionItem;
			
			ITextEditor textEditor = context.Editor;
			
			IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService;
			
			if (uiService == null)
				return;
			
			ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName);
			
			if (parseInfo == null)
				return;
			
			CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator;
			IClass current = parseInfo.CompilationUnit.GetInnermostClass(textEditor.Caret.Line, textEditor.Caret.Column);
			ClassFinder finder = new ClassFinder(current, textEditor.Caret.Line, textEditor.Caret.Column);
			
			if (current == null)
				return;
			
			using (textEditor.Document.OpenUndoGroup()) {
				ITextAnchor startAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset);
				startAnchor.MovementType = AnchorMovementType.BeforeInsertion;
				
				ITextAnchor endAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset);
				endAnchor.MovementType = AnchorMovementType.AfterInsertion;
				
				MethodDeclaration member = (MethodDeclaration)generator.GetOverridingMethod(completionItem.Member, finder);
				
				string indent = DocumentUtilitites.GetWhitespaceBefore(textEditor.Document, textEditor.Caret.Offset);
				string codeForBaseCall = generator.GenerateCode(member.Body.Children.OfType<AbstractNode>().First(), "");
				string code = generator.GenerateCode(member, indent);
				int marker = code.IndexOf(codeForBaseCall);
				
				textEditor.Document.Insert(startAnchor.Offset, code.Substring(0, marker).TrimStart());
				
				ITextAnchor insertionPos = textEditor.Document.CreateAnchor(endAnchor.Offset);
				insertionPos.MovementType = AnchorMovementType.BeforeInsertion;
				
				InsertionContext insertionContext = new InsertionContext(textEditor.GetService(typeof(TextArea)) as TextArea, startAnchor.Offset);
				
				AbstractInlineRefactorDialog dialog = new OverrideEqualsGetHashCodeMethodsDialog(insertionContext, textEditor, startAnchor, endAnchor, insertionPos, current, completionItem.Member as IMethod, codeForBaseCall.Trim());
				dialog.Element = uiService.CreateInlineUIElement(insertionPos, dialog);
				
				textEditor.Document.InsertNormalized(endAnchor.Offset, Environment.NewLine + code.Substring(marker + codeForBaseCall.Length));
				
				insertionContext.RegisterActiveElement(new InlineRefactorSnippetElement(cxt => null, ""), dialog);
				insertionContext.RaiseInsertionCompleted(EventArgs.Empty);
			}
		}
		public override void Complete(CompletionContext context, ICompletionItem item)
		{
			base.Complete(context, item);
			
			if (item.Text == "..") {
				VBNetCompletionBinding.Instance.CtrlSpace(context.Editor);
			}
		}
		bool FitsToContext(ICompletionItem item, List<ICompletionItem> list)
		{
			if (!(item is ISnippetCompletionItem))
				return false;
			
			var snippetItem = item as ISnippetCompletionItem;
			
			if (string.IsNullOrEmpty(snippetItem.Keyword))
				return true;
			
			return list.Any(x => x.Image == ClassBrowserIconService.Keyword
			                && x.Text == snippetItem.Keyword);
		}
		protected void TestTextInsert(string fileHeader, string fileFooter, char completionChar, ICompletionItemList list, ICompletionItem item, string expectedOutput, int expectedOffset)
		{
			this.textEditor.Document.Text = fileHeader + fileFooter;
			this.textEditor.Caret.Offset = fileHeader.Length;
			this.textEditor.CreateParseInformation();
			
			CompletionContext context = new CompletionContext() {
				Editor = this.textEditor,
				CompletionChar = completionChar,
				StartOffset = textEditor.Caret.Offset,
				EndOffset = textEditor.Caret.Offset
			};
			
			list.Complete(context, item);
			
			if (!context.CompletionCharHandled && context.CompletionChar != '\n')
				this.textEditor.Document.Insert(this.textEditor.Caret.Offset, completionChar + "");
			
			string insertedText = this.textEditor.Document.GetText(fileHeader.Length, this.textEditor.Document.TextLength - fileHeader.Length - fileFooter.Length);
			
			Assert.AreEqual(expectedOutput, insertedText);
			Assert.AreEqual(fileHeader.Length + expectedOffset, textEditor.Caret.Offset);
		}
Exemplo n.º 6
0
 public ItemClickedEventArgs(MouseEventArgs args, ICompletionItem completionItem)
 {
     Args = args;
     CompletionItem = completionItem;
 }
Exemplo n.º 7
0
		public override void Complete(CompletionContext context, ICompletionItem item)
		{
			using (context.Editor.Document.OpenUndoGroup()) {
				base.Complete(context, item);
				
				XamlCompletionContext xamlContext = XamlContextResolver.ResolveCompletionContext(context.Editor, context.CompletionChar);
				
				if (xamlContext.Description == XamlContextDescription.None && (context.StartOffset <= 0 || context.Editor.Document.GetCharAt(context.StartOffset - 1) != '<')) {
					context.Editor.Document.Insert(context.StartOffset, "<");
					context.EndOffset++;
				}
				
				if (item is XamlCompletionItem && !item.Text.EndsWith(":", StringComparison.Ordinal)) {
					XamlCompletionItem cItem = item as XamlCompletionItem;
					
					if (xamlContext.Description == XamlContextDescription.InTag) {
						context.Editor.Document.Insert(context.EndOffset, "=\"\"");
						context.CompletionCharHandled = context.CompletionChar == '=';
						context.Editor.Caret.Offset--;
						new XamlCodeCompletionBinding().CtrlSpace(context.Editor);
					} else if (xamlContext.Description == XamlContextDescription.InMarkupExtension && !string.IsNullOrEmpty(xamlContext.RawAttributeValue)) {
						string valuePart = xamlContext.RawAttributeValue.Substring(0, xamlContext.ValueStartOffset);
						AttributeValue value = MarkupExtensionParser.ParseValue(valuePart);
						
						if (value != null && !value.IsString) {
							var markup = Utils.GetMarkupExtensionAtPosition(value.ExtensionValue, context.Editor.Caret.Offset);
							if (markup.NamedArguments.Count > 0 || markup.PositionalArguments.Count > 0) {
								int oldOffset = context.Editor.Caret.Offset;
								context.Editor.Caret.Offset = context.StartOffset;
								string word = context.Editor.GetWordBeforeCaret().TrimEnd();
								int spaces = CountWhiteSpacesAtEnd(context.Editor.GetWordBeforeCaret());
								int typeNameStart = markup.ExtensionType.IndexOf(':') + 1;
								
								if (!(word == "." || word == "," || word == ":") && markup.ExtensionType.Substring(typeNameStart, markup.ExtensionType.Length - typeNameStart) != word) {
									context.Editor.Document.Replace(context.Editor.Caret.Offset - spaces, spaces, ", ");
									oldOffset += (2 - spaces);
								}
								
								context.Editor.Caret.Offset = oldOffset;
							}
						}
						
						if (cItem.Text.EndsWith("=", StringComparison.OrdinalIgnoreCase))
							new XamlCodeCompletionBinding().CtrlSpace(context.Editor);
					}
				}
				
				if (item is NewEventCompletionItem) {
					CreateEventHandlerCode(xamlContext, item as NewEventCompletionItem);
				}
				
				if (item is XmlnsCompletionItem) {
					context.Editor.Caret.Offset++;
				}
				
				switch (item.Text) {
					case "![CDATA[":
						context.Editor.Document.Insert(context.Editor.Caret.Offset, "]]>");
						context.Editor.Caret.Offset -= 3;
						break;
					case "?":
						context.Editor.Document.Insert(context.Editor.Caret.Offset, "?>");
						context.Editor.Caret.Offset -= 2;
						break;
					case "!--":
						context.Editor.Document.Insert(context.Editor.Caret.Offset, "  -->");
						context.Editor.Caret.Offset -= 4;
						break;
				}
				
				if (item.Text.StartsWith("/", StringComparison.OrdinalIgnoreCase)) {
					context.Editor.Document.Insert(context.EndOffset, ">");
					context.CompletionCharHandled = context.CompletionChar == '>';
					context.Editor.Caret.Offset++;
				}
			}
		}
		public CodeCompletionDataAdapter(SharpDevelopCompletionWindow window, ICompletionItem item)
		{
			if (window == null)
				throw new ArgumentNullException("window");
			if (item == null)
				throw new ArgumentNullException("item");
			this.window = window;
			this.item = item;
			this.fancyCompletionItem = item as IFancyCompletionItem;
		}
		/// <inheritdoc/>
		public virtual void Complete(CompletionContext context, ICompletionItem item)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			if (item == null)
				throw new ArgumentNullException("item");
			if (InsertSpace) {
				InsertSpace = false;
				context.Editor.Document.Insert(context.StartOffset, " ");
				context.StartOffset++;
				context.EndOffset++;
			}
			item.Complete(context);
		}
Exemplo n.º 10
0
 public ItemClickedEvent(MouseEventArgs args, ICompletionItem item)
 {
     this.args = new ItemClickedEventArgs(args, item);
 }
		public bool Handles(ICompletionItem item)
		{
			return item is OverrideCompletionItem && item.Text == "ToString()";
		}
		public void SetUpFixture()
		{
			defaultSchema = new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema());
			completionItems = new XmlCompletionItemCollection(defaultSchema.GetRootElementCompletion());
			selectedCompletionItem = completionItems.SuggestedItem;
		}
 public ScrollIntoViewMessage(object sender, ICompletionItem target)
     : base(sender)
 {
     TargetItem = target;
 }
		public bool Handles(ICompletionItem item)
		{
			return item is OverrideCompletionItem && (item.Text == "GetHashCode()" || item.Text == "Equals(object obj)");
		}