private void InitializeRazorLSPTextBuffer(ITextBuffer textBuffer)
        {
            if (_lspEditorFeatureDetector.IsRemoteClient())
            {
                // We purposefully do not set ClientName's in remote client scenarios because we don't want to boot 2 langauge servers (one for both host and client).
                // The ClientName controls whether or not an ILanguageClient instantiates.

                // We still change the content type for remote scenarios in order to enable our TextMate grammar to light up the Razor editor properly.
                textBuffer.ChangeContentType(_razorLSPContentType, editTag: null);
            }
            else
            {
                // ClientName controls if the LSP infrastructure in VS will boot when it detects our Razor LSP contennt type. If the property exists then it will; otherwise
                // the text buffer will be ignored by the LSP
                textBuffer.Properties.AddProperty(LanguageClientConstants.ClientNamePropertyKey, RazorLanguageServerClient.ClientName);

                // Initialize the buffer with editor options.
                InitializeOptions(textBuffer);

                textBuffer.ChangeContentType(_razorLSPContentType, editTag: null);

                // Must track the document after changing the content type so any LSPDocuments created understand they're being created for a Razor LSP document.
                _lspDocumentManager.TrackDocument(textBuffer);
            }
        }
Exemplo n.º 2
0
        // Internal for testing
        internal void TextDocumentFactory_TextDocumentDisposed(object sender, TextDocumentEventArgs args)
        {
            if (args is null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            // Do a lighter check to see if we care about this document.
            if (IsRazorFilePath(args.TextDocument.FilePath))
            {
                // If we don't know about this document we'll no-op
                _lspDocumentManager.UntrackDocument(args.TextDocument.TextBuffer);

                if (_lspEditorFeatureDetector.IsRemoteClient() &&
                    args.TextDocument.TextBuffer.Properties.ContainsProperty(FilePathPropertyKey))
                {
                    // We no longer want to watch for guest buffer changes.
                    args.TextDocument.TextBuffer.Properties.RemoveProperty(FilePathPropertyKey);
                    args.TextDocument.TextBuffer.ChangedHighPriority -= RazorGuestBuffer_Changed;
                }
            }
        }
Exemplo n.º 3
0
        // Internal for testing
        internal void RazorBufferCreated(ITextBuffer textBuffer)
        {
            if (textBuffer is null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            if (!_lspEditorFeatureDetector.IsRemoteClient())
            {
                // Renames on open files don't dispose buffer state so we need to separately monitor the buffer for document renames to ensure
                // we can tell the lsp document manager when state changes.
                MonitorDocumentForRenames(textBuffer);

                // Only need to track documents on a host because we don't do any extra work on remote clients.
                _lspDocumentManager.TrackDocument(textBuffer);
            }
        }
Exemplo n.º 4
0
        // Internal for testing
        internal void RazorBufferCreated(ITextBuffer textBuffer)
        {
            if (textBuffer is null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            // Initialize the buffer with editor options.
            // Temporary: Ideally in remote scenarios, we should be using host's settings.
            // But we need this until that support is built.
            InitializeOptions(textBuffer);

            if (!_lspEditorFeatureDetector.IsRemoteClient())
            {
                // Only need to track documents on a host because we don't do any extra work on remote clients.
                _lspDocumentManager.TrackDocument(textBuffer);
            }
        }
Exemplo n.º 5
0
        // Internal for testing
        internal void RazorBufferCreated(ITextBuffer textBuffer)
        {
            if (textBuffer is null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            // Initialize the buffer with editor options.
            // Temporary: Ideally in remote scenarios, we should be using host's settings.
            // But we need this until that support is built.
            InitializeOptions(textBuffer);

            if (!_lspEditorFeatureDetector.IsRemoteClient())
            {
                // Renames on open files don't dispose buffer state so we need to separately monitor the buffer for document renames to ensure
                // we can tell the lsp document manager when state changes.
                MonitorDocumentForRenames(textBuffer);

                // Only need to track documents on a host because we don't do any extra work on remote clients.
                _lspDocumentManager.TrackDocument(textBuffer);
            }
        }