Example #1
0
        internal static string FormatOnPaste(string original, PasteInfo pasteInfo)
        {
            var buffer = host.CreateTextBuffer(original);
            var prePastSnapshot = buffer.CurrentSnapshot;
            var bufferEdit = buffer.CreateEdit();
            bufferEdit.Replace(pasteInfo.Start, pasteInfo.Length, pasteInfo.PasteString);
            var bufferApplied = bufferEdit.Apply();
            SnapshotSpan? span = EditorUtilities.GetPasteSpan(prePastSnapshot, bufferApplied);

            if (span != null)
            {
                SnapshotSpan newSpan = (SnapshotSpan)span;
                var featureContainer = new LuaFeatureContainer();
                SourceText sourceText = new SourceText(bufferApplied.GetText());
                Range range = new Range(newSpan.Start.Position, newSpan.Length);
                List<TextEditInfo> edits = featureContainer.Formatter.Format(sourceText, range,
                    new FormattingOptions(new List<DisableableRules>(), 4, 4, false));
                var pastedBufferEdit = buffer.CreateEdit();
                foreach (TextEditInfo edit in edits)
                {
                    pastedBufferEdit.Replace(edit.Start, edit.Length, edit.ReplacingWith);
                }
                var pasteApplied = pastedBufferEdit.Apply();
                return pasteApplied.GetText();
            }

            return original;
        }
Example #2
0
        public SyntaxTree Get(SourceText sourceText)
        {
            Requires.NotNull(sourceText, nameof(sourceText));

            SyntaxTree syntaxTree;
            if (this.sources.TryGetValue(sourceText, out syntaxTree))
            {
                return syntaxTree;
            }

            syntaxTree = Parser.Parse(sourceText.TextReader);
            this.sources.Add(sourceText, syntaxTree);

            return syntaxTree;
        }
Example #3
0
        internal SourceText Get(ITextSnapshot textSnapshot)
        {
            Requires.NotNull(textSnapshot, nameof(textSnapshot));

            SourceText sourceText = null;
            if (this.sources.TryGetValue(textSnapshot, out sourceText))
            {
                return sourceText;
            }

            sourceText = new SourceText(textSnapshot.GetText());
            this.sources.Add(textSnapshot, sourceText);

            return sourceText;
        }
Example #4
0
        private static void ClassificationAndOrderTest(string text, Classification[] classifications, string[] tokenTexts)
        {
            var featureContainer = new LuaFeatureContainer();
            SourceText sourceText = new SourceText(text);

            List<Classification> actualClassifications = new List<Classification>();
            List<string> actualTokenTexts = new List<string>();

            foreach (TagInfo tagInfo in featureContainer.Colourizer.ColorizeParserTokens(sourceText))
            {
                actualClassifications.Add(tagInfo.Classification);
                actualTokenTexts.Add(text.Substring(tagInfo.Start, tagInfo.Length));
            }

            Assert.Equal(classifications, actualClassifications);
            Assert.Equal(tokenTexts, actualTokenTexts);
        }