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


C# ICompletionWidget.GetText方法代码示例

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


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

示例1: GenerateCompletionData

        public ICompletionData[] GenerateCompletionData(ICompletionWidget widget, char charTyped)
        {
            completionData = new ArrayList();

            // the parser works with 1 based coordinates
            caretLineNumber      = widget.TriggerLine + 1;
            caretColumn          = widget.TriggerLineOffset + 1;
            //string expression    = TextUtilities.GetExpressionBeforeOffset (textArea, insertIter.Offset);
            ResolveResult results;

            IExpressionFinder expressionFinder = parserContext.GetExpressionFinder(fileName);
            string expression    = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset(widget, widget.TriggerOffset) : expressionFinder.FindExpression(widget.GetText (0, widget.TriggerOffset), widget.TriggerOffset - 2);
            if (expression == null) return null;
            Console.WriteLine ("Expr: |{0}|", expression);
            //FIXME: This chartyped check is a fucking *HACK*
            if (expression == "is" || expression == "as") {
                string expr = expressionFinder == null ? TextUtilities.GetExpressionBeforeOffset (widget, widget.TriggerOffset - 3) : expressionFinder.FindExpression (widget.GetText (0, widget.TriggerOffset), widget.TriggerOffset - 5);
                AddResolveResults (parserContext.IsAsResolve (expr, caretLineNumber, caretColumn, fileName, widget.GetText (0, widget.TextLength)));
                return (ICompletionData[])completionData.ToArray (typeof (ICompletionData));
            }
            if (ctrlspace && charTyped != '.') {
                AddResolveResults (parserContext.CtrlSpace (caretLineNumber, caretColumn, fileName));
                return (ICompletionData[])completionData.ToArray (typeof (ICompletionData));
            }
            if (charTyped == ' ') {
                if (expression == "using" || expression.EndsWith(" using") || expression.EndsWith("\tusing")|| expression.EndsWith("\nusing")|| expression.EndsWith("\rusing")) {
                    string[] namespaces = parserContext.GetNamespaceList ("", true, true);
                    AddResolveResults(new ResolveResult(namespaces));
                }
            } else {
                //FIXME: I added the null check, #D doesnt need it, why do we?
                if (fileName != null) {
                    results = parserContext.Resolve (expression, caretLineNumber, caretColumn, fileName, widget.GetText (0, widget.TextLength));
                    AddResolveResults(results);
                }
            }
            return (ICompletionData[]) completionData.ToArray (typeof (ICompletionData));
        }
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:38,代码来源:CodeCompletionDataProvider.cs

示例2: GetExpressionBeforeOffset

        /// <remarks>
        /// This method returns the expression before a specified offset.
        /// That method is used in code completion to determine the expression given
        /// to the parser for type resolve.
        /// </remarks>
        //public static string GetExpressionBeforeOffset(string text, int offset)
        public static string GetExpressionBeforeOffset(ICompletionWidget widget, int offset)
        {
            int origOffset = offset;

            while (offset - 1 > 0) {
                switch (widget.GetChar (offset - 1)) {
                    case '}':
                        goto done;
            //						break;
                    case ']':
                        offset = SearchBracketBackward(widget, offset - 2, '[',']');
                        break;
                    case ')':
                        offset = SearchBracketBackward(widget, offset - 2, '(',')');
                        break;
                    case '.':
                        --offset;
                        break;
                    case '"':
                        return "\"\"";
                    case '\'':
                        return "'a'";
                    case '>':
                        if (widget.GetChar (offset - 2) == '-') {
                            offset -= 2;
                            break;
                        }
                        goto done;
                    default:
                        if (Char.IsWhiteSpace (widget.GetChar (offset - 1))) {
                            --offset;
                            break;
                        }
                        int start = offset - 1;
                        if (!IsLetterDigitOrUnderscore (widget.GetChar (start))) {
                            goto done;
                        }

                        while (start > 0 && IsLetterDigitOrUnderscore (widget.GetChar(start - 1))) {
                            --start;
                        }

                        Console.WriteLine("{0} -- {1}", offset, start);
                        string word = widget.GetText (start, offset);
                        Console.WriteLine("word >{0}<", word);
                        switch (word) {
                            case "ref":
                            case "out":
                            case "in":
                            case "return":
                            case "throw":
                            case "case":
                                goto done;
                        }

                        if (word.Length > 0 && !IsLetterDigitOrUnderscore(word[0])) {
                            goto done;
                        }
                        offset = start;
                        break;
                }
            }
            done:
            //			Console.WriteLine("offset : {0} origOffset: {1}", offset, origOffset);
            return offset - origOffset > 0 ? widget.GetText(origOffset, offset).Trim() : "";
        }
开发者ID:slluis,项目名称:monodevelop-prehistoric,代码行数:72,代码来源:TextUtilities.cs


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