Пример #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;
        }
Пример #2
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);
        }
Пример #3
0
        private static string Format(string original, uint tabSize = 4, uint indentSize = 4, bool usingTabs = false, FormattingOptions formattingOptions = null)
        {
            LuaFeatureContainer featureContainer = new LuaFeatureContainer();
            Range range = new Range(0, original.Length);

            if (formattingOptions == null)
            {
                formattingOptions = new FormattingOptions(new List<DisableableRules>(), tabSize, indentSize, usingTabs);
            }

            List<TextEditInfo> textEdits = featureContainer.Formatter.Format(new SourceText(original), range, formattingOptions);

            var buffer = host.CreateTextBuffer(original);
            var edit = buffer.CreateEdit();

            foreach (var textEdit in textEdits)
            {
                edit.Replace(textEdit.Start, textEdit.Length, textEdit.ReplacingWith);
            }

            var applied = edit.Apply();

            return applied.GetText();
        }
Пример #4
0
        private static int SmartIndent(string text, int lineNumber)
        {
            LuaFeatureContainer featureContainer = new LuaFeatureContainer();

            var buffer = host.CreateTextBuffer(text);
            var lineSnapshot = buffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber);
            int position = lineSnapshot.Start.Position;

            return featureContainer.Formatter.SmartIndent(new SourceText(text), position);
        }