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


C# IVsTextLines.GetLastLineIndex方法代码示例

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


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

示例1: ReformatCode

        public static List<EditSpan> ReformatCode(IVsTextLines pBuffer, TextSpan span, int tabSize)
        {
            string filePath = FilePathUtilities.GetFilePath(pBuffer);

            // Return dynamic scanner based on file extension
           
            List<EditSpan> changeList = new List<EditSpan>();
            int nbLines;
            pBuffer.GetLineCount(out nbLines);
            string codeToFormat;

            int lastLine;
            int lastLineIndex;
            pBuffer.GetLastLineIndex(out lastLine, out lastLineIndex);
            pBuffer.GetLineText(0, 0, lastLine, lastLineIndex, out codeToFormat);

            NShaderScanner shaderScanner = NShaderScannerFactory.GetShaderScanner(filePath);
            Scanner lexer = shaderScanner.Lexer;
            lexer.SetSource(codeToFormat, 0);

            int spanStart;
            int spanEnd;
            pBuffer.GetPositionOfLineIndex(span.iStartLine, span.iStartIndex, out spanStart);
            pBuffer.GetPositionOfLineIndex(span.iEndLine, span.iEndIndex, out spanEnd);

            int state = 0;
            int start, end;
            ShaderToken token = (ShaderToken) lexer.GetNext(ref state, out start, out end);

            List<int> brackets = new List<int>();
            List<int> delimiters = new List<int>();
            // !EOL and !EOF
            int level = 0;
            int startCopy = 0;
            int levelParenthesis = 0;
            while (token != ShaderToken.EOF)
            {
                switch (token)
                {
                    case ShaderToken.LEFT_PARENTHESIS:
                        levelParenthesis++;
                        break;
                    case ShaderToken.RIGHT_PARENTHESIS:
                        levelParenthesis--;
                        if ( levelParenthesis < 0 )
                        {
                            levelParenthesis = 0;
                        }
                        break;
                    case ShaderToken.LEFT_BRACKET:
                        level++;
                        if (codeToFormat[start] == '{' && start >= spanStart && end <= spanEnd)
                        {
                            Match match = matchBraceStart.Match(codeToFormat, start);
                            

                            StringBuilder codeFormatted = new StringBuilder();
                            codeFormatted.Append("{\r\n");
                            int levelToIndentNext = level;                            
                            if (match.Groups.Count == 2)
                            {
                                string matchStr = match.Groups[1].Value;
                                levelToIndentNext--;
                            }
                            for (int i = 0; i < levelToIndentNext; i++)
                            {
                                for (int j = 0; j < tabSize; j++)
                                {
                                    codeFormatted.Append(' ');
                                }
                            }
                            if (match.Groups.Count == 2)
                            {
                                codeFormatted.Append("}\r\n");
                            }

                            TextSpan editTextSpan = new TextSpan();

                            pBuffer.GetLineIndexOfPosition(start,
                                                           out editTextSpan.iStartLine,
                                                           out editTextSpan.iStartIndex);
                            pBuffer.GetLineIndexOfPosition(startCopy + match.Index + match.Length,
                                                           out editTextSpan.iEndLine,
                                                           out editTextSpan.iEndIndex);

                            changeList.Add(new EditSpan(editTextSpan, codeFormatted.ToString()));
                        }
                        break;
                    case ShaderToken.RIGHT_BRACKET:
                        level--;
                        if (level < 0)
                        {
                            level = 0;
                        }
                        brackets.Add(start);
                        break;
                    case ShaderToken.DELIMITER:
                        if (codeToFormat[start] == ';' && start >= spanStart && end <= spanEnd && levelParenthesis == 0)
                        {
                            Match match = matchEndOfStatement.Match(codeToFormat, start);
//.........这里部分代码省略.........
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:101,代码来源:NShaderFormatHelper.cs

示例2: GetLine

        static string GetLine(IVsTextLines lines, int lineNr)
        {
            if (lineNr < 0)
                throw new ArgumentOutOfRangeException("lineNr");
            else if (lines == null)
                return null;

            int lastLine, lastIndex;
            if (!ErrorHandler.Succeeded(lines.GetLastLineIndex(out lastLine, out lastIndex)))
                return null;

            if (lineNr > lastLine)
                return null;

            LINEDATA[] data = new LINEDATA[1];

            if (!ErrorHandler.Succeeded(lines.GetLineData(lineNr, data, null)))
                return null;

            return Marshal.PtrToStringUni(data[0].pszText, data[0].iLength);
        }
开发者ID:necora,项目名称:ank_git,代码行数:21,代码来源:OpenIssue.cs

示例3: UpdateServiceDefinition

        private static void UpdateServiceDefinition(IVsTextLines lines, string roleType, string projectName) {
            if (lines == null) {
                throw new ArgumentException("lines");
            }

            int lastLine, lastIndex;
            string text;

            ErrorHandler.ThrowOnFailure(lines.GetLastLineIndex(out lastLine, out lastIndex));
            ErrorHandler.ThrowOnFailure(lines.GetLineText(0, 0, lastLine, lastIndex, out text));

            var doc = new XmlDocument();
            doc.LoadXml(text);

            UpdateServiceDefinition(doc, roleType, projectName);

            var encoding = Encoding.UTF8;

            var userData = lines as IVsUserData;
            if (userData != null) {
                var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingVSTFF_guid;
                object data;
                int cp;
                if (ErrorHandler.Succeeded(userData.GetData(ref guid, out data)) &&
                    (cp = (data as int? ?? (int)(data as uint? ?? 0)) & (int)__VSTFF.VSTFF_CPMASK) != 0) {
                    try {
                        encoding = Encoding.GetEncoding(cp);
                    } catch (NotSupportedException) {
                    } catch (ArgumentException) {
                    }
                }
            }

            var sw = new StringWriterWithEncoding(encoding);
            doc.Save(XmlWriter.Create(
                sw,
                new XmlWriterSettings {
                    Indent = true,
                    IndentChars = " ",
                    NewLineHandling = NewLineHandling.Entitize,
                    Encoding = encoding
                }
            ));

            var sb = sw.GetStringBuilder();
            var len = sb.Length;
            var pStr = Marshal.StringToCoTaskMemUni(sb.ToString());

            try {
                ErrorHandler.ThrowOnFailure(lines.ReplaceLines(0, 0, lastLine, lastIndex, pStr, len, new TextSpan[1]));
            } finally {
                Marshal.FreeCoTaskMem(pStr);
            }
        }
开发者ID:CforED,项目名称:Node.js-Tools-for-Visual-Studio,代码行数:54,代码来源:NodejsProject.cs

示例4: GetText

        /// <summary>
        /// Gets the text.
        /// </summary>
        /// <param name="textLines">The text lines.</param>
        /// <returns></returns>
        private static string GetText(IVsTextLines textLines)
        {
            int line, index;
            string buffer;

            if (textLines.GetLastLineIndex(out line, out index) != VSConstants.S_OK)
                return String.Empty;
            if (textLines.GetLineText(0, 0, line, index, out buffer) != VSConstants.S_OK)
                return String.Empty;

            return buffer;
        }
开发者ID:jda808,项目名称:NPL,代码行数:17,代码来源:LanguageService.cs

示例5: GetAllText

            private static string GetAllText(IVsTextLines buffer)
            {
                int endLine, endIndex;
                string text;

                if (buffer.GetLastLineIndex(out endLine, out endIndex) != VSConstants.S_OK ||
                    buffer.GetLineText(0, 0, endLine, endIndex, out text) != VSConstants.S_OK)
                {
                    text = null;
                }

                return text;
            }
开发者ID:KevinKelley,项目名称:Pegasus,代码行数:13,代码来源:PegasusLanguageService.cs


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