/// <summary> /// Get current Gherkin language setting by scanning first 5 lines /// </summary> /// <param name="document"></param> /// <returns>language defined in tag or English as default language</returns> public static string CurrentLanguage(ICSharpCode.AvalonEdit.Document.TextDocument document) { var location = new Ast.Location(); ICSharpCode.AvalonEdit.Document.DocumentLine line = document.GetLineByNumber(1); while (line != null) { string line_text = document.GetText(line.Offset, line.TotalLength); Token token = new Token(new GherkinLine(line_text, line.LineNumber), location); try { if (s_TokenMatcher.Match_Language(token) && IsSupported(token.MatchedText)) { return(token.MatchedText); } if (line.LineNumber > 5) { return(DEFAULT_LANGUAGE); } line = line.NextLine; } catch { return(DEFAULT_LANGUAGE); } } return(DEFAULT_LANGUAGE); }
public static string GetWordAround(this ICSharpCode.AvalonEdit.Document.TextDocument doc, int offset) { if (offset < 0 || offset >= doc.TextLength) { return(string.Empty); } int start, end; //find start for (start = offset; start >= 0; start--) { var c = doc.GetCharAt(start); if (!char.IsLetterOrDigit(c) && c != '_') { start++; break; } } //find end for (end = start; end < doc.TextLength; end++) { var c = doc.GetCharAt(end); if (!char.IsLetterOrDigit(c) && c != '_') { break; } } return(doc.GetText(start, end - start)); }
public IEnumerable <ISelectedCompletionData> GetCompletionData() { var lastLine = text.Lines.Last(); var context = text.GetText(lastLine).TrimStart('>'); var words = context.Split(' '); var last = words.Last().TrimEnd('.'); List <CompletionData> data = new List <CompletionData>(); if (eProvider.IsEnum(last, ref data)) { return(data); } else if (char.IsUpper(last[0]) && sProvider.IsClassName(last, ref data)) { return(data); } else { var result = _service.Executor.ExecuteScript(last); MethodInfo[] lMethods = new MethodInfo[0]; if (result.ReturnValue != null) { var type = result.ReturnValue.GetType(); Type[] genType; if (LinqExtensionProvider.IsLinqType(type, out genType)) { lMethods = LinqExtensionProvider.GetExtensions(type); } var extensions = type.GetExtensionMethods(); var props = type.GetMembers(BindingFlags.Public | BindingFlags.Instance) .Where(p => char.IsUpper(p.Name[0])) .Concat(extensions) .Concat(lMethods) .Select(p => p.Name) .OrderBy(p => p) .Distinct() .Select(p => new CompletionData(p)); return(props); } } return(new CompletionData[0]); }