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); } }
private void UnBindFromSession() { // Don't do anything with an invalid session (dismissed session is ok). if (_session == null) { return; } // Unsubscribe from some events. _session.SelectedSignatureChanged -= this.OnSession_SelectedSignatureChanged; if (_session.SelectedSignature != null) { _session.SelectedSignature.CurrentParameterChanged -= this.OnSelectedSignature_CurrentParameterChanged; } ((INotifyCollectionChanged)_session.Signatures).CollectionChanged -= this.OnSignatures_CollectionChanged; _signatureWpfTextView.SizeAllocated -= this.OnTextView_LayoutChanged; this.PagerVisibility = false; this.SignatureDocumentationVisibility = false; this.CurrentParameterVisibility = false; // Make sure that our property added to the signature text buffer is released. Also, the buffer should be empty. _signatureTextBuffer.Replace(new Span(0, _signatureTextBuffer.CurrentSnapshot.Length), string.Empty); _signatureTextBuffer.Properties.RemoveProperty(typeof(ISignatureHelpSession)); // Change the content-type of our signature text buffer back to text. This is how we'll ensure that our classifiers // always get run. When we change the content type when binding to a session, our classifiers will be re-run. _signatureTextBuffer.ChangeContentType(this.TextContentType, null); // Null-out our ref to the session. _session = null; }
private void InitializeRazorLSPTextBuffer(string filePath, 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); // 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); // Temporary: The guest needs to react to the host manually applying edits and moving the cursor. // This can be removed once the client starts supporting snippets. textBuffer.Properties.AddProperty(FilePathPropertyKey, filePath); textBuffer.ChangedHighPriority += RazorGuestBuffer_Changed; } 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); } }
private void NewBufferChanged(object sender, TextContentChangedEventArgs e) { bool isCommand = IsCommand(e.After.GetExtent()); ITextBuffer buffer = e.After.TextBuffer; IContentType contentType = buffer.ContentType; IContentType newContentType = null; if (contentType == _languageContentType) { if (isCommand) { newContentType = _commandContentType; } } else { if (!isCommand) { newContentType = _languageContentType; } } if (newContentType != null) { buffer.ChangeContentType(newContentType, editTag: null); } }
object CreateSignatureObject() { if (session.IsDismissed) return null; var signature = session.SelectedSignature; if (signature == null) return null; bool prettyPrintedContent = false; var text = signature.Content; if (text == null) { prettyPrintedContent = true; text = signature.PrettyPrintedContent; } if (text == null) return null; signatureTextBuffer.Properties[SignatureHelpConstants.UsePrettyPrintedContentBufferKey] = prettyPrintedContent; signatureTextBuffer.Replace(new Span(0, signatureTextBuffer.CurrentSnapshot.Length), text); var oldContentType = signatureTextBuffer.ContentType; var atSpan = signature.ApplicableToSpan; Debug.Assert(atSpan != null); if (atSpan != null) { var span = atSpan.GetStartPoint(atSpan.TextBuffer.CurrentSnapshot); signatureTextBuffer.ChangeContentType(GetSigHelpContentType(span.Snapshot.ContentType), null); } if (signatureClassifier == null || oldContentType != signatureTextBuffer.ContentType) { UnregisterSignatureClassifierEvents(); signatureClassifier = classifierAggregatorService.GetClassifier(signatureTextBuffer); RegisterSignatureClassifierEvents(); } var classificationSpans = signatureClassifier.GetClassificationSpans(new SnapshotSpan(signatureTextBuffer.CurrentSnapshot, 0, signatureTextBuffer.CurrentSnapshot.Length)); var propsSpans = classificationSpans.Select(a => new TextRunPropertiesAndSpan(a.Span.Span, classificationFormatMap.GetTextProperties(a.ClassificationType))); return TextBlockFactory.Create(text, classificationFormatMap.DefaultTextProperties, propsSpans, TextBlockFactory.Flags.DisableSetTextBlockFontFamily | TextBlockFactory.Flags.DisableFontSize); }
private void ChangeContentType(ITextBuffer buffer) { IContentType fakeXLang = Registry.GetContentType(ContentTypes.XLang); buffer.ChangeContentType(fakeXLang, FakeTag); }
protected override void Initialize() { base.Initialize(); IComponentModel compMod = GetService(typeof(SComponentModel)) as IComponentModel; ITextBufferFactoryService bufferFactory = compMod.GetService <ITextBufferFactoryService>(); ITextEditorFactoryService editorFactory = compMod.GetService <ITextEditorFactoryService>(); IVsEditorAdaptersFactoryService adapterFactory = compMod.GetService <IVsEditorAdaptersFactoryService>(); IContentTypeRegistryService registryService = compMod.GetService <IContentTypeRegistryService>(); //completionBroker = compMod.GetService<ICompletionBroker>(); textView = adapterFactory.CreateVsTextViewAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); IVsTextBuffer textBuffer = adapterFactory.CreateVsTextBufferAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); uint textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT | (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL; textBuffer.InitializeContent("", 0); textView.Initialize(textBuffer as IVsTextLines, IntPtr.Zero, textViewInitFlags, null); // Create Dev10 objects _textView = adapterFactory.GetWpfTextView(textView); mefTextBuffer = adapterFactory.GetDataBuffer(textBuffer); IVsUserData userData = textView as IVsUserData; if (userData != null) { Guid g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost; object obj; int hr = userData.GetData(ref g, out obj); if (hr == VSConstants.S_OK) { _textViewHost = obj as IWpfTextViewHost; } } // disable zoom view _textView.Options.SetOptionValue(DefaultTextViewHostOptions.ZoomControlId, false); //Initialize the history if (null == history) { history = new HistoryBuffer(); } adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length)); IContentType ivsdContentType = registryService.GetContentType(VSDContentTypeDefinition.ContentType); mefTextBuffer.ChangeContentType(ivsdContentType, null); // init console input WriteConsoleInputSymbol(); return; }
private static void UpdateTextBufferContentType(ITextBuffer textBuffer, IContentType contentType) { if (textBuffer == null || contentType == null) { return; } textBuffer.ChangeContentType(contentType, null); }
public void SaveAs(string filePath, bool overwrite, bool createFolder, IContentType newContentType) { if (newContentType == null) { throw new ArgumentNullException(nameof(newContentType)); } SaveAs(filePath, overwrite, createFolder); // content type won't be changed if the save fails (in which case SaveAs will throw an exception) _textBuffer.ChangeContentType(newContentType, null); }
object CreateUIObject(string text, IContentType contentType, SignatureHelpClassifierContext context) { otherTextBuffer.Properties[SignatureHelpConstants.SignatureHelpClassifierContextBufferKey] = context; otherTextBuffer.Replace(new Span(0, otherTextBuffer.CurrentSnapshot.Length), text); var oldContentType = otherTextBuffer.ContentType; otherTextBuffer.ChangeContentType(contentType, null); if (otherClassifier == null || oldContentType != contentType) { (otherClassifier as IDisposable)?.Dispose(); otherClassifier = classifierAggregatorService.GetClassifier(otherTextBuffer); } var classificationSpans = otherClassifier.GetClassificationSpans(new SnapshotSpan(otherTextBuffer.CurrentSnapshot, 0, otherTextBuffer.CurrentSnapshot.Length)); var propsSpans = classificationSpans.Select(a => new TextRunPropertiesAndSpan(a.Span.Span, classificationFormatMap.GetTextProperties(a.ClassificationType))); var result = TextBlockFactory.Create(text, classificationFormatMap.DefaultTextProperties, propsSpans, TextBlockFactory.Flags.DisableSetTextBlockFontFamily | TextBlockFactory.Flags.DisableFontSize); otherTextBuffer.Properties.RemoveProperty(SignatureHelpConstants.SignatureHelpClassifierContextBufferKey); return result; }
protected override void Initialize() { base.Initialize(); IComponentModel compMod = GetService(typeof(SComponentModel)) as IComponentModel; ITextBufferFactoryService bufferFactory = compMod.GetService<ITextBufferFactoryService>(); ITextEditorFactoryService editorFactory = compMod.GetService<ITextEditorFactoryService>(); IVsEditorAdaptersFactoryService adapterFactory = compMod.GetService<IVsEditorAdaptersFactoryService>(); IContentTypeRegistryService registryService = compMod.GetService<IContentTypeRegistryService>(); completionBroker = compMod.GetService<ICompletionBroker>(); textView = adapterFactory.CreateVsTextViewAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); IVsTextBuffer textBuffer = adapterFactory.CreateVsTextBufferAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); uint textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT | (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL; textBuffer.InitializeContent("", 0); textView.Initialize(textBuffer as IVsTextLines, IntPtr.Zero, textViewInitFlags, null); // Create Dev10 objects _textView = adapterFactory.GetWpfTextView(textView); mefTextBuffer = adapterFactory.GetDataBuffer(textBuffer); IVsUserData userData = textView as IVsUserData; if (userData != null) { Guid g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost; object obj; int hr = userData.GetData(ref g, out obj); if (hr == VSConstants.S_OK) { _textViewHost = obj as IWpfTextViewHost; } } //Initialize the history history = new HistoryBuffer(); // Create the stream on top of the text buffer. textStream = new TextBufferStream(mefTextBuffer); // Initialize the engine. InitializeEngine(); IContentType ipContentType = registryService.GetContentType(PyContentTypeDefinition.ConsoleContentType); mefTextBuffer.ChangeContentType(ipContentType, null); adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length)); // Set the title of the window. this.Caption = Resources.ToolWindowTitle; // Set the icon of the toolwindow. this.BitmapResourceID = 301; this.BitmapIndex = 0; return; }
protected override void Initialize() { base.Initialize(); IComponentModel compMod = GetService(typeof(SComponentModel)) as IComponentModel; ITextBufferFactoryService bufferFactory = compMod.GetService <ITextBufferFactoryService>(); ITextEditorFactoryService editorFactory = compMod.GetService <ITextEditorFactoryService>(); IVsEditorAdaptersFactoryService adapterFactory = compMod.GetService <IVsEditorAdaptersFactoryService>(); IContentTypeRegistryService registryService = compMod.GetService <IContentTypeRegistryService>(); completionBroker = compMod.GetService <ICompletionBroker>(); textView = adapterFactory.CreateVsTextViewAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); IVsTextBuffer textBuffer = adapterFactory.CreateVsTextBufferAdapter(GetService(typeof(IOleServiceProvider)) as IOleServiceProvider); uint textViewInitFlags = (uint)TextViewInitFlags.VIF_DEFAULT | (uint)TextViewInitFlags.VIF_HSCROLL | (uint)TextViewInitFlags.VIF_VSCROLL; textBuffer.InitializeContent("", 0); textView.Initialize(textBuffer as IVsTextLines, IntPtr.Zero, textViewInitFlags, null); // Create Dev10 objects _textView = adapterFactory.GetWpfTextView(textView); mefTextBuffer = adapterFactory.GetDataBuffer(textBuffer); IVsUserData userData = textView as IVsUserData; if (userData != null) { Guid g = Microsoft.VisualStudio.Editor.DefGuidList.guidIWpfTextViewHost; object obj; int hr = userData.GetData(ref g, out obj); if (hr == VSConstants.S_OK) { _textViewHost = obj as IWpfTextViewHost; } } //Initialize the history history = new HistoryBuffer(); // Create the stream on top of the text buffer. textStream = new TextBufferStream(mefTextBuffer); // Initialize the engine. InitializeEngine(); IContentType ipContentType = registryService.GetContentType(PyContentTypeDefinition.ConsoleContentType); mefTextBuffer.ChangeContentType(ipContentType, null); adapterFactory.GetWpfTextView(textView).Caret.MoveTo(new SnapshotPoint(mefTextBuffer.CurrentSnapshot, mefTextBuffer.CurrentSnapshot.Length)); // Set the title of the window. this.Caption = Resources.ToolWindowTitle; // Set the icon of the toolwindow. this.BitmapResourceID = 301; this.BitmapIndex = 0; return; }