コード例 #1
0
        public IEnumerable <IInsightItem> CreateMarkupExtensionInsight(XamlCompletionContext context)
        {
            var markup   = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset);
            var resolver = new XamlResolver(compilation);
            var type     = (resolver.ResolveExpression(markup.ExtensionType, context) ?? resolver.ResolveExpression(markup.ExtensionType + "Extension", context)).Type;

            if (type != null)
            {
                var ctors = type
                            .GetMethods(m => m.IsPublic && m.IsConstructor && m.Parameters.Count >= markup.PositionalArguments.Count)
                            .OrderBy(m => m.Parameters.Count);

                foreach (var ctor in ctors)
                {
                    yield return(new MarkupExtensionInsightItem(ctor));
                }
            }
        }
コード例 #2
0
		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;
		}
コード例 #3
0
		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;
		}
コード例 #4
0
		public IEnumerable<IInsightItem> CreateMarkupExtensionInsight(XamlCompletionContext context)
		{
			var markup = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset);
			var resolver = new XamlResolver(compilation);
			var type = (resolver.ResolveExpression(markup.ExtensionType, context) ?? resolver.ResolveExpression(markup.ExtensionType + "Extension", context)).Type;
			
			if (type != null) {
				var ctors = type
					.GetMethods(m => m.IsPublic && m.IsConstructor && m.Parameters.Count >= markup.PositionalArguments.Count)
					.OrderBy(m => m.Parameters.Count);
				
				foreach (var ctor in ctors)
					yield return new MarkupExtensionInsightItem(ctor);
			}
		}
コード例 #5
0
        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);
        }