示例#1
0
        public int?GetDesiredIndentation(ITextSnapshotLine line)
        {
            // get point at the subject buffer
            var mappingPoint = _view.BufferGraph.CreateMappingPoint(line.Start, PointTrackingMode.Negative);

            // TODO (https://github.com/dotnet/roslyn/issues/5281): Remove try-catch.
            SnapshotPoint?point = null;

            try
            {
                point = mappingPoint.GetInsertionPoint(b => b.ContentType.IsOfType(_contentType.TypeName));
            }
            catch (ArgumentOutOfRangeException)
            {
                // Suppress this to work around DevDiv #144964.
                // Note: Other callers might be affected, but this is the narrowest workaround for the observed problems.
                // A fix is already being reviewed, so a broader change is not required.
                return(null);
            }

            if (!point.HasValue)
            {
                return(null);
            }

            // Currently, interactive smart indenter returns indentation based
            // solely on subject buffer's information and doesn't consider spaces
            // in interactive window itself. Note: This means the ITextBuffer passed
            // to ISmartIndent.GetDesiredIndentation is not this.view.TextBuffer.
            return(_indenter.GetDesiredIndentation(point.Value.GetContainingLine()));
        }
示例#2
0
        private int?GetSmartIndent(string content, int lineNumber)
        {
            AstRoot   ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var       document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            ISmartIndentProvider provider = EditorShell.Current.ExportProvider.GetExport <ISmartIndentProvider>().Value;
            ISmartIndent         indenter = provider.CreateSmartIndent(textView);

            return(indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNumber)));
        }
示例#3
0
        public int?GetDesiredIndentation(ITextSnapshotLine line)
        {
            // In markdown indent is default. In R block delegate to the R indenter.
            var point = _textView.MapDownToR(line.Start);

            if (point.HasValue)
            {
                return(_smartIndent.GetDesiredIndentation(point.Value.Snapshot.GetLineFromPosition(point.Value)));
            }
            return(null);
        }
示例#4
0
        public void Scope(string content, int lineNum, int expectedIndent)
        {
            AstRoot   ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var       document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            ISmartIndentProvider provider = _exportProvider.GetExportedValue <ISmartIndentProvider>();
            ISmartIndent         indenter = provider.CreateSmartIndent(textView);
            int?indent = indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNum));

            indent.Should().HaveValue().And.Be(expectedIndent);
        }
示例#5
0
        public void Scope(string content, int lineNum, int expectedIndent)
        {
            AstRoot   ast;
            ITextView textView = TextViewTest.MakeTextView(content, 0, out ast);
            var       document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast));

            var          cs       = _services.GetService <ICompositionService>();
            var          composer = new ContentTypeImportComposer <ISmartIndentProvider>(cs);
            var          provider = composer.GetImport(RContentTypeDefinition.ContentType);
            ISmartIndent indenter = provider.CreateSmartIndent(textView);
            int?         indent   = indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(lineNum));

            indent.Should().HaveValue().And.Be(expectedIndent);
        }
        public int?GetDesiredIndentation(ITextSnapshotLine line)
        {
            // get point at the subject buffer
            var mappingPoint = _view.BufferGraph.CreateMappingPoint(line.Start, PointTrackingMode.Negative);
            var point        = mappingPoint.GetInsertionPoint(b => b.ContentType.IsOfType(_contentType.TypeName));

            if (!point.HasValue)
            {
                return(null);
            }

            // Currently, interactive smart indenter returns indentation based
            // solely on subject buffer's information and doesn't consider spaces
            // in interactive window itself. Note: This means the ITextBuffer passed
            // to ISmartIndent.GetDesiredIndentation is not this.view.TextBuffer.
            return(_indenter.GetDesiredIndentation(point.Value.GetContainingLine()));
        }