Example #1
0
        public static ITextBuffer ToITextBuffer(this IVsTextLayer vsTextLayer)
        {
            IVsTextLines vsTextLines;

            vsTextLayer.GetBaseBuffer(out vsTextLines);

            return(vsTextLines.ToITextBuffer());
        }
Example #2
0
 private bool TryGetLineIndentation(IVsTextLayer vsTextLayer, IVsLanguageLineIndent vsLineIdent, int lineNumber, out int preferredIndentation)
 {
     if (ErrorHandler.Failed(vsLineIdent.GetIndentPosition(vsTextLayer, lineNumber, out preferredIndentation)))
     {
         preferredIndentation = 0;
         return(false);
     }
     return(true);
 }
        public int Format(IVsTextLayer textLayer, TextSpan[] selections)
        {
            var waitIndicator = this.Package.ComponentModel.GetService <IWaitIndicator>();
            var result        = VSConstants.S_OK;

            waitIndicator.Wait(
                "Intellisense",
                allowCancel: true,
                action: c => result = FormatWorker(textLayer, selections, c.CancellationToken));

            return(result);
        }
Example #5
0
        public bool TryGetLineIndentation(ITextSnapshotLine line, out int preferredIndentation)
        {
            IVsTextLayer          vsTextLayer          = this.subjectBuffer.ToIVsTextBuffer() as IVsTextLayer;
            IVsLanguageLineIndent vsLanguageLineIndent = this.VsLanguageLineIndent;

            if ((vsLanguageLineIndent != null) && (vsTextLayer != null))
            {
                return(this.TryGetLineIndentation(vsTextLayer, vsLanguageLineIndent, line.LineNumber, out preferredIndentation));
            }
            preferredIndentation = 0;
            return(false);
        }
Example #6
0
        public bool TryGetLineIndentation(ITextSnapshotLine line, IEditorOptions options, out string indentationString)
        {
            IVsTextLayer          vsTextLayer          = this.subjectBuffer.ToIVsTextBuffer() as IVsTextLayer;
            IVsLanguageLineIndent vsLanguageLineIndent = this.VsLanguageLineIndent;

            if ((vsLanguageLineIndent != null) && (vsTextLayer != null))
            {
                return(this.TryGetLineIndentation(vsTextLayer, vsLanguageLineIndent, options, line.LineNumber, out indentationString));
            }
            indentationString = string.Empty;
            return(false);
        }
Example #7
0
        private bool TryGetLineIndentation(IVsTextLayer vsTextLayer, IVsLanguageLineIndent vsLineIdent, IEditorOptions options, int lineNumber, out string indentationString)
        {
            int num;

            if (!this.TryGetLineIndentation(vsTextLayer, vsLineIdent, lineNumber, out num))
            {
                indentationString = string.Empty;
                return(false);
            }
            indentationString = this.GetIndentationString(options, num);
            return(true);
        }
        private int FormatWorker(IVsTextLayer textLayer, TextSpan[] selections, CancellationToken cancellationToken)
        {
            var textBuffer = this.EditorAdaptersFactoryService.GetDataBuffer((IVsTextBuffer)textLayer);

            if (textBuffer == null)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            var document = textBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();

            if (document == null)
            {
                return(VSConstants.E_FAIL);
            }

            var documentSyntax    = ParsedDocument.CreateSynchronously(document, cancellationToken);
            var text              = documentSyntax.Text;
            var root              = documentSyntax.Root;
            var formattingOptions = textBuffer.GetSyntaxFormattingOptions(EditorOptionsService, document.Project.LanguageServices, explicitFormat: true);

            var ts           = selections.Single();
            var start        = text.Lines[ts.iStartLine].Start + ts.iStartIndex;
            var end          = text.Lines[ts.iEndLine].Start + ts.iEndIndex;
            var adjustedSpan = GetFormattingSpan(root, start, end);

            // Since we know we are on the UI thread, lets get the base indentation now, so that there is less
            // cleanup work to do later in Venus.
            var ruleFactory = Workspace.Services.GetService <IHostDependentFormattingRuleFactoryService>();
            var rules       = ruleFactory.CreateRule(documentSyntax, start).Concat(Formatter.GetDefaultFormattingRules(document.Project.Services));

            // use formatting that return text changes rather than tree rewrite which is more expensive
            var formatter       = document.GetRequiredLanguageService <ISyntaxFormattingService>();
            var originalChanges = formatter.GetFormattingResult(root, SpecializedCollections.SingletonEnumerable(adjustedSpan), formattingOptions, rules, cancellationToken)
                                  .GetTextChanges(cancellationToken);

            var originalSpan     = RoslynTextSpan.FromBounds(start, end);
            var formattedChanges = ruleFactory.FilterFormattedChanges(document.Id, originalSpan, originalChanges);

            if (formattedChanges.IsEmpty())
            {
                return(VSConstants.S_OK);
            }

            // create new formatted document
            var formattedDocument = document.WithText(text.WithChanges(formattedChanges));

            Workspace.ApplyDocumentChanges(formattedDocument, cancellationToken);

            return(VSConstants.S_OK);
        }
        public int Format(IVsTextLayer textLayer, TextSpan[] selections)
        {
            var result = VSConstants.S_OK;
            var uiThreadOperationExecutor = this.Package.ComponentModel.GetService <IUIThreadOperationExecutor>();

            uiThreadOperationExecutor.Execute(
                "Intellisense",
                defaultDescription: "",
                allowCancellation: true,
                showProgress: false,
                action: c => result = FormatWorker(textLayer, selections, c.UserCancellationToken));

            return(result);
        }
Example #10
0
 private bool TryFormat(IVsTextLayer vsTextLayer, IVsLanguageTextOps languageTextOp, SnapshotSpan span)
 {
     return(false);
     //Position position = span.Start.ToCSharpPosition(null);
     //Position position2 = span.End.ToCSharpPosition(null);
     //TextSpan[] ptsSel = new TextSpan[1];
     //TextSpan span2 = new TextSpan
     //{
     //    iStartLine = position.Line,
     //    iStartIndex = position.Character,
     //    iEndLine = position2.Line,
     //    iEndIndex = position2.Character
     //};
     //ptsSel[0] = span2;
     //return ErrorHandler.Succeeded(languageTextOp.Format(vsTextLayer, ptsSel));
 }
        private int FormatWorker(IVsTextLayer textLayer, TextSpan[] selections, CancellationToken cancellationToken)
        {
            var textBuffer = this.EditorAdaptersFactoryService.GetDataBuffer((IVsTextBuffer)textLayer);

            if (textBuffer == null)
            {
                return(VSConstants.E_UNEXPECTED);
            }

            var document = textBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();

            if (document == null)
            {
                return(VSConstants.E_FAIL);
            }

            var text = document.GetTextAsync(cancellationToken).WaitAndGetResult(cancellationToken);
            var root = document.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);

            var ts           = selections.Single();
            int start        = text.Lines[ts.iStartLine].Start + ts.iStartIndex;
            int end          = text.Lines[ts.iEndLine].Start + ts.iEndIndex;
            var adjustedSpan = GetFormattingSpan(root, start, end);

            // Since we know we are on the UI thread, lets get the base indentation now, so that there is less
            // cleanup work to do later in Venus.
            var ruleFactory = this.Workspace.Services.GetService <IHostDependentFormattingRuleFactoryService>();
            var rules       = ruleFactory.CreateRule(document, start).Concat(Formatter.GetDefaultFormattingRules(document));

            // use formatting that return text changes rather than tree rewrite which is more expensive
            var originalChanges = Formatter.GetFormattedTextChanges(root, adjustedSpan, document.Project.Solution.Workspace, rules: rules, cancellationToken: cancellationToken);

            var originalSpan     = RoslynTextSpan.FromBounds(start, end);
            var formattedChanges = ruleFactory.FilterFormattedChanges(document, originalSpan, originalChanges);

            if (formattedChanges.IsEmpty())
            {
                return(VSConstants.S_OK);
            }

            // create new formatted document
            var formattedDocument = document.WithText(text.WithChanges(formattedChanges));

            formattedDocument.Project.Solution.Workspace.ApplyDocumentChanges(formattedDocument, cancellationToken);

            return(VSConstants.S_OK);
        }
Example #12
0
 public virtual int GetPairExtent(IVsTextLayer textLayer, TextAddress textAddress, TextSpan[] span) => VSConstants.E_NOTIMPL;
Example #13
0
 int IVsLanguageTextOps.GetDataTip(IVsTextLayer pTextLayer, TextSpan[] ptsSel, TextSpan[] ptsTip, out string pbstrText)
 {
     pbstrText = string.Empty;
     return(VSConstants.E_NOTIMPL);
 }
Example #14
0
 public int GetPairExtent(IVsTextLayer pTextLayer, TextAddress ta, TextSpan[] pts)
 {
     return(VSConstants.E_NOTIMPL);
 }
Example #15
0
 public int Format(IVsTextLayer pTextLayer, TextSpan[] ptsSel)
 {
     return(VSConstants.E_NOTIMPL);
 }
 public int GetDataTip(IVsTextLayer pTextLayer, TextSpan[] ptsSel, TextSpan[] ptsTip, out string pbstrText)
 {
     pbstrText = null;
     return FAILED;
 }
 public int GetWordExtent(IVsTextLayer pTextLayer, TextAddress ta, WORDEXTFLAGS flags, TextSpan[] pts)
 {
     return FAILED;
 }
Example #18
0
 public virtual int GetWordExtent(IVsTextLayer textLayer, TextAddress textAddress, WORDEXTFLAGS flags, TextSpan[] span) {
     return VSConstants.E_NOTIMPL;
 }
Example #19
0
 public int Format(IVsTextLayer pTextLayer, TextSpan[] ptsSel)
 {
     return failed;
 }
Example #20
0
 public virtual int GetDataTip(IVsTextLayer textLayer, TextSpan[] span, TextSpan[] tipSpan, out string text) {
     text = null;
     return VSConstants.E_NOTIMPL;
 }
Example #21
0
 public virtual int GetPairExtent(IVsTextLayer textLayer, TextAddress textAddress, TextSpan[] span) {
     return VSConstants.E_NOTIMPL;
 }
Example #22
0
 public virtual int Format(IVsTextLayer textLayer, TextSpan[] span) {
     return VSConstants.E_NOTIMPL;
 }
Example #23
0
 int IVsLanguageTextOps.GetWordExtent(IVsTextLayer pTextLayer, TextAddress ta, WORDEXTFLAGS flags, TextSpan[] pts)
 {
     return(VSConstants.E_NOTIMPL);
 }
Example #24
0
 int IVsLanguageTextOps.GetPairExtent(IVsTextLayer pTextLayer, TextAddress ta, TextSpan[] pts)
 {
     return(VSConstants.E_NOTIMPL);
 }
 public int GetWordExtent(IVsTextLayer pTextLayer, TextAddress ta, WORDEXTFLAGS flags, TextSpan[] pts)
 {
     return(failed);
 }
Example #26
0
 int IVsLanguageTextOps.Format(IVsTextLayer pTextLayer, TextSpan[] ptsSel)
 {
     return VSConstants.E_NOTIMPL;
 }
 public int GetWordExtent(IVsTextLayer textLayer, TextAddress ta, WORDEXTFLAGS flags, TextSpan[] textSpan)
 => VSConstants.E_NOTIMPL;
Example #28
0
 int IVsLanguageTextOps.GetDataTip(IVsTextLayer pTextLayer, TextSpan[] ptsSel, TextSpan[] ptsTip, out string pbstrText)
 {
     pbstrText = string.Empty;
     return VSConstants.E_NOTIMPL;
 }
 public int Format(IVsTextLayer pTextLayer, TextSpan[] ptsSel)
 {
     return FAILED;
 }
Example #30
0
 int IVsLanguageTextOps.GetPairExtent(IVsTextLayer pTextLayer, TextAddress ta, TextSpan[] pts)
 {
     return VSConstants.E_NOTIMPL;
 }
 public int GetPairExtent(IVsTextLayer pTextLayer, TextAddress ta, TextSpan[] pts)
 {
     return FAILED;
 }
Example #32
0
 int IVsLanguageTextOps.GetWordExtent(IVsTextLayer pTextLayer, TextAddress ta, WORDEXTFLAGS flags, TextSpan[] pts)
 {
     return VSConstants.E_NOTIMPL;
 }
Example #33
0
 /// <summary>
 /// Displays a tip over a span of text when the mouse hovers over this location.
 /// </summary>
 /// <param name="pTextLayer">[in] An <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextLayer"/> object representing the text file.</param>
 /// <param name="ptsSel">[in] Span of text relevant to the specified text layer. For more information, see <see cref="T:Microsoft.VisualStudio.TextManager.Interop.TextSpan"/>.</param>
 /// <param name="ptsTip">[out] Returns a span of text to center the tip over. For more information, see <see cref="N:Microsoft.VisualStudio.TextManager.Interop"/>.</param>
 /// <param name="pbstrText">[out] Returns the text of the tip to display.</param>
 /// <returns>
 /// If the method succeeds, it returns <see cref="F:Microsoft.VisualStudio.VSConstants.S_OK"/>. If it fails, it returns an error code.
 /// </returns>
 public int GetDataTip(IVsTextLayer pTextLayer, TextSpan[] ptsSel, TextSpan[] ptsTip, out string pbstrText)
 {
     pbstrText = "";
     return(VSConstants.E_NOTIMPL);
 }
 public int GetPairExtent(IVsTextLayer pTextLayer, TextAddress ta, TextSpan[] pts)
 {
     return VSConstants.E_NOTIMPL;
 }
Example #35
0
 public int GetWordExtent(IVsTextLayer pTextLayer, TextAddress ta, WORDEXTFLAGS flags, TextSpan[] pts)
 {
     return(VSConstants.E_NOTIMPL);
 }
Example #36
0
 public int GetIndentPosition(IVsTextLayer pBaseLayer, int BaseBufferLineIndex, out int pIndentPosition)
 {
     pIndentPosition = 4;
     return(VSConstants.S_OK);
 }
Example #37
0
 public virtual int Format(IVsTextLayer textLayer, TextSpan[] span) => VSConstants.E_NOTIMPL;
 public int GetDataTip(IVsTextLayer pTextLayer, TextSpan[] ptsSel, TextSpan[] ptsTip, out string pbstrText)
 {
     pbstrText = null;
     return(failed);
 }
 public int GetIndentPosition(IVsTextLayer pBaseLayer, int BaseBufferLineIndex, out int pIndentPosition)
 {
     throw new NotImplementedException();
 }
Example #40
0
 int IVsLanguageTextOps.Format(IVsTextLayer pTextLayer, TextSpan[] ptsSel)
 {
     return(VSConstants.E_NOTIMPL);
 }
 public int Format(IVsTextLayer pTextLayer, TextSpan[] ptsSel)
 {
     return(failed);
 }
 /// <summary>
 /// Displays a tip over a span of text when the mouse hovers over this location.
 /// </summary>
 /// <param name="pTextLayer">[in] An <see cref="T:Microsoft.VisualStudio.TextManager.Interop.IVsTextLayer"/> object representing the text file.</param>
 /// <param name="ptsSel">[in] Span of text relevant to the specified text layer. For more information, see <see cref="T:Microsoft.VisualStudio.TextManager.Interop.TextSpan"/>.</param>
 /// <param name="ptsTip">[out] Returns a span of text to center the tip over. For more information, see <see cref="N:Microsoft.VisualStudio.TextManager.Interop"/>.</param>
 /// <param name="pbstrText">[out] Returns the text of the tip to display.</param>
 /// <returns>
 /// If the method succeeds, it returns <see cref="F:Microsoft.VisualStudio.VSConstants.S_OK"/>. If it fails, it returns an error code.
 /// </returns>
 public int GetDataTip(IVsTextLayer pTextLayer, TextSpan[] ptsSel, TextSpan[] ptsTip, out string pbstrText)
 {
     pbstrText = "";
     return VSConstants.E_NOTIMPL;
 }
 public int GetPairExtent(IVsTextLayer pTextLayer, TextAddress ta, TextSpan[] pts)
 {
     return(failed);
 }
 public int Format(IVsTextLayer pTextLayer, TextSpan[] ptsSel)
 {
     return VSConstants.E_NOTIMPL;
 }
 public int GetPairExtent(IVsTextLayer textLayer, TextAddress ta, TextSpan[] textSpan)
 => VSConstants.E_NOTIMPL;
Example #46
0
 public virtual int GetWordExtent(IVsTextLayer textLayer, TextAddress textAddress, WORDEXTFLAGS flags, TextSpan[] span)
 {
     return(VSConstants.E_NOTIMPL);
 }
Example #47
0
 public virtual int Format(IVsTextLayer textLayer, TextSpan[] span)
 {
     return(VSConstants.E_NOTIMPL);
 }
 public int GetWordExtent(IVsTextLayer pTextLayer, TextAddress ta, WORDEXTFLAGS flags, TextSpan[] pts)
 {
     return VSConstants.E_NOTIMPL;
 }