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


C# ITextBuffer.GetPythonClassifier方法代码示例

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


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

示例1: AddImport

        public static void AddImport(
            IServiceProvider serviceProvider,
            ITextBuffer buffer,
            ITextView view,
            string fromModule,
            string name
        ) {
            var analyzer = buffer.GetAnalyzer(serviceProvider);
            var curAst = analyzer.ParseSnapshot(buffer.CurrentSnapshot);

            var suiteBody = curAst.Body as SuiteStatement;
            Statement insertBefore = null;
            if (suiteBody != null) {
                bool firstStatement = true;

                foreach (var statement in suiteBody.Statements) {
                    if (firstStatement && IsDocString(statement as ExpressionStatement)) {
                        // doc string, ignore this
                        firstStatement = false;
                        continue;
                    }

                    firstStatement = false;

                    // __future__ imports go first
                    if (fromModule == null || fromModule != "__future__") {
                        if (statement is ImportStatement) {
                            // we insert after this
                            continue;
                        } else if (statement is FromImportStatement) {
                            // we might update this, we might insert after
                            FromImportStatement fromImport = statement as FromImportStatement;
                            if (fromImport.Root.MakeString() == fromModule) {
                                // update the existing from ... import statement to include the new name.
                                UpdateFromImport(curAst, buffer, fromImport, name);
                                return;
                            }
                            continue;
                        }
                    }

                    // this isn't an import, we insert before this statement
                    insertBefore = statement;
                    break;
                }
            }

            int start;
            if (insertBefore != null) {
                var location = insertBefore.GetStart(curAst);

                var point = buffer.CurrentSnapshot.GetLineFromLineNumber(location.Line - 1).Start;
                // the span starts after any whitespace, so walk backup and see if we should skip some lines
                if (point.Position != 0) {
                    var prevPoint = point.Subtract(1);

                    //  walk past all the previous lines
                    var classifier = buffer.GetPythonClassifier();

                    bool moved = false;
                    while (prevPoint.Position != 0 &&
                        (char.IsWhiteSpace(prevPoint.GetChar()) || IsCommentChar(prevPoint, classifier))) {
                        prevPoint = prevPoint.Subtract(1);
                        moved = true;
                    }
                    prevPoint = prevPoint.Add(1);

                    // then walk forward one line
                    if (moved) {
                        int lineNum = prevPoint.GetContainingLine().LineNumber;
                        do {
                            prevPoint = prevPoint.Add(1);
                        } while (lineNum == prevPoint.GetContainingLine().LineNumber);
                    }

                    point = prevPoint;
                }
                start = point.Position;
            } else {
                start = 0;
            }

            buffer.Insert(start, MakeImportCode(fromModule, name) + view.Options.GetNewLineCharacter());
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:84,代码来源:MissingImportAnalysis.cs


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