public ICompletionItemList CreateMarkupExtensionCompletion(XamlCompletionContext context) { var list = new XamlCompletionItemList(context); compilation = SD.ParserService.GetCompilationForFile(context.Editor.FileName); string visibleValue = context.RawAttributeValue.Substring(0, Utils.MinMax(context.ValueStartOffset, 0, context.RawAttributeValue.Length)); if (context.PressedKey == '=') { visibleValue += "="; } var markup = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset); var resolver = new XamlResolver(compilation); var type = resolver.ResolveExpression(markup.ExtensionType, context).Type; if (type.Kind == TypeKind.Unknown) { type = resolver.ResolveExpression(markup.ExtensionType + "Extension", context).Type; } if (type.Kind == TypeKind.Unknown) { list.Items.AddRange(CreateListOfMarkupExtensions(context)); list.PreselectionLength = markup.ExtensionType.Length; } else { if (markup.NamedArguments.Count == 0) { if (DoPositionalArgsCompletion(list, context, markup, type)) { DoNamedArgsCompletion(list, context, type, markup); } } else { DoNamedArgsCompletion(list, context, type, markup); } } list.SortItems(); return(list); }
public XamlCompletionItemList CreateListForContext(XamlCompletionContext context) { XamlCompletionItemList list = new XamlCompletionItemList(context); ITextEditor editor = context.Editor; compilation = SD.ParserService.GetCompilationForFile(editor.FileName); XamlAstResolver resolver = new XamlAstResolver(compilation, context.ParseInformation); switch (context.Description) { case XamlContextDescription.None: if (context.Forced) { list.Items.AddRange(standardElements); list.Items.AddRange(CreateElementList(context, false)); AddClosingTagCompletion(context, list, resolver); } break; case XamlContextDescription.AtTag: if ((editor.Caret.Offset > 0 && editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.') || context.PressedKey == '.') { list.Items.AddRange(CreateAttributeList(context, false)); } else { list.Items.AddRange(standardElements); list.Items.AddRange(CreateElementList(context, false)); AddClosingTagCompletion(context, list, resolver); } break; case XamlContextDescription.InTag: string word = editor.GetWordBeforeCaretExtended(); if (context.PressedKey == '.' || word.Contains(".")) { int pos = word.IndexOf(':'); string element = word.Substring(pos + 1, word.Length - pos - 1); string className = word; int propertyStart = element.IndexOf('.'); if (propertyStart != -1) { element = element.Substring(0, propertyStart).TrimEnd('.'); className = className.Substring(0, propertyStart + pos + 1).TrimEnd('.'); } int caretOffset = editor.Caret.Offset; int offset = editor.Document.LastIndexOf(className, caretOffset - word.Length, word.Length, StringComparison.OrdinalIgnoreCase); TextLocation loc = editor.Document.GetLocation(offset); XamlFullParseInformation info = context.ParseInformation; XamlResolver nameResolver = new XamlResolver(compilation); TypeResolveResult trr = nameResolver.ResolveExpression(className, context) as TypeResolveResult; ITypeDefinition typeClass = trr != null ? trr.Type.GetDefinition() : null; if (typeClass != null && typeClass.HasAttached(true, true)) list.Items.AddRange(GetListOfAttached(context, typeClass, true, true)); } else { list.Items.AddRange(CreateAttributeList(context, true)); list.Items.AddRange(standardAttributes); } break; case XamlContextDescription.InAttributeValue: new XamlCodeCompletionBinding().CtrlSpace(editor); break; } list.SortItems(); return list; }
public ICompletionItemList CreateMarkupExtensionCompletion(XamlCompletionContext context) { var list = new XamlCompletionItemList(context); compilation = SD.ParserService.GetCompilationForFile(context.Editor.FileName); string visibleValue = context.RawAttributeValue.Substring(0, Utils.MinMax(context.ValueStartOffset, 0, context.RawAttributeValue.Length)); if (context.PressedKey == '=') visibleValue += "="; var markup = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset); var resolver = new XamlResolver(compilation); var type = resolver.ResolveExpression(markup.ExtensionType, context).Type; if (type.Kind == TypeKind.Unknown) type = resolver.ResolveExpression(markup.ExtensionType + "Extension", context).Type; if (type.Kind == TypeKind.Unknown) { list.Items.AddRange(CreateListOfMarkupExtensions(context)); list.PreselectionLength = markup.ExtensionType.Length; } else { if (markup.NamedArguments.Count == 0) { if (DoPositionalArgsCompletion(list, context, markup, type)) DoNamedArgsCompletion(list, context, type, markup); } else DoNamedArgsCompletion(list, context, type, markup); } list.SortItems(); return list; }
public bool CtrlSpace(ITextEditor editor) { XamlCompletionContext context = CompletionDataHelper.ResolveCompletionContext(editor, ' '); context.Forced = trackForced; if (context.Description == XamlContextDescription.InComment || context.Description == XamlContextDescription.InCData) { return(false); } if (context.ActiveElement != null) { if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset) && context.Description != XamlContextDescription.InAttributeValue) { XamlCompletionItemList list = CompletionDataHelper.CreateListForContext(context); string starter = editor.GetWordBeforeCaretExtended().TrimStart('/'); if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter)) { if (starter.Contains(".")) { list.PreselectionLength = starter.Length - starter.IndexOf('.') - 1; } else { list.PreselectionLength = starter.Length; } } editor.ShowCompletionWindow(list); return(true); } else { // DO NOT USE CompletionDataHelper.CreateListForContext here!!! results in endless recursion!!!! if (context.Attribute != null) { if (!DoMarkupExtensionCompletion(context)) { var completionList = new XamlCompletionItemList(context); completionList.PreselectionLength = editor.GetWordBeforeCaretExtended().Length; if ((context.ActiveElement.Name == "Setter" || context.ActiveElement.Name == "EventSetter") && (context.Attribute.Name == "Property" || context.Attribute.Name == "Value")) { DoSetterAndEventSetterCompletion(context, completionList); } else if ((context.ActiveElement.Name.EndsWith("Trigger") || context.ActiveElement.Name == "Condition") && context.Attribute.Name == "Value") { DoTriggerCompletion(context, completionList); } else { if (context.Attribute.Name == "xml:space") { completionList.Items.AddRange(new[] { new SpecialCompletionItem("preserve"), new SpecialCompletionItem("default") }); } var mrr = XamlResolver.Resolve(context.Attribute.Name, context) as MemberResolveResult; if (mrr != null && mrr.ResolvedType != null) { completionList.Items.AddRange(CompletionDataHelper.MemberCompletion(context, mrr.ResolvedType, string.Empty)); editor.ShowInsightWindow(CompletionDataHelper.MemberInsight(mrr)); if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.PropertyPath") { string start = editor.GetWordBeforeCaretExtended(); int index = start.LastIndexOfAny(PropertyPathTokenizer.ControlChars); if (index + 1 < start.Length) { start = start.Substring(index + 1); } else { start = ""; } completionList.PreselectionLength = start.Length; } else if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.Media.FontFamily") { string text = context.ValueStartOffset > -1 ? context.RawAttributeValue.Substring(0, Math.Min(context.ValueStartOffset, context.RawAttributeValue.Length)) : ""; int lastComma = text.LastIndexOf(','); completionList.PreselectionLength = lastComma == -1 ? context.ValueStartOffset : context.ValueStartOffset - lastComma - 1; } } } completionList.SortItems(); if (context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) || context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase)) { completionList.Items.AddRange(CompletionDataHelper.CreateListForXmlnsCompletion(context.ProjectContent)); } ICompletionListWindow window = editor.ShowCompletionWindow(completionList); if ((context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) || context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase)) && window != null) { window.Width = 400; } return(completionList.Items.Any()); } return(true); } } } return(false); }
public XamlCompletionItemList CreateListForContext(XamlCompletionContext context) { XamlCompletionItemList list = new XamlCompletionItemList(context); ITextEditor editor = context.Editor; compilation = SD.ParserService.GetCompilationForFile(editor.FileName); XamlAstResolver resolver = new XamlAstResolver(compilation, context.ParseInformation); switch (context.Description) { case XamlContextDescription.None: if (context.Forced) { list.Items.AddRange(standardElements); list.Items.AddRange(CreateElementList(context, false)); AddClosingTagCompletion(context, list, resolver); } break; case XamlContextDescription.AtTag: if ((editor.Caret.Offset > 0 && editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.') || context.PressedKey == '.') { list.Items.AddRange(CreateAttributeList(context, false)); } else { list.Items.AddRange(standardElements); list.Items.AddRange(CreateElementList(context, false)); AddClosingTagCompletion(context, list, resolver); } break; case XamlContextDescription.InTag: string word = editor.GetWordBeforeCaretExtended(); if (context.PressedKey == '.' || word.Contains(".")) { int pos = word.IndexOf(':'); string element = word.Substring(pos + 1, word.Length - pos - 1); string className = word; int propertyStart = element.IndexOf('.'); if (propertyStart != -1) { element = element.Substring(0, propertyStart).TrimEnd('.'); className = className.Substring(0, propertyStart + pos + 1).TrimEnd('.'); } int caretOffset = editor.Caret.Offset; int offset = editor.Document.LastIndexOf(className, caretOffset - word.Length, word.Length, StringComparison.OrdinalIgnoreCase); TextLocation loc = editor.Document.GetLocation(offset); XamlFullParseInformation info = context.ParseInformation; XamlResolver nameResolver = new XamlResolver(compilation); TypeResolveResult trr = nameResolver.ResolveExpression(className, context) as TypeResolveResult; ITypeDefinition typeClass = trr != null?trr.Type.GetDefinition() : null; if (typeClass != null && typeClass.HasAttached(true, true)) { list.Items.AddRange(GetListOfAttached(context, typeClass, true, true)); } } else { list.Items.AddRange(CreateAttributeList(context, true)); list.Items.AddRange(standardAttributes); } break; case XamlContextDescription.InAttributeValue: new XamlCodeCompletionBinding().CtrlSpace(editor); break; } list.SortItems(); return(list); }
public bool CtrlSpace(ITextEditor editor) { XamlCompletionContext context = CompletionDataHelper.ResolveCompletionContext(editor, ' '); context.Forced = trackForced; if (context.Description == XamlContextDescription.InComment || context.Description == XamlContextDescription.InCData) return false; if (context.ActiveElement != null) { if (!XmlParser.IsInsideAttributeValue(editor.Document.Text, editor.Caret.Offset) && context.Description != XamlContextDescription.InAttributeValue) { XamlCompletionItemList list = CompletionDataHelper.CreateListForContext(context); string starter = editor.GetWordBeforeCaretExtended().TrimStart('/'); if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter)) { if (starter.Contains(".")) list.PreselectionLength = starter.Length - starter.IndexOf('.') - 1; else list.PreselectionLength = starter.Length; } editor.ShowCompletionWindow(list); return true; } else { // DO NOT USE CompletionDataHelper.CreateListForContext here!!! results in endless recursion!!!! if (context.Attribute != null) { if (!DoMarkupExtensionCompletion(context)) { var completionList = new XamlCompletionItemList(context); completionList.PreselectionLength = editor.GetWordBeforeCaretExtended().Length; if ((context.ActiveElement.Name == "Setter" || context.ActiveElement.Name == "EventSetter") && (context.Attribute.Name == "Property" || context.Attribute.Name == "Value")) DoSetterAndEventSetterCompletion(context, completionList); else if ((context.ActiveElement.Name.EndsWith("Trigger") || context.ActiveElement.Name == "Condition") && context.Attribute.Name == "Value") DoTriggerCompletion(context, completionList); else { if (context.Attribute.Name == "xml:space") { completionList.Items.AddRange(new[] { new SpecialCompletionItem("preserve"), new SpecialCompletionItem("default") }); } var mrr = XamlResolver.Resolve(context.Attribute.Name, context) as MemberResolveResult; if (mrr != null && mrr.ResolvedType != null) { completionList.Items.AddRange(CompletionDataHelper.MemberCompletion(context, mrr.ResolvedType, string.Empty)); editor.ShowInsightWindow(CompletionDataHelper.MemberInsight(mrr)); if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.PropertyPath") { string start = editor.GetWordBeforeCaretExtended(); int index = start.LastIndexOfAny(PropertyPathTokenizer.ControlChars); if (index + 1 < start.Length) start = start.Substring(index + 1); else start = ""; completionList.PreselectionLength = start.Length; } else if (mrr.ResolvedType.FullyQualifiedName == "System.Windows.Media.FontFamily") { string text = context.ValueStartOffset > -1 ? context.RawAttributeValue.Substring(0, Math.Min(context.ValueStartOffset + 1, context.RawAttributeValue.Length)) : ""; int lastComma = text.LastIndexOf(','); completionList.PreselectionLength = lastComma == -1 ? context.ValueStartOffset + 1 : context.ValueStartOffset - lastComma; } } } completionList.SortItems(); if (context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) || context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase)) completionList.Items.AddRange(CompletionDataHelper.CreateListForXmlnsCompletion(context.ProjectContent)); ICompletionListWindow window = editor.ShowCompletionWindow(completionList); if ((context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) || context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase)) && window != null) window.Width = 400; return completionList.Items.Any(); } return true; } } } return false; }
public static ICompletionItemList CreateMarkupExtensionCompletion(XamlCompletionContext context) { var list = new XamlCompletionItemList(context); string visibleValue = context.RawAttributeValue.Substring(0, Utils.MinMax(context.ValueStartOffset, 0, context.RawAttributeValue.Length)); if (context.PressedKey == '=') visibleValue += "="; // context.RawAttributeValue = visibleValue; // context.AttributeValue = MarkupExtensionParser.ParseValue(visibleValue); var markup = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset); var type = ResolveType(markup.ExtensionType, context) ?? ResolveType(markup.ExtensionType + "Extension", context); if (type == null) { list.Items.AddRange(CreateListOfMarkupExtensions(context)); list.PreselectionLength = markup.ExtensionType.Length; } else { if (markup.NamedArguments.Count == 0) { if (DoPositionalArgsCompletion(list, context, markup, type)) DoNamedArgsCompletion(list, context, type, markup); } else DoNamedArgsCompletion(list, context, type, markup); } list.SortItems(); return list; }
public static XamlCompletionItemList CreateListForContext(XamlCompletionContext context) { XamlCompletionItemList list = new XamlCompletionItemList(context); ParseInformation info = context.ParseInformation; ITextEditor editor = context.Editor; switch (context.Description) { case XamlContextDescription.None: if (context.Forced) { list.Items.AddRange(standardElements); list.Items.AddRange(CreateElementList(context, false, false)); AddClosingTagCompletion(context, list); } break; case XamlContextDescription.AtTag: if ((editor.Caret.Offset > 0 && editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.') || context.PressedKey == '.') { list.Items.AddRange(CreateAttributeList(context, false)); } else { list.Items.AddRange(standardElements); list.Items.AddRange(CreateElementList(context, false, false)); AddClosingTagCompletion(context, list); } break; case XamlContextDescription.InTag: DebugTimer.Start(); string word = context.Editor.GetWordBeforeCaretExtended(); if (context.PressedKey == '.' || word.Contains(".")) { string ns = ""; int pos = word.IndexOf(':'); if (pos > -1) ns = word.Substring(0, pos); string element = word.Substring(pos + 1, word.Length - pos - 1); string className = word; int propertyStart = element.IndexOf('.'); if (propertyStart != -1) { element = element.Substring(0, propertyStart).TrimEnd('.'); className = className.Substring(0, propertyStart + pos + 1).TrimEnd('.'); } TypeResolveResult trr = XamlResolver.Resolve(className, context) as TypeResolveResult; IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null; if (typeClass != null && typeClass.HasAttached(true, true)) list.Items.AddRange(GetListOfAttached(context, element, ns, true, true)); } else { QualifiedNameWithLocation last = context.ActiveElement.ToQualifiedName(); TypeResolveResult trr = XamlResolver.Resolve(last.Name, context) as TypeResolveResult; IClass typeClass = (trr != null && trr.ResolvedType != null) ? trr.ResolvedType.GetUnderlyingClass() : null; list.Items.AddRange(CreateAttributeList(context, true)); list.Items.AddRange(standardAttributes); } DebugTimer.Stop("CreateListForContext - InTag"); break; case XamlContextDescription.InAttributeValue: new XamlCodeCompletionBinding().CtrlSpace(editor); break; } list.SortItems(); return list; }