Exemplo n.º 1
0
 static void AddSpecialItems(ref VBNetCompletionItemList result, ParseInformation info, IReturnType resolvedType, IMember m, ExpressionResult expressionResult, ITextEditor editor)
 {
     if (expressionResult.Context == ExpressionContext.Type && m != null && m.BodyRegion.IsInside(editor.Caret.Line, editor.Caret.Column))
     {
         result.Items.Add(new DefaultCompletionItem("? =")
         {
             Image       = ClassBrowserIconService.GotoArrow,
             Description = StringParser.Parse("${res:AddIns.VBNetBinding.CodeCompletion.QuestionmarkEqualsItem.Description}")
         });
     }
     if (resolvedType != null && AllowsDescendentAccess(resolvedType, info.CompilationUnit.ProjectContent))
     {
         result.Items.Add(new DefaultCompletionItem("..")
         {
             Image = ClassBrowserIconService.GotoArrow
         });
     }
     if (resolvedType != null && AllowsAttributeValueAccess(resolvedType, info.CompilationUnit.ProjectContent))
     {
         result.Items.Add(new DefaultCompletionItem("@")
         {
             Image = ClassBrowserIconService.GotoArrow
         });
     }
 }
Exemplo n.º 2
0
        static void HandleKeyword(ref VBNetCompletionItemList result, IReturnType resolvedType, string word, IClass c, IMember m, ITextEditor editor, char pressedKey)
        {
            if (pressedKey == ' ')
            {
                if (word.Equals("return", StringComparison.OrdinalIgnoreCase) && m != null)
                {
                    c = m.ReturnType != null?m.ReturnType.GetUnderlyingClass() : null;

                    if (c != null)
                    {
                        foreach (CodeCompletionItem item in result.Items.OfType <CodeCompletionItem>())
                        {
                            IClass itemClass = item.Entity as IClass;
                            if (itemClass != null && c.FullyQualifiedName == itemClass.FullyQualifiedName && c.TypeParameters.Count == itemClass.TypeParameters.Count)
                            {
                                result.SuggestedItem = item;
                                break;
                            }
                        }
                    }
                }

                if (word.Equals("overrides", StringComparison.OrdinalIgnoreCase) && c != null)
                {
                    result = new OverrideCompletionItemProvider().GenerateCompletionList(editor).ToVBCCList();
                }
            }
        }
Exemplo n.º 3
0
        static bool ShowCompletion(ExpressionResult result, ITextEditor editor, char ch)
        {
            VBNetCompletionItemList list = CompletionDataHelper.GenerateCompletionData(result, editor, ch);

            list.Editor = editor;
            list.Window = editor.ShowCompletionWindow(list);
            return(list.Items.Any());
        }
Exemplo n.º 4
0
        internal static VBNetCompletionItemList ToVBCCList(this ICompletionItemList list)
        {
            var result = new VBNetCompletionItemList()
            {
                SuggestedItem      = list.SuggestedItem,
                PreselectionLength = list.PreselectionLength
            };

            result.Items.AddRange(list.Items);

            return(result);
        }
Exemplo n.º 5
0
		public static VBNetCompletionItemList GenerateCompletionData(this ExpressionResult expressionResult, ITextEditor editor, char pressedKey)
		{
			VBNetCompletionItemList result = new VBNetCompletionItemList();
			
			IResolver resolver = ParserService.CreateResolver(editor.FileName);
			ParseInformation info = ParserService.GetParseInformation(editor.FileName);
			
			if (info == null)
				return result;
			
			List<ICompletionEntry> data = new List<ICompletionEntry>();
			
			bool completingDotExpression = false;
			IReturnType resolvedType = null;
			
			if (expressionResult.Context != ExpressionContext.Global && expressionResult.Context != ExpressionContext.TypeDeclaration) {
				if (expressionResult.Context == ExpressionContext.Importable
				    && string.IsNullOrWhiteSpace(expressionResult.Expression)) {
					expressionResult.Expression = "Global";
				} else if (pressedKey == '\0') {
					int idx = string.IsNullOrWhiteSpace(expressionResult.Expression)
						? -1
						: expressionResult.Expression.LastIndexOf('.');
					
					if (idx > -1) {
						expressionResult.Expression = expressionResult.Expression.Substring(0, idx);
						// its the same as if . was pressed
						completingDotExpression = true;
					} else {
						expressionResult.Expression = "";
					}
				}
				
				var rr = resolver.Resolve(expressionResult, info, editor.Document.Text);
				
				if (rr == null || !rr.IsValid || (pressedKey != '.' && !completingDotExpression)) {
					if (((BitArray)expressionResult.Tag)[Tokens.Identifier])
						data = new NRefactoryResolver(LanguageProperties.VBNet)
							.CtrlSpace(editor.Caret.Line, editor.Caret.Column, info, editor.Document.Text, expressionResult.Context,
							           ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces);
				} else {
					if (rr is MethodGroupResolveResult) {
						IMethod singleMethod = ((MethodGroupResolveResult)rr).GetMethodWithEmptyParameterList();
						if (singleMethod != null)
							rr = new MemberResolveResult(rr.CallingClass, rr.CallingMember, singleMethod);
					}
					
					if (rr is IntegerLiteralResolveResult && pressedKey == '.')
						return result;
					
					data = rr.GetCompletionData(info.CompilationUnit.ProjectContent, ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces) ?? new List<ICompletionEntry>();
					
					resolvedType = rr.ResolvedType;
				}
			}
			
			bool addedKeywords = false;
			
			if (expressionResult.Tag != null && (expressionResult.Context != ExpressionContext.Importable) && pressedKey != '.' && !completingDotExpression) {
				AddVBNetKeywords(data, (BitArray)expressionResult.Tag);
				addedKeywords = true;
			}
			
			CodeCompletionItemProvider.ConvertCompletionData(result, data, expressionResult.Context);
			
			if (addedKeywords && result.Items.Any())
				AddTemplates(editor, result);
			
			string word = editor.GetWordBeforeCaret().Trim();
			
			IClass c = GetCurrentClass(editor);
			IMember m = GetCurrentMember(editor);
			
			HandleKeyword(ref result,  resolvedType, word, c, m, editor, pressedKey);
			
			AddSpecialItems(ref result, info, resolvedType, m, expressionResult, editor);
			
			char prevChar;
			
			if (pressedKey == '\0') { // ctrl+space
				prevChar = editor.Caret.Offset > 0 ? editor.Document.GetCharAt(editor.Caret.Offset - 1) : '\0';
				word = char.IsLetterOrDigit(prevChar) || prevChar == '_' ? editor.GetWordBeforeCaret() : "";
				
				if (!string.IsNullOrWhiteSpace(word))
					result.PreselectionLength = word.Length;
			}
			
			prevChar =  editor.Caret.Offset > 0 ? editor.Document.GetCharAt(editor.Caret.Offset - 1) : '\0';
			
			if (prevChar == '_')
				result.PreselectionLength++;
			
			result.SortItems();
			
			return result;
		}
Exemplo n.º 6
0
		static void AddSpecialItems(ref VBNetCompletionItemList result, ParseInformation info, IReturnType resolvedType, IMember m, ExpressionResult expressionResult, ITextEditor editor)
		{
			if (expressionResult.Context == ExpressionContext.Type && m != null && m.BodyRegion.IsInside(editor.Caret.Line, editor.Caret.Column)) {
				result.Items.Add(new DefaultCompletionItem("? =") {
				                 	Image = ClassBrowserIconService.GotoArrow,
				                 	Description = StringParser.Parse("${res:AddIns.VBNetBinding.CodeCompletion.QuestionmarkEqualsItem.Description}")
				                 });
			}
			if (resolvedType != null && AllowsDescendentAccess(resolvedType, info.CompilationUnit.ProjectContent))
				result.Items.Add(new DefaultCompletionItem("..") { Image = ClassBrowserIconService.GotoArrow });
			if (resolvedType != null && AllowsAttributeValueAccess(resolvedType, info.CompilationUnit.ProjectContent))
				result.Items.Add(new DefaultCompletionItem("@") { Image = ClassBrowserIconService.GotoArrow });
		}
Exemplo n.º 7
0
		static void HandleKeyword(ref VBNetCompletionItemList result, IReturnType resolvedType, string word, IClass c, IMember m, ITextEditor editor, char pressedKey)
		{
			if (pressedKey == ' ') {
				if (word.Equals("return", StringComparison.OrdinalIgnoreCase) && m != null) {
					c = m.ReturnType != null ? m.ReturnType.GetUnderlyingClass() : null;
					if (c != null) {
						foreach (CodeCompletionItem item in result.Items.OfType<CodeCompletionItem>()) {
							IClass itemClass = item.Entity as IClass;
							if (itemClass != null && c.FullyQualifiedName == itemClass.FullyQualifiedName && c.TypeParameters.Count == itemClass.TypeParameters.Count) {
								result.SuggestedItem = item;
								break;
							}
						}
					}
				}
				
				if (word.Equals("overrides", StringComparison.OrdinalIgnoreCase) && c != null) {
					result = new OverrideCompletionItemProvider().GenerateCompletionList(editor).ToVBCCList();
				}
			}
		}
Exemplo n.º 8
0
        public static VBNetCompletionItemList GenerateCompletionData(this ExpressionResult expressionResult, ITextEditor editor, char pressedKey)
        {
            VBNetCompletionItemList result = new VBNetCompletionItemList();

            IResolver        resolver = ParserService.CreateResolver(editor.FileName);
            ParseInformation info     = ParserService.GetParseInformation(editor.FileName);

            if (info == null)
            {
                return(result);
            }

            List <ICompletionEntry> data = new List <ICompletionEntry>();

            bool        completingDotExpression = false;
            IReturnType resolvedType            = null;

            if (expressionResult.Context != ExpressionContext.Global && expressionResult.Context != ExpressionContext.TypeDeclaration)
            {
                if (expressionResult.Context == ExpressionContext.Importable &&
                    string.IsNullOrWhiteSpace(expressionResult.Expression))
                {
                    expressionResult.Expression = "Global";
                }
                else if (pressedKey == '\0')
                {
                    int idx = string.IsNullOrWhiteSpace(expressionResult.Expression)
                                                ? -1
                                                : expressionResult.Expression.LastIndexOf('.');

                    if (idx > -1)
                    {
                        expressionResult.Expression = expressionResult.Expression.Substring(0, idx);
                        // its the same as if . was pressed
                        completingDotExpression = true;
                    }
                    else
                    {
                        expressionResult.Expression = "";
                    }
                }

                var rr = resolver.Resolve(expressionResult, info, editor.Document.Text);

                if (rr == null || !rr.IsValid || (pressedKey != '.' && !completingDotExpression))
                {
                    if (((BitArray)expressionResult.Tag)[Tokens.Identifier])
                    {
                        data = new NRefactoryResolver(LanguageProperties.VBNet)
                               .CtrlSpace(editor.Caret.Line, editor.Caret.Column, info, editor.Document.Text, expressionResult.Context,
                                          ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces);
                    }
                }
                else
                {
                    if (rr is MethodGroupResolveResult)
                    {
                        IMethod singleMethod = ((MethodGroupResolveResult)rr).GetMethodWithEmptyParameterList();
                        if (singleMethod != null)
                        {
                            rr = new MemberResolveResult(rr.CallingClass, rr.CallingMember, singleMethod);
                        }
                    }

                    if (rr is IntegerLiteralResolveResult && pressedKey == '.')
                    {
                        return(result);
                    }

                    data = rr.GetCompletionData(info.CompilationUnit.ProjectContent, ((NRefactoryCompletionItemList)result).ContainsItemsFromAllNamespaces) ?? new List <ICompletionEntry>();

                    resolvedType = rr.ResolvedType;
                }
            }

            bool addedKeywords = false;

            if (expressionResult.Tag != null && (expressionResult.Context != ExpressionContext.Importable) && pressedKey != '.' && !completingDotExpression)
            {
                AddVBNetKeywords(data, (BitArray)expressionResult.Tag);
                addedKeywords = true;
            }

            CodeCompletionItemProvider.ConvertCompletionData(result, data, expressionResult.Context);

            if (addedKeywords && result.Items.Any())
            {
                AddTemplates(editor, result);
            }

            string word = editor.GetWordBeforeCaret().Trim();

            IClass  c = GetCurrentClass(editor);
            IMember m = GetCurrentMember(editor);

            HandleKeyword(ref result, resolvedType, word, c, m, editor, pressedKey);

            AddSpecialItems(ref result, info, resolvedType, m, expressionResult, editor);

            char prevChar;

            if (pressedKey == '\0')               // ctrl+space
            {
                prevChar = editor.Caret.Offset > 0 ? editor.Document.GetCharAt(editor.Caret.Offset - 1) : '\0';
                word     = char.IsLetterOrDigit(prevChar) || prevChar == '_' ? editor.GetWordBeforeCaret() : "";

                if (!string.IsNullOrWhiteSpace(word))
                {
                    result.PreselectionLength = word.Length;
                }
            }

            prevChar = editor.Caret.Offset > 0 ? editor.Document.GetCharAt(editor.Caret.Offset - 1) : '\0';

            if (prevChar == '_')
            {
                result.PreselectionLength++;
            }

            result.SortItems();

            return(result);
        }