当前位置: 首页>>代码示例>>C#>>正文


C# ITextEditor.GetWordBeforeCaret方法代码示例

本文整理汇总了C#中ITextEditor.GetWordBeforeCaret方法的典型用法代码示例。如果您正苦于以下问题:C# ITextEditor.GetWordBeforeCaret方法的具体用法?C# ITextEditor.GetWordBeforeCaret怎么用?C# ITextEditor.GetWordBeforeCaret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextEditor的用法示例。


在下文中一共展示了ITextEditor.GetWordBeforeCaret方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateCompletionData

		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;
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:96,代码来源:CompletionDataHelper.cs

示例2: HandleKeyPress

		public virtual CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
		{
			switch (ch) {
				case '(':
					if (enableMethodInsight && CodeCompletionOptions.InsightEnabled) {
						IInsightWindow insightWindow = editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor));
						if (insightWindow != null && insightHandler != null) {
							insightHandler.InitializeOpenedInsightWindow(editor, insightWindow);
							insightHandler.HighlightParameter(insightWindow, -1); // disable highlighting
						}
						return CodeCompletionKeyPressResult.Completed;
					}
					break;
				case '[':
					if (enableIndexerInsight && CodeCompletionOptions.InsightEnabled) {
						IInsightWindow insightWindow = editor.ShowInsightWindow(new IndexerInsightProvider().ProvideInsight(editor));
						if (insightWindow != null && insightHandler != null)
							insightHandler.InitializeOpenedInsightWindow(editor, insightWindow);
						return CodeCompletionKeyPressResult.Completed;
					}
					break;
				case '<':
					if (enableXmlCommentCompletion) {
						new CommentCompletionItemProvider().ShowCompletion(editor);
						return CodeCompletionKeyPressResult.Completed;
					}
					break;
				case '.':
					if (enableDotCompletion) {
						new DotCodeCompletionItemProvider().ShowCompletion(editor);
						return CodeCompletionKeyPressResult.Completed;
					}
					break;
				case ' ':
					if (CodeCompletionOptions.KeywordCompletionEnabled) {
						string word = editor.GetWordBeforeCaret();
						if (!string.IsNullOrEmpty(word)) {
							if (HandleKeyword(editor, word))
								return CodeCompletionKeyPressResult.Completed;
						}
					}
					break;
			}
			return CodeCompletionKeyPressResult.None;
		}
开发者ID:hpsa,项目名称:SharpDevelop,代码行数:45,代码来源:CodeCompletionBinding.cs

示例3: HandleKeyPress

		public CodeCompletionKeyPressResult HandleKeyPress(ITextEditor editor, char ch)
		{
			if (IsInComment(editor) || IsInString(editor))
				return CodeCompletionKeyPressResult.None;
			
			if (editor.SelectionLength > 0) {
				// allow code completion when overwriting an identifier
				int endOffset = editor.SelectionStart + editor.SelectionLength;
				// but block code completion when overwriting only part of an identifier
				if (endOffset < editor.Document.TextLength && char.IsLetterOrDigit(editor.Document.GetCharAt(endOffset)))
					return CodeCompletionKeyPressResult.None;
				
				editor.Document.Remove(editor.SelectionStart, editor.SelectionLength);
			}
			
			VBNetExpressionFinder ef = new VBNetExpressionFinder(ParserService.GetParseInformation(editor.FileName));
			
			ExpressionResult result;
			
			switch (ch) {
				case '(':
					if (CodeCompletionOptions.InsightEnabled) {
						IInsightWindow insightWindow = editor.ShowInsightWindow(new MethodInsightProvider().ProvideInsight(editor));
						if (insightWindow != null) {
							insightHandler.InitializeOpenedInsightWindow(editor, insightWindow);
							insightHandler.HighlightParameter(insightWindow, 0);
							insightWindow.CaretPositionChanged += delegate { Run(insightWindow, editor); };
						}
						return CodeCompletionKeyPressResult.Completed;
					}
					break;
				case ',':
					if (CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled) {
						IInsightWindow insightWindow;
						editor.Document.Insert(editor.Caret.Offset, ",");
						if (insightHandler.InsightRefreshOnComma(editor, ch, out insightWindow)) {
							if (insightWindow != null) {
								insightHandler.HighlightParameter(insightWindow, GetArgumentIndex(editor) + 1);
								insightWindow.CaretPositionChanged += delegate { Run(insightWindow, editor); };;
							}
						}
						return CodeCompletionKeyPressResult.EatKey;
					}
					break;
				case '\n':
					TryDeclarationTypeInference(editor, editor.Document.GetLineForOffset(editor.Caret.Offset));
					break;
				case '.':
					string w = editor.GetWordBeforeCaret(); int index = w.IndexOf('.');
					
					if (index > -1 && w.Length - index == 2)
						index = editor.Caret.Offset - 2;
					else
						index = editor.Caret.Offset;
					
					result = ef.FindExpression(editor.Document.Text, index);
					LoggingService.Debug("CC: After dot, result=" + result + ", context=" + result.Context);
					ShowCompletion(result, editor, ch);
					return CodeCompletionKeyPressResult.Completed;
				case '@':
					if (editor.Caret.Offset > 0 && editor.Document.GetCharAt(editor.Caret.Offset - 1) == '.')
						return CodeCompletionKeyPressResult.None;
					goto default;
				case ' ':
					editor.Document.Insert(editor.Caret.Offset, " ");
					result = ef.FindExpression(editor.Document.Text, editor.Caret.Offset);
					
					string word = editor.GetWordBeforeCaret().Trim();
					if (word.Equals("overrides", StringComparison.OrdinalIgnoreCase) || word.Equals("return", StringComparison.OrdinalIgnoreCase) || !LiteralMayFollow((BitArray)result.Tag) && !OperatorMayFollow((BitArray)result.Tag) && ExpressionContext.IdentifierExpected != result.Context) {
						LoggingService.Debug("CC: After space, result=" + result + ", context=" + result.Context);
						ShowCompletion(result, editor, ch);
					}
					return CodeCompletionKeyPressResult.EatKey;
				default:
					if (CodeCompletionOptions.CompleteWhenTyping) {
						int cursor = editor.Caret.Offset;
						char prevChar = cursor > 1 ? editor.Document.GetCharAt(cursor - 1) : ' ';
						char ppChar = cursor > 2 ? editor.Document.GetCharAt(cursor - 2) : ' ';
						
						result = ef.FindExpression(editor.Document.Text, cursor);
						
						if ((result.Context != ExpressionContext.IdentifierExpected && char.IsLetter(ch)) &&
						    (!char.IsLetterOrDigit(prevChar) && prevChar != '.')) {
							if (prevChar == '@' && ppChar == '.')
								return CodeCompletionKeyPressResult.None;
							if (IsTypeCharacter(ch, prevChar))
								return CodeCompletionKeyPressResult.None;
							LoggingService.Debug("CC: Beginning to type a word, result=" + result + ", context=" + result.Context);
							ShowCompletion(result, editor, ch);
							return CodeCompletionKeyPressResult.CompletedIncludeKeyInCompletion;
						}
					}
					break;
			}
			
			return CodeCompletionKeyPressResult.None;
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:97,代码来源:VBNetCompletionBinding.cs


注:本文中的ITextEditor.GetWordBeforeCaret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。