本文整理汇总了C#中ICompletionWidget.GetChar方法的典型用法代码示例。如果您正苦于以下问题:C# ICompletionWidget.GetChar方法的具体用法?C# ICompletionWidget.GetChar怎么用?C# ICompletionWidget.GetChar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICompletionWidget
的用法示例。
在下文中一共展示了ICompletionWidget.GetChar方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentParameterIndex
// Returns the index of the parameter where the cursor is currently positioned.
// -1 means the cursor is outside the method parameter list
// 0 means no parameter entered
// > 0 is the index of the parameter (1-based)
public int GetCurrentParameterIndex(ICompletionWidget widget, CodeCompletionContext ctx)
{
int cursor = widget.CreateCodeCompletionContext().TriggerOffset;
int i = ctx.TriggerOffset;
//if (i < 0 || i >= editor.Length || editor.GetCharAt (i) == ')')
// return -1;
if (i > cursor)
return -1;
else if (i == cursor)
return 0;
int parameterIndex = 1;
while (i++ < cursor) {
if (i >= widget.TextLength)
break;
char ch = widget.GetChar (i);
if (ch == ',')
parameterIndex++;
else if (ch == ')')
return -1;
}
return parameterIndex;
}
示例2: GetCurrentParameterIndex
internal static int GetCurrentParameterIndex (ICompletionWidget widget, int offset, int memberStart)
{
int cursor = widget.CurrentCodeCompletionContext.TriggerOffset;
int i = offset;
if (i > cursor)
return -1;
if (i == cursor)
return 1;
int index = memberStart + 1;
int depth = 0;
do {
char c = widget.GetChar (i - 1);
if (c == ',' && depth == 1)
index++;
if (c == '<')
depth++;
if (c == '>')
depth--;
i++;
} while (i <= cursor && depth > 0);
return depth == 0 ? -1 : index;
}
示例3: GetCurrentParameterIndex
internal static int GetCurrentParameterIndex (ICompletionWidget widget, int offset, int memberStart)
{
int cursor = widget.CurrentCodeCompletionContext.TriggerOffset;
int i = offset;
if (i > cursor)
return -1;
if (i == cursor)
return 1; // parameters are 1 based
IEnumerable<string> types = MonoDevelop.Ide.DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
CSharpIndentEngine engine = new CSharpIndentEngine (MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<CSharpFormattingPolicy> (types));
int index = memberStart + 1;
int parentheses = 0;
int bracket = 0;
do {
char c = widget.GetChar (i - 1);
engine.Push (c);
switch (c) {
case '{':
if (!engine.IsInsideOrdinaryCommentOrString)
bracket++;
break;
case '}':
if (!engine.IsInsideOrdinaryCommentOrString)
bracket--;
break;
case '(':
if (!engine.IsInsideOrdinaryCommentOrString)
parentheses++;
break;
case ')':
if (!engine.IsInsideOrdinaryCommentOrString)
parentheses--;
break;
case ',':
if (!engine.IsInsideOrdinaryCommentOrString && parentheses == 1 && bracket == 0)
index++;
break;
}
i++;
} while (i <= cursor && parentheses >= 0);
return parentheses != 1 || bracket > 0 ? -1 : index;
}
示例4: 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() : "";
}
示例5: GetCharacterType
/*
public static CharacterType GetCharacterType(char c)
{
if(IsLetterDigitOrUnderscore(c))
return CharacterType.LetterDigitOrUnderscore;
if(Char.IsWhiteSpace(c))
return CharacterType.WhiteSpace;
return CharacterType.Other;
}
public static int GetFirstNonWSChar(IDocument document, int offset)
{
while (offset < document.TextLength && Char.IsWhiteSpace(document.GetCharAt(offset))) {
++offset;
}
return offset;
}
public static int FindWordEnd(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
int endPos = line.Offset + line.Length;
while (offset < endPos && IsLetterDigitOrUnderscore(document.GetCharAt(offset))) {
++offset;
}
return offset;
}
public static int FindWordStart(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
while (offset > line.Offset && !IsLetterDigitOrUnderscore(document.GetCharAt(offset - 1))) {
--offset;
}
return offset;
}
// go forward to the start of the next word
// if the cursor is at the start or in the middle of a word we move to the end of the word
// and then past any whitespace that follows it
// if the cursor is at the start or in the middle of some whitespace we move to the start of the
// next word
public static int FindNextWordStart(IDocument document, int offset)
{
int originalOffset = offset;
LineSegment line = document.GetLineSegmentForOffset(offset);
int endPos = line.Offset + line.Length;
// lets go to the end of the word, whitespace or operator
CharacterType t = GetCharacterType(document.GetCharAt(offset));
while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == t) {
++offset;
}
// now we're at the end of the word, lets find the start of the next one by skipping whitespace
while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == CharacterType.WhiteSpace) {
++offset;
}
return offset;
}
// go back to the start of the word we are on
// if we are already at the start of a word or if we are in whitespace, then go back
// to the start of the previous word
public static int FindPrevWordStart(IDocument document, int offset)
{
int originalOffset = offset;
LineSegment line = document.GetLineSegmentForOffset(offset);
if (offset > 0) {
CharacterType t = GetCharacterType(document.GetCharAt(offset - 1));
while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t) {
--offset;
}
// if we were in whitespace, and now we're at the end of a word or operator, go back to the beginning of it
if(t == CharacterType.WhiteSpace && offset > line.Offset) {
t = GetCharacterType(document.GetCharAt(offset - 1));
while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t) {
--offset;
}
}
}
return offset;
}
public static string GetLineAsString(IDocument document, int lineNumber)
{
LineSegment line = document.GetLineSegment(lineNumber);
return document.GetText(line.Offset, line.Length);
}
*/
static bool ScanLineComment(ICompletionWidget widget, int offset)
{
while (offset > 0 && offset < widget.TextLength) {
char ch = widget.GetChar (offset);
switch (ch) {
//.........这里部分代码省略.........
示例6: SearchBracketBackward
public static int SearchBracketBackward(ICompletionWidget widget, int offset, char openBracket, char closingBracket)
{
// FIXME: use iters
int brackets = -1;
bool inString = false;
bool inChar = false;
bool blockComment = false;
while (offset >= 0 && offset < widget.TextLength) {
char ch = widget.GetChar(offset);
switch (ch) {
case '/':
if (blockComment) {
if (widget.GetChar(offset + 1)== '*') {
blockComment = false;
}
}
if (!inString && !inChar && offset + 1 < widget.TextLength) {
if (offset > 0 && widget.GetChar(offset - 1) == '*') {
blockComment = true;
}
}
break;
case '"':
if (!inChar && !blockComment && !ScanLineComment(widget, offset)) {
inString = !inString;
}
break;
case '\'':
if (!inString && !blockComment && !ScanLineComment(widget, offset)) {
inChar = !inChar;
}
break;
default :
if (ch == closingBracket) {
if (!(inString || inChar || blockComment) && !ScanLineComment(widget, offset)) {
--brackets;
}
} else if (ch == openBracket) {
if (!(inString || inChar || blockComment) && !ScanLineComment(widget, offset)) {
++brackets;
if (brackets == 0) {
return offset;
}
}
}
break;
}
--offset;
}
return - 1;
}