コード例 #1
0
        protected override void OnTextBufferCreated(ITextView textView, ITextBuffer textBuffer)
        {
            var clh = ContainedLanguageHost.GetHost(textView, textBuffer, _coreShell);

            OleControllerChain.InitEditorInstance(textBuffer, _coreShell.Services);
            base.OnTextBufferCreated(textView, textBuffer);
        }
コード例 #2
0
        protected override void OnTextBufferCreated(ITextView textView, ITextBuffer textBuffer)
        {
            var clh = ContainedLanguageHost.GetHost(textView, textBuffer, Services);

            VsAppShell.EnsurePackageLoaded(RGuidList.RPackageGuid);
            OleControllerChain.InitEditorInstance(textBuffer, Services);
            base.OnTextBufferCreated(textView, textBuffer);
        }
コード例 #3
0
        protected override void OnTextBufferCreated(ITextView textView, ITextBuffer textBuffer)
        {
            // Force creations
            var appShell = VsAppShell.Current;
            var clh      = ContainedLanguageHost.GetHost(textView, textBuffer, appShell);

            OleControllerChain.InitEditorInstance(textBuffer);
            base.OnTextBufferCreated(textView, textBuffer);
        }
コード例 #4
0
 public VsLegacyContainedLanguageHost(HtmlEditorDocument vsDocument, LanguageProjectionBuffer secondaryBuffer, IVsHierarchy hierarchy)
 {
     _modernContainedLanguageHost = (ContainedLanguageHost.GetHost(vsDocument.PrimaryView, secondaryBuffer.IProjectionBuffer) as IWebContainedLanguageHost);
     _secondaryBuffer             = secondaryBuffer;
     this.hierarchy = hierarchy;
     _vsDocument    = vsDocument;
     _vsDocument.OnDocumentClosing    += OnDocumentClosing;
     secondaryBuffer.MappingsChanging += OnMappingsChanging;
     secondaryBuffer.MappingsChanged  += OnMappingsChanged;
 }
コード例 #5
0
 private void OnMappingsChanged(object sender, MappingsChangedEventArgs e)
 {
     if (e.Mappings.Count > 0)
     {
         _languageBuffer.MappingsChanged -= OnMappingsChanged;
         IContainedLanguageHost host = ContainedLanguageHost.GetHost(TextView, _languageBuffer.IProjectionBuffer);
         host.SetContainedCommandTarget(TextView, ContainedLanguageTarget);
         ContainedLanguageTarget = null;
         TextView        = null;
         _languageBuffer = null;
     }
 }
コード例 #6
0
        protected override void OnTextViewDisconnected(ITextView textView, ITextBuffer textBuffer)
        {
            if (textBuffer != textView.TextBuffer)
            {
                var containedLanguageHost = ContainedLanguageHost.GetHost(textView, textBuffer);
                if (containedLanguageHost != null)
                {
                    containedLanguageHost.RemoveContainedCommandTarget(textView);
                }
            }

            base.OnTextViewDisconnected(textView, textBuffer);
        }
コード例 #7
0
        protected override void OnTextViewConnected(ITextView textView, ITextBuffer textBuffer)
        {
            var mainController = ServiceManager.GetService <TemplateMainController>(textView) ??
                                 new TemplateMainController(textView, textBuffer);

            if (textBuffer != textView.TextBuffer)
            {
                var containedLanguageHost = ContainedLanguageHost.GetHost(textView, textBuffer);
                if (containedLanguageHost != null)
                {
                    object nextFilter = containedLanguageHost.SetContainedCommandTarget(textView, mainController);
                    mainController.ChainedController = WebEditor.TranslateCommandTarget(textView, nextFilter);
                }
            }

            base.OnTextViewConnected(textView, textBuffer);
        }
コード例 #8
0
        protected override void OnTextViewConnected(ITextView textView, ITextBuffer textBuffer)
        {
            RMainController.Attach(textView, textBuffer, Shell);
            if (textBuffer != textView.TextBuffer)
            {
                // Projected scenario
                _containedLanguageHost = ContainedLanguageHost.GetHost(textView, textBuffer, Shell);
                if (_containedLanguageHost != null)
                {
                    _containedLanguageHost.Closing += OnContainedLanguageHostClosing;
                    _textBuffer = textBuffer;

                    var mainController = RMainController.FromTextView(textView);
                    var nextTarget     = _containedLanguageHost.SetContainedCommandTarget(textView, mainController);
                    // Convert chained target to ICommandTarget (chained target might be IOleCommandTarget and host will create a shim then).
                    mainController.ChainedController = nextTarget;
                }
            }
            base.OnTextViewConnected(textView, textBuffer);
        }
コード例 #9
0
        private static bool CanFormatRange(ITextView textView, ITextBuffer textBuffer, ITextRange formatRange)
        {
            // Make sure we are not formatting damaging the projected range in R Markdown
            // which looks like ```{r. 'r' should not separate from {.
            var host = ContainedLanguageHost.GetHost(textView, textBuffer);

            if (host != null)
            {
                ITextSnapshot snapshot = textBuffer.CurrentSnapshot;

                int startLine = snapshot.GetLineNumberFromPosition(formatRange.Start);
                int endLine   = snapshot.GetLineNumberFromPosition(formatRange.End);
                for (int i = startLine; i <= endLine; i++)
                {
                    if (!host.CanFormatLine(textView, textBuffer, i))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #10
0
        public static void HandleAutoformat(ITextView textView, IEditorShell editorShell, char typedChar)
        {
            if (!REditorSettings.AutoFormat)
            {
                return;
            }

            if (!REditorSettings.FormatScope && typedChar == '}')
            {
                return;
            }

            SnapshotPoint?rPoint = GetCaretPointInBuffer(textView);

            if (!rPoint.HasValue)
            {
                return;
            }

            var document = REditorDocument.FromTextBuffer(textView.TextBuffer);
            var ast      = document.EditorTree.AstRoot;

            // Make sure we are not formatting damaging the projected range in R Markdown
            // which looks like ```{r. 'r' should not separate from {.
            var host = ContainedLanguageHost.GetHost(textView, document.TextBuffer, editorShell);

            if (host != null && !host.CanFormatLine(textView, document.TextBuffer, document.TextBuffer.CurrentSnapshot.GetLineNumberFromPosition(rPoint.Value)))
            {
                return;
            }

            // We don't want to auto-format inside strings
            if (ast.IsPositionInsideString(rPoint.Value.Position))
            {
                return;
            }

            ITextBuffer subjectBuffer = rPoint.Value.Snapshot.TextBuffer;

            if (typedChar.IsLineBreak())
            {
                // Special case for hitting caret after } and before 'else'. We do want to format
                // the construct as '} else {' but if user types Enter after } and we auto-format
                // it will look as if the editor just eats the Enter. Instead, we will not be
                // autoformatting in this specific case. User can always format either the document
                // or select the block and reformat it.
                if (!IsBetweenCurlyAndElse(subjectBuffer, rPoint.Value.Position))
                {
                    var scopeStatement = GetFormatScope(textView, subjectBuffer, ast);
                    // Do not format large scope blocks for performance reasons
                    if (scopeStatement != null && scopeStatement.Length < 200)
                    {
                        FormatOperations.FormatNode(textView, subjectBuffer, editorShell, scopeStatement);
                    }
                    else if (CanFormatLine(textView, subjectBuffer, -1))
                    {
                        FormatOperations.FormatViewLine(textView, subjectBuffer, -1, editorShell);
                    }
                }
            }
            else if (typedChar == ';')
            {
                // Verify we are at the end of the string and not in a middle
                // of another string or inside a statement.
                ITextSnapshotLine line = subjectBuffer.CurrentSnapshot.GetLineFromPosition(rPoint.Value.Position);
                int    positionInLine  = rPoint.Value.Position - line.Start;
                string lineText        = line.GetText();
                if (positionInLine >= lineText.TrimEnd().Length)
                {
                    FormatOperations.FormatViewLine(textView, subjectBuffer, 0, editorShell);
                }
            }
            else if (typedChar == '}')
            {
                FormatOperations.FormatCurrentStatement(textView, subjectBuffer, editorShell, limitAtCaret: true, caretOffset: -1);
            }
        }