本文整理汇总了C#中IVsTextLines.GetLineText方法的典型用法代码示例。如果您正苦于以下问题:C# IVsTextLines.GetLineText方法的具体用法?C# IVsTextLines.GetLineText怎么用?C# IVsTextLines.GetLineText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsTextLines
的用法示例。
在下文中一共展示了IVsTextLines.GetLineText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Line
internal static string Line(IVsTextLines vsTextLines, int index)
{
int length;
vsTextLines.GetLengthOfLine(index, out length);
string result;
vsTextLines.GetLineText(index, 0, index, length, out result);
return result;
}
示例2: ParseLine
public List<TokenInfo> ParseLine(IVsTextLines textLines, int line, int maxTokens, out string lineOut)
{
int maxColumn;
textLines.GetLengthOfLine(line, out maxColumn);
textLines.GetLineText(line, 0, line, maxColumn, out lineOut);
return Parse(lineOut, maxTokens);
}
示例3: SearchForCodeBlocks
// »щет в исходном файле все блоки, обрамленные прагмой #line N / #line default
private void SearchForCodeBlocks(IVsTextLines buffer)
{
ErrorHandler.ThrowOnFailure(buffer.LockBufferEx((uint)BufferLockFlags.BLF_READ));
try
{
int totalLines;
ErrorHandler.ThrowOnFailure(buffer.GetLineCount(out totalLines));
var state = ParseState.WaitForBlockStart;
var blockSpan = new TextSpanAndCookie();
for (int line = 0; line < totalLines; ++line)
{
int lineLen;
ErrorHandler.ThrowOnFailure(buffer.GetLengthOfLine(line, out lineLen));
string lineText;
ErrorHandler.ThrowOnFailure(buffer.GetLineText(line, 0, line, lineLen, out lineText));
if (state == ParseState.WaitForBlockStart)
{
var match = _linePragmaRegex.Match(lineText);
if (match.Success)
{
blockSpan.ulHTMLCookie = uint.Parse(match.Groups[1].Value, NumberStyles.Integer, CultureInfo.InvariantCulture);
blockSpan.CodeSpan = new TextSpan();
blockSpan.CodeSpan.iStartLine = line + 1;
blockSpan.CodeSpan.iStartIndex = 0;
state = ParseState.WaitForBlockEnd;
}
}
else
{
if (lineText.Trim().StartsWith("#line default", StringComparison.InvariantCultureIgnoreCase))
{
blockSpan.CodeSpan.iEndLine = line - 1;
buffer.GetLengthOfLine(blockSpan.CodeSpan.iEndLine, out blockSpan.CodeSpan.iEndIndex);
blocks.Add(blockSpan);
blockSpan = new TextSpanAndCookie();
state = ParseState.WaitForBlockStart;
}
}
}
}
finally
{
// Make sure that the buffer is always unlocked when we exit this function.
buffer.UnlockBufferEx((uint)BufferLockFlags.BLF_READ);
}
}
示例4: addMarkersToDocument
private static void addMarkersToDocument(IVsTextLines textLines)
{
int lineCount;
textLines.GetLineCount(out lineCount);
for (int i = 0; i < lineCount; ++i)
{
string text;
int len;
textLines.GetLengthOfLine(i, out len);
textLines.GetLineText(i, 0, i, len, out text);
string cmt = "//";
string issueKey = "PL-1357";
if (text == null || !text.Contains(cmt) || !text.Contains(issueKey)) continue;
int cmtIdx = text.IndexOf(cmt);
int idx = text.IndexOf(issueKey);
if (idx < cmtIdx) continue;
addMarker(textLines, i, idx, idx + issueKey.Length);
}
}
示例5: 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);
//.........这里部分代码省略.........
示例6: 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;
}
示例7: PositionCaretForEditing
public int PositionCaretForEditing(IVsTextLines pBuffer, [ComAliasName("Microsoft.VisualStudio.TextManager.Interop.TextSpan")]VsTextSpan[] ts)
{
// If the formatted location of the $end$ position (the inserted comment) was on an
// empty line and indented, then we have already removed the white space on that line
// and the navigation location will be at column 0 on a blank line. We must now
// position the caret in virtual space.
if (indentCaretOnCommit)
{
int lineLength;
pBuffer.GetLengthOfLine(ts[0].iStartLine, out lineLength);
string lineText;
pBuffer.GetLineText(ts[0].iStartLine, 0, ts[0].iStartLine, lineLength, out lineText);
if (lineText == string.Empty)
{
int endLinePosition;
pBuffer.GetPositionOfLine(ts[0].iStartLine, out endLinePosition);
TextView.TryMoveCaretToAndEnsureVisible(new VirtualSnapshotPoint(TextView.TextSnapshot.GetPoint(endLinePosition), indentDepth));
}
}
return VSConstants.S_OK;
}
示例8: 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);
}
}
示例9: PositionCaretForEditing
public int PositionCaretForEditing(IVsTextLines pBuffer, [ComAliasName("Microsoft.VisualStudio.TextManager.Interop.TextSpan")]VsTextSpan[] ts)
{
// If the formatted location of the $end$ position (the inserted comment) was on an
// empty line and indented, then we have already removed the white space on that line
// and the navigation location will be at column 0 on a blank line. We must now
// position the caret in virtual space.
int lineLength;
pBuffer.GetLengthOfLine(ts[0].iStartLine, out lineLength);
string endLineText;
pBuffer.GetLineText(ts[0].iStartLine, 0, ts[0].iStartLine, lineLength, out endLineText);
int endLinePosition;
pBuffer.GetPositionOfLine(ts[0].iStartLine, out endLinePosition);
PositionCaretForEditingInternal(endLineText, endLinePosition);
return VSConstants.S_OK;
}
示例10: 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;
}
示例11: GetLineInfo
/// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState) {
int length;
NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
if (length == 0)
return null;
string text;
NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));
int state;
NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));
if (this.cachedLine == line && this.cachedLineText == text &&
this.cachedLineState == state && this.cachedLineInfo != null) {
return this.cachedLineInfo;
}
// recolorize the line, and cache the results
this.cachedLineInfo = null;
this.cachedLine = line;
this.cachedLineText = text;
this.cachedLineState = state;
NativeMethods.ThrowOnFailure(GetColorInfo(text, length, state));
//now it should be in the cache
return this.cachedLineInfo;
}
示例12: CollapseToDefinitions
public int CollapseToDefinitions(IVsTextLines textLines, IVsOutliningSession session){
if (textLines == null || session == null) return (int)HResult.E_INVALIDARG;
int lastLine;
int lastIdx;
string text;
textLines.GetLineCount(out lastLine );
textLines.GetLengthOfLine(--lastLine, out lastIdx);
textLines.GetLineText(0, 0, lastLine, lastIdx, out text);
NewOutlineRegion[] outlineRegions = this.GetCollapsibleRegions(text, VsShell.GetFilePath(textLines));
if (outlineRegions != null && outlineRegions.Length > 0)
session.AddOutlineRegions((uint)ADD_OUTLINE_REGION_FLAGS.AOR_PRESERVE_EXISTING, outlineRegions.Length, outlineRegions);
return 0;
}
示例13: GetLineInfo
/// <include file='doc\Colorizer.uex' path='docs/doc[@for="Colorizer.GetLineInfo"]/*' />
public virtual TokenInfo[] GetLineInfo(IVsTextLines buffer, int line, IVsTextColorState colorState)
{
int length;
NativeMethods.ThrowOnFailure(buffer.GetLengthOfLine(line, out length));
if (length == 0)
return null;
string text;
NativeMethods.ThrowOnFailure(buffer.GetLineText(line, 0, line, length, out text));
int state;
NativeMethods.ThrowOnFailure(colorState.GetColorStateAtStartOfLine(line, out state));
if (this.cachedLine == line && this.cachedLineText == text &&
this.cachedLineState == state && this.cachedLineInfo != null) {
return this.cachedLineInfo;
}
// recolorize the line, and cache the results
this.cachedLineInfo = null;
this.cachedLine = line;
this.cachedLineText = text;
this.cachedLineState = state;
// GetColorInfo will update the cache. Note that here we don't use NativeMethods.ThrowOnFailure
// because the return code is the current parsing state, not an HRESULT.
GetColorInfo(text, length, state);
//now it should be in the cache
return this.cachedLineInfo;
}
示例14: 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>();
string codeToFormat;
int endOfFirstLineIndex;
// Get 1st line and parse custom define
pBuffer.GetLengthOfLine(0, out endOfFirstLineIndex);
pBuffer.GetLineText(0, 0, 0, endOfFirstLineIndex, out codeToFormat);
Dictionary<string,string> defines = ParseDefineLine(codeToFormat);
AsmHighlighterScanner scanner = AsmHighlighterScannerFactory.GetScanner(filePath);
Scanner lexer = scanner.Lexer;
// Iterate on each line of the selection to format
for (int line = span.iStartLine; line <= span.iEndLine; line++)
{
int lineLength;
pBuffer.GetLengthOfLine(line, out lineLength);
pBuffer.GetLineText(line, 0, line, lineLength, out codeToFormat);
string codeToAssemble = ConvertToFasm(lexer, codeToFormat, defines);
lexer.SetSource(codeToFormat, 0);
int state = 0;
int start, end;
bool instructionFound = false, commentFound = false;
int commentStart = 0;
AsmHighlighterToken token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);
while (token != AsmHighlighterToken.EOF )
{
switch (token)
{
case AsmHighlighterToken.INSTRUCTION:
case AsmHighlighterToken.FPUPROCESSOR:
case AsmHighlighterToken.SIMDPROCESSOR:
instructionFound = true;
break;
case AsmHighlighterToken.COMMENT_LINE:
if (!commentFound)
{
commentFound = true;
commentStart = start;
}
break;
}
if ( instructionFound && commentFound )
{
byte[] buffer = null;
try
{
buffer = ManagedFasm.Assemble(codeToAssemble);
}
catch (Exception ex)
{
// Unable to parse instruction... skip
}
if (buffer != null)
{
}
TextSpan editTextSpan = new TextSpan();
editTextSpan.iStartLine = line;
editTextSpan.iEndLine = line;
editTextSpan.iStartIndex = commentStart;
editTextSpan.iEndIndex = commentStart+1;
if ((codeToFormat.Length - commentStart) > 2 && codeToFormat.Substring(commentStart, 2) == ";#")
{
editTextSpan.iEndIndex = editTextSpan.iEndIndex + 2;
}
string text = ";#" + ((buffer == null) ? "?" : string.Format("{0:X}",buffer.Length));
changeList.Add(new EditSpan(editTextSpan, text));
break;
}
token = (AsmHighlighterToken)lexer.GetNext(ref state, out start, out end);
}
}
return changeList;
}
示例15: GetTextFromVsTextLines
internal static string GetTextFromVsTextLines(IVsTextLines vsTextLines) {
int lines;
int lastLineLength;
VSErrorHandler.ThrowOnFailure(vsTextLines.GetLineCount(out lines));
VSErrorHandler.ThrowOnFailure(vsTextLines.GetLengthOfLine(lines - 1, out lastLineLength));
string text;
VSErrorHandler.ThrowOnFailure(vsTextLines.GetLineText(0, 0, lines - 1, lastLineLength, out text));
return text;
}