Esempio n. 1
0
		void GotoMember(IMember member)
		{
			MemberResolveResult resolveResult = new MemberResolveResult(null, null, member);
			GotoFilePosition(resolveResult.GetDefinitionPosition());
		}
		/// <summary>
		/// Makes the given ExpressionResult point to the underlying expression if
		/// the expression is an indexer expression.
		/// </summary>
		/// <returns><c>true</c>, if the expression was an indexer expression and has been changed, <c>false</c> otherwise.</returns>
		public static bool FixIndexerExpression(IExpressionFinder expressionFinder, ref ExpressionResult expr, MemberResolveResult mrr)
		{
			if (mrr != null && mrr.ResolvedMember is IProperty && ((IProperty)mrr.ResolvedMember).IsIndexer) {
				// we got an indexer call as expression ("objectList[0].ToString()[2]")
				// strip the index from the expression to resolve the underlying expression
				string newExpr = expressionFinder.RemoveLastPart(expr.Expression);
				if (newExpr.Length >= expr.Expression.Length) {
					//throw new ApplicationException("new expression must be shorter than old expression");
					
					// If the exception finder doesn't work as expected, we just pretend this wasn't an indexer.
					// This method of 'Find References' will become obsolete with the new NRefactory anyways,
					// so since we likely won't spend time to track down the EF bug, we just ignore it and accept
					// that 'find references' might sometimes miss some results.
					return false;
				}
				expr.Expression = newExpr;
				return true;
			}
			return false;
		}
		/// <summary>
		/// Makes the given ExpressionResult point to the underlying expression if
		/// the expression is an indexer expression.
		/// </summary>
		/// <returns><c>true</c>, if the expression was an indexer expression and has been changed, <c>false</c> otherwise.</returns>
		public static bool FixIndexerExpression(IExpressionFinder expressionFinder, ref ExpressionResult expr, MemberResolveResult mrr)
		{
			if (mrr != null && mrr.ResolvedMember is IProperty && ((IProperty)mrr.ResolvedMember).IsIndexer) {
				// we got an indexer call as expression ("objectList[0].ToString()[2]")
				// strip the index from the expression to resolve the underlying expression
				string newExpr = expressionFinder.RemoveLastPart(expr.Expression);
				if (newExpr.Length >= expr.Expression.Length) {
					throw new ApplicationException("new expression must be shorter than old expression");
				}
				expr.Expression = newExpr;
				return true;
			}
			return false;
		}
Esempio n. 4
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;
		}
Esempio n. 5
0
		static FileLineReference FindTest(TestMember testMember)
		{
			MemberResolveResult resolveResult = new MemberResolveResult(null, null, testMember.Member);
			FilePosition filePos = resolveResult.GetDefinitionPosition();
			return new FileLineReference(filePos.FileName, filePos.Line - 1, filePos.Column - 1);
		}
		public static IEnumerable<IInsightItem> MemberInsight(MemberResolveResult result)
		{
			switch (result.ResolvedType.FullyQualifiedName) {
				case "System.Windows.Thickness":
					yield return new MemberInsightItem(result.ResolvedMember, "uniformLength");
					yield return new MemberInsightItem(result.ResolvedMember, "left, top");
					yield return new MemberInsightItem(result.ResolvedMember, "left, top, right, bottom");
					break;
				case "System.Windows.Size":
					yield return new MemberInsightItem(result.ResolvedMember, "width, height");
					break;
				case "System.Windows.Point":
					yield return new MemberInsightItem(result.ResolvedMember, "x, y");
					break;
				case "System.Windows.Rect":
					yield return new MemberInsightItem(result.ResolvedMember, "x, y, width, height");
					break;
			}
		}
		/// <summary>
		/// Returns the location of the specified test method in the
		/// project being tested.
		/// </summary>
		FileLineReference FindTest(string methodName)
		{
			TestProject testProject = GetTestProject(currentProject);
			if (testProject != null) {
				TestMethod method = testProject.TestClasses.GetTestMethod(methodName);
				if (method != null) {
					MemberResolveResult resolveResult = new MemberResolveResult(null, null, method.Method);
					FilePosition filePos = resolveResult.GetDefinitionPosition();
					return new FileLineReference(filePos.FileName, filePos.Line, filePos.Column);
				}
			}
			return null;
		}