public TextSnapshotMock(string content, ITextBuffer textBuffer, TextVersionMock version) { TextProvider = new TextStream(content); TextBuffer = textBuffer; _lines = MakeLines(content); _version = version; Change = new TextChangeMock(); }
/// <summary> /// Given RD data and function name parses the data and creates structured /// information about the function. Method returns multiple functions since /// RD data often provides information on several functions so in order /// to avoid processing same data multiple times parser extracts information /// on all related functions. /// </summary> public static IReadOnlyList<IFunctionInfo> GetFunctionInfos(string rdHelpData) { var tokenizer = new RdTokenizer(tokenizeRContent: false); ITextProvider textProvider = new TextStream(rdHelpData); IReadOnlyTextRangeCollection<RdToken> tokens = tokenizer.Tokenize(textProvider, 0, textProvider.Length); RdParseContext context = new RdParseContext(tokens, textProvider); return ParseFunctions(context); }
public void TextHelperTest_IsWhitespaceOnlyBetweenPositionsTest() { ITextProvider tp = new TextStream("0 \n3 \r 7 \r\n AB "); TextHelper.IsWhitespaceOnlyBetweenPositions(tp, 0, 1).Should().BeFalse(); TextHelper.IsWhitespaceOnlyBetweenPositions(tp, 1, 2).Should().BeTrue(); TextHelper.IsWhitespaceOnlyBetweenPositions(tp, 2, 5).Should().BeFalse(); TextHelper.IsWhitespaceOnlyBetweenPositions(tp, 5, 10).Should().BeFalse(); TextHelper.IsWhitespaceOnlyBetweenPositions(tp, tp.Length - 1, tp.Length).Should().BeTrue(); TextHelper.IsWhitespaceOnlyBetweenPositions(tp, 100, 200).Should().BeTrue(); }
public void TextHelperTest_IsNewLineAfterPositionTest() { ITextProvider tp = new TextStream("0 \n3 \r 7 \r\n "); TextHelper.IsNewLineAfterPosition(tp, 0).Should().BeFalse(); TextHelper.IsNewLineAfterPosition(tp, 1).Should().BeTrue(); TextHelper.IsNewLineAfterPosition(tp, 2).Should().BeTrue(); TextHelper.IsNewLineAfterPosition(tp, 3).Should().BeFalse(); TextHelper.IsNewLineAfterPosition(tp, 4).Should().BeTrue(); TextHelper.IsNewLineAfterPosition(tp, 5).Should().BeTrue(); TextHelper.IsNewLineAfterPosition(tp, 6).Should().BeFalse(); TextHelper.IsNewLineAfterPosition(tp, 7).Should().BeFalse(); TextHelper.IsNewLineAfterPosition(tp, 8).Should().BeTrue(); TextHelper.IsNewLineAfterPosition(tp, 9).Should().BeTrue(); TextHelper.IsNewLineAfterPosition(tp, 10).Should().BeTrue(); TextHelper.IsNewLineAfterPosition(tp, 11).Should().BeFalse(); TextHelper.IsNewLineAfterPosition(tp, 12).Should().BeFalse(); }
public void TextHelperTest_IsNewLineBeforePositionTest() { ITextProvider tp = new TextStream("01\n34\r678\r\nBC"); tp.IsNewLineBeforePosition(0).Should().BeFalse(); tp.IsNewLineBeforePosition(1).Should().BeFalse(); tp.IsNewLineBeforePosition(2).Should().BeFalse(); tp.IsNewLineBeforePosition(3).Should().BeTrue(); tp.IsNewLineBeforePosition(4).Should().BeFalse(); tp.IsNewLineBeforePosition(5).Should().BeFalse(); tp.IsNewLineBeforePosition(6).Should().BeTrue(); tp.IsNewLineBeforePosition(7).Should().BeFalse(); tp.IsNewLineBeforePosition(8).Should().BeFalse(); tp.IsNewLineBeforePosition(9).Should().BeFalse(); tp.IsNewLineBeforePosition(10).Should().BeTrue(); tp.IsNewLineBeforePosition(11).Should().BeTrue(); tp.IsNewLineBeforePosition(12).Should().BeFalse(); }
public static void TokenizeFileImplementation(CoreTestFilesFixture fixture, string name) { string testFile = fixture.GetDestinationPath(name); string baselineFile = testFile + ".tokens"; string text = fixture.LoadDestinationFile(name); ITextProvider textProvider = new TextStream(text); var tokenizer = new RTokenizer(); var tokens = tokenizer.Tokenize(textProvider, 0, textProvider.Length); string actual = DebugWriter.WriteTokens<RToken, RTokenType>(tokens); if (_regenerateBaselineFiles) { // Update this to your actual enlistment if you need to update baseline baselineFile = Path.Combine(fixture.SourcePath, @"Tokenization\", Path.GetFileName(testFile)) + ".tokens"; TestFiles.UpdateBaseline(baselineFile, actual); } else { TestFiles.CompareToBaseLine(baselineFile, actual); } }
public static IReadOnlyList<ISignatureInfo> ParseSignatures(string usageContent, IReadOnlyDictionary<string, string> argumentsDescriptions = null) { // RD signature text may contain \dots sequence which denotes ellipsis. // R parser does not know about it and hence we will replace \dots by ... // Also, signatures may contain S3 method info like // '\method{as.matrix}{data.frame}(x, rownames.force = NA, \dots)' // which we need to filter out since they are irrelevant to intellisense. List<ISignatureInfo> signatures = new List<ISignatureInfo>(); usageContent = usageContent.Replace(@"\dots", "..."); RTokenizer tokenizer = new RTokenizer(separateComments: true); IReadOnlyTextRangeCollection<RToken> collection = tokenizer.Tokenize(usageContent); ITextProvider textProvider = new TextStream(usageContent); TokenStream<RToken> tokens = new TokenStream<RToken>(collection, RToken.EndOfStreamToken); var parseContext = new ParseContext(textProvider, TextRange.FromBounds(tokens.CurrentToken.Start, textProvider.Length), tokens, tokenizer.CommentTokens); while (!tokens.IsEndOfStream()) { // Filter out '\method{...}{}(signature) if (tokens.CurrentToken.TokenType == RTokenType.OpenCurlyBrace) { // Check if { is preceded by \method } if (tokens.CurrentToken.TokenType != RTokenType.Identifier) { break; } string functionName = textProvider.GetText(tokens.CurrentToken); tokens.MoveToNextToken(); ISignatureInfo info = ParseSignature(functionName, parseContext, argumentsDescriptions); if (info != null) { signatures.Add(info); } } return signatures; }
/// <summary> /// Parse HTML from a string /// </summary> /// <param name="text">String to parse</param> public void Parse(string text) { TextStream ts = new TextStream(text); Parse(ts); }