Example #1
0
        public static string FormatText(Microsoft.CodeAnalysis.Options.OptionSet optionSet, string input, int startOffset, int endOffset)
        {
            var inputTree = CSharpSyntaxTree.ParseText(input);

            var root   = inputTree.GetRoot();
            var doc    = Formatter.Format(root, new TextSpan(startOffset, endOffset - startOffset), IdeApp.TypeSystemService.Workspace, optionSet);
            var result = doc.ToFullString();

            return(result.Substring(startOffset, endOffset + result.Length - input.Length - startOffset));
        }
Example #2
0
        protected override async void CorrectIndentingImplementation(PolicyContainer policyParent, TextEditor editor, int line)
        {
            var lineSegment = editor.GetLine(line);

            if (lineSegment == null)
            {
                return;
            }

            try {
                Microsoft.CodeAnalysis.Options.OptionSet options = null;

                foreach (var doc in IdeApp.Workbench.Documents)
                {
                    if (doc.Editor == editor)
                    {
                        options = await doc.GetOptionsAsync();

                        break;
                    }
                }

                if (options == null)
                {
                    var policy     = policyParent.Get <CSharpFormattingPolicy> (MimeType);
                    var textpolicy = policyParent.Get <TextStylePolicy> (MimeType);
                    options = policy.CreateOptions(textpolicy);
                }

                var tracker = new CSharpIndentEngine(options);

                tracker.Update(IdeApp.Workbench.ActiveDocument.Editor, lineSegment.Offset);
                for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.Length; i++)
                {
                    tracker.Push(editor.GetCharAt(i));
                }

                string curIndent = lineSegment.GetIndentation(editor);

                int nlwsp = curIndent.Length;
                if (!tracker.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.LengthIncludingDelimiter && editor.GetCharAt(lineSegment.Offset + nlwsp) == '*'))
                {
                    // Possibly replace the indent
                    string newIndent = tracker.ThisLineIndent;
                    if (newIndent != curIndent)
                    {
                        editor.ReplaceText(lineSegment.Offset, nlwsp, newIndent);
                    }
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while indenting", e);
            }
        }
Example #3
0
 public void SetOptions(OptionSet optionSet) => _globalOptionService.SetOptions(optionSet);
Example #4
0
 string IEditorConfigStorageLocation2.GetEditorConfigString(object value, OptionSet optionSet)
 => GetEditorConfigString((T)value, optionSet);