public GotoBraceCommand(ITextView textView, ITextBuffer textBuffer) : base(textView, _commands, false) { var importComposer = new ContentTypeImportComposer<IBraceMatcherProvider>(EditorShell.Current.CompositionService); _braceMatcherProvider = importComposer.GetImport(textBuffer.ContentType.TypeName); TextBuffer = textBuffer; }
private void InitEditorInstance(ITextBuffer textBuffer) { if (ServiceManager.GetService<IEditorInstance>(textBuffer) == null) { ContentTypeImportComposer<IEditorFactory> importComposer = new ContentTypeImportComposer<IEditorFactory>(_shell.CompositionService); IEditorFactory factory = importComposer.GetImport(textBuffer.ContentType.TypeName); IEditorInstance editorInstance = factory.CreateEditorInstance(textBuffer, new RDocumentFactory(_shell)); } }
public GotoBraceCommand(ITextView textView, ITextBuffer textBuffer, ICoreShell shell) : base(textView, _commands, false) { var importComposer = new ContentTypeImportComposer <IBraceMatcherProvider>(shell.GetService <ICompositionService>()); _braceMatcherProvider = importComposer.GetImport(textBuffer.ContentType.TypeName); TextBuffer = textBuffer; }
private void InitEditorInstance(ITextBuffer textBuffer) { if (ServiceManager.GetService <IEditorInstance>(textBuffer) == null) { ContentTypeImportComposer <IEditorFactory> importComposer = new ContentTypeImportComposer <IEditorFactory>(_shell.CompositionService); IEditorFactory factory = importComposer.GetImport(textBuffer.ContentType.TypeName); IEditorInstance editorInstance = factory.CreateEditorInstance(textBuffer, new RDocumentFactory(_shell)); } }
public GotoBraceCommand(ITextView textView, ITextBuffer textBuffer) : base(textView, _commands, false) { var importComposer = new ContentTypeImportComposer <IBraceMatcherProvider>(EditorShell.Current.CompositionService); _braceMatcherProvider = importComposer.GetImport(textBuffer.ContentType.TypeName); TextBuffer = textBuffer; }
public static IEditorInstance CreateEditorInstance(ITextBuffer textBuffer, ICompositionService compositionService) { var importComposer = new ContentTypeImportComposer <IEditorFactory>(compositionService); var factory = importComposer.GetImport(textBuffer.ContentType.TypeName); var documentFactoryImportComposer = new ContentTypeImportComposer <IEditorDocumentFactory>(compositionService); var documentFactory = documentFactoryImportComposer.GetImport(textBuffer.ContentType.TypeName); return(factory?.CreateEditorInstance(textBuffer, documentFactory)); }
public static void InitEditorInstance(ITextBuffer textBuffer) { if (ServiceManager.GetService<IEditorInstance>(textBuffer) == null) { var importComposer1 = new ContentTypeImportComposer<IEditorFactory>(VsAppShell.Current.CompositionService); var editorInstanceFactory = importComposer1.GetImport(textBuffer.ContentType.TypeName); var importComposer2 = new ContentTypeImportComposer<IVsEditorDocumentFactory>(VsAppShell.Current.CompositionService); var documentFactory = importComposer2.GetImport(textBuffer.ContentType.TypeName); var editorInstance = editorInstanceFactory.CreateEditorInstance(textBuffer, documentFactory); } }
public ValidatorManager() { EditorShell.Current.CompositionService.SatisfyImportsOnce(this); // Import validator providers var validatorImportComposer = new ContentTypeImportComposer<IValidatorProvider>(EditorShell.Current.CompositionService); var validatorProviderImports = validatorImportComposer.GetAllLazy(RContentTypeDefinition.ContentType); foreach (var import in validatorProviderImports) { _validatorProviders.Add(import.Value); } }
public static void InitEditorInstance(ITextBuffer textBuffer) { if (ServiceManager.GetService <IEditorInstance>(textBuffer) == null) { var importComposer1 = new ContentTypeImportComposer <IEditorFactory>(VsAppShell.Current.CompositionService); var editorInstanceFactory = importComposer1.GetImport(textBuffer.ContentType.TypeName); var importComposer2 = new ContentTypeImportComposer <IVsEditorDocumentFactory>(VsAppShell.Current.CompositionService); var documentFactory = importComposer2.GetImport(textBuffer.ContentType.TypeName); var editorInstance = editorInstanceFactory.CreateEditorInstance(textBuffer, documentFactory); } }
private void InitEditorInstance(ITextBuffer textBuffer) { if (ServiceManager.GetService<IEditorInstance>(textBuffer) == null) { ITextDocument textDocument; textBuffer.Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out textDocument); Debug.Assert(textDocument != null); ContentTypeImportComposer<IEditorFactory> importComposer = new ContentTypeImportComposer<IEditorFactory>(VsAppShell.Current.CompositionService); IEditorFactory factory = importComposer.GetImport(textBuffer.ContentType.TypeName); IEditorInstance editorInstance = factory.CreateEditorInstance(textBuffer, new VsMdEditorDocumentFactory()); } }
public ValidatorManager() { shell.Current.CompositionService.SatisfyImportsOnce(this); // Import validator providers var validatorImportComposer = new ContentTypeImportComposer <IValidatorProvider>(shell.Current.CompositionService); var validatorProviderImports = validatorImportComposer.GetAllLazy(RContentTypeDefinition.ContentType); foreach (var import in validatorProviderImports) { _validatorProviders.Add(import.Value); } }
public static void InitEditorInstance(ITextBuffer textBuffer, IServiceContainer services) { if (Languages.Editor.Services.ServiceManager.GetService <IEditorInstance>(textBuffer) == null) { var cs = services.GetService <ICompositionService>(); var importComposer1 = new ContentTypeImportComposer <IEditorFactory>(cs); var editorInstanceFactory = importComposer1.GetImport(textBuffer.ContentType.TypeName); var importComposer2 = new ContentTypeImportComposer <IVsEditorDocumentFactory>(cs); var documentFactory = importComposer2.GetImport(textBuffer.ContentType.TypeName); var editorInstance = editorInstanceFactory.CreateEditorInstance(textBuffer, documentFactory); } }
public static IEditorInstance CreateEditorInstance(ITextBuffer textBuffer, ICompositionService cs) { var importComposer = new ContentTypeImportComposer<IEditorFactory>(cs); var factory = importComposer.GetImport(textBuffer.ContentType.TypeName); var documentFactoryImportComposer = new ContentTypeImportComposer<IEditorDocumentFactory>(EditorShell.Current.CompositionService); var documentFactory = documentFactoryImportComposer.GetImport(textBuffer.ContentType.TypeName); // Debug.Assert(factory != null, String.Format("No editor factory found for content type {0}", textBuffer.ContentType.TypeName)); if(factory != null) // may be null if file type only support colorization, like VBScript return factory.CreateEditorInstance(textBuffer, documentFactory); return null; }
public virtual void BuildCommandSet() { // It is allowed here not to have host. The reason is that we allow using controller classes // without host as long as derived controller is adding commands manually. Without host there is // no composition service and hence we are unable to import command factories. if (EditorShell.Current.CompositionService != null) { var importComposer = new ContentTypeImportComposer<ICommandFactory>(EditorShell.Current.CompositionService); var commandFactories = importComposer.GetAll(TextBuffer.ContentType.TypeName); foreach (var factory in commandFactories) { var commands = factory.GetCommands(TextView, TextBuffer); AddCommandSet(commands); } } }
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); }
private void InitEditorInstance(ITextBuffer textBuffer) { if (ServiceManager.GetService <IEditorInstance>(textBuffer) == null) { ITextDocument textDocument; textBuffer.Properties.TryGetProperty <ITextDocument>(typeof(ITextDocument), out textDocument); Debug.Assert(textDocument != null); ContentTypeImportComposer <IEditorFactory> importComposer = new ContentTypeImportComposer <IEditorFactory>(VsAppShell.Current.CompositionService); IEditorFactory factory = importComposer.GetImport(textBuffer.ContentType.TypeName); IEditorInstance editorInstance = factory.CreateEditorInstance(textBuffer, new VsREditorDocumentFactory()); } }
public void SmartIndentTest05() { AstRoot ast; var textView = TextViewTest.MakeTextView(" x <- 1\r\n", 0, out ast); using (var document = new EditorDocumentMock(new EditorTreeMock(textView.TextBuffer, ast))) { var cs = _shell.GetService <ICompositionService>(); var composer = new ContentTypeImportComposer <ISmartIndentProvider>(cs); var provider = composer.GetImport(RContentTypeDefinition.ContentType); var indenter = (SmartIndenter)provider.CreateSmartIndent(textView); int?indent = indenter.GetDesiredIndentation(textView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1), IndentStyle.Block); indent.Should().HaveValue().And.Be(2); } }
public static IEditorInstance CreateEditorInstance(ITextBuffer textBuffer, ICompositionService cs) { var importComposer = new ContentTypeImportComposer <IEditorFactory>(cs); var factory = importComposer.GetImport(textBuffer.ContentType.TypeName); var documentFactoryImportComposer = new ContentTypeImportComposer <IEditorDocumentFactory>(EditorShell.Current.CompositionService); var documentFactory = documentFactoryImportComposer.GetImport(textBuffer.ContentType.TypeName); // Debug.Assert(factory != null, String.Format("No editor factory found for content type {0}", textBuffer.ContentType.TypeName)); if (factory != null) // may be null if file type only support colorization, like VBScript { return(factory.CreateEditorInstance(textBuffer, documentFactory)); } return(null); }
public virtual void BuildCommandSet() { // It is allowed here not to have host. The reason is that we allow using controller classes // without host as long as derived controller is adding commands manually. Without host there is // no composition service and hence we are unable to import command factories. if (_shell.CompositionService != null) { var importComposer = new ContentTypeImportComposer <ICommandFactory>(_shell.CompositionService); var commandFactories = importComposer.GetAll(TextBuffer.ContentType.TypeName); foreach (var factory in commandFactories) { var commands = factory.GetCommands(TextView, TextBuffer); AddCommandSet(commands); } } }
public BraceHighlighter(ITextView view, ITextBuffer textBuffer) { _textBuffer = textBuffer; _textView = view; var importComposer = new ContentTypeImportComposer <IBraceMatcherProvider>(EditorShell.Current.CompositionService); var braceMatcherProvider = importComposer.GetImport(textBuffer.ContentType.TypeName); if (braceMatcherProvider != null) { _braceMatcher = braceMatcherProvider.CreateBraceMatcher(view, textBuffer); view.LayoutChanged += OnViewLayoutChanged; view.Caret.PositionChanged += OnCaretPositionChanged; ServiceManager.AddService <BraceHighlighter>(this, _textView); } }
public int OnLoadCompleted(int fReload) { var adapterService = VsAppShell.Current.ExportProvider.GetExport <IVsEditorAdaptersFactoryService>().Value; // Set language service ID as early as possible, since it may change content type of the buffer, // e.g. in a weird scenario when someone does "Open With X Editor" on an Y file. Calling this // will change content type to the one language service specifies instead of the default one for // the file extension, and will ensure that correct editor factory is used. _textLines.SetLanguageServiceID(ref _languageServiceGuid); ITextBuffer diskBuffer = adapterService.GetDocumentBuffer(_textLines); Debug.Assert(diskBuffer != null); try { var editorInstance = ServiceManager.GetService <IEditorInstance>(diskBuffer); if (editorInstance == null) { var importComposer = new ContentTypeImportComposer <IEditorFactory>(VsAppShell.Current.CompositionService); var instancefactory = importComposer.GetImport(diskBuffer.ContentType.TypeName); Debug.Assert(instancefactory != null); var documentFactoryImportComposer = new ContentTypeImportComposer <IVsEditorDocumentFactory>(VsAppShell.Current.CompositionService); var documentFactory = documentFactoryImportComposer.GetImport(diskBuffer.ContentType.TypeName); Debug.Assert(documentFactory != null); editorInstance = instancefactory.CreateEditorInstance(diskBuffer, documentFactory); } Debug.Assert(editorInstance != null); adapterService.SetDataBuffer(_textLines, editorInstance.ViewBuffer); } finally { cp.Unadvise(cookie); cookie = 0; _textLines = null; _hierarchy = null; _trackers.Remove(this); _trackers = null; } return(VSConstants.S_OK); }
private void PopulateLanguageBuffer(IContentType contentType, IEnumerable<CodeLineArtifact> artifacts) { var pBuffer = ProjectionBufferManager.GetProjectionBuffer(contentType); var contentTypeImportComposer = new ContentTypeImportComposer<ICodeLanguageEmbedder>(WebEditor.CompositionService); var embedder = contentTypeImportComposer.GetImport(contentType); var fullSource = new StringBuilder(); if (embedder != null) fullSource.AppendLine(embedder.GlobalPrefix); var mappings = new List<ProjectionMapping>(); foreach (var block in artifacts.GroupBy(a => a.BlockInfo)) { IReadOnlyCollection<string> surround = null; if (embedder != null) surround = embedder.GetBlockWrapper(block.Select(a => a.GetText(EditorTree.TextSnapshot))); if (surround != null) fullSource.AppendLine(surround.FirstOrDefault()); foreach (var artifact in block) { if (artifact.Start >= EditorTree.TextSnapshot.Length || artifact.End > EditorTree.TextSnapshot.Length || artifact.TreatAs != ArtifactTreatAs.Code) continue; mappings.Add(new ProjectionMapping(artifact.InnerRange.Start, fullSource.Length, artifact.InnerRange.Length, AdditionalContentInclusion.All)); fullSource.AppendLine(artifact.GetText(EditorTree.TextSnapshot)); } if (surround != null) fullSource.AppendLine(surround.LastOrDefault()); } if (embedder != null) fullSource.AppendLine(embedder.GlobalSuffix); pBuffer.SetTextAndMappings(fullSource.ToString(), mappings.ToArray()); if (createdContentTypes.Add(contentType)) if (embedder != null) embedder.OnBlockCreated(EditorTree.TextBuffer, pBuffer); }
public int OnLoadCompleted(int fReload) { var adapterService = VsAppShell.Current.ExportProvider.GetExport<IVsEditorAdaptersFactoryService>().Value; // Set language service ID as early as possible, since it may change content type of the buffer, // e.g. in a weird scenario when someone does "Open With X Editor" on an Y file. Calling this // will change content type to the one language service specifies instead of the default one for // the file extension, and will ensure that correct editor factory is used. _textLines.SetLanguageServiceID(ref _languageServiceGuid); ITextBuffer diskBuffer = adapterService.GetDocumentBuffer(_textLines); Debug.Assert(diskBuffer != null); try { var editorInstance = ServiceManager.GetService<IEditorInstance>(diskBuffer); if (editorInstance == null) { var importComposer = new ContentTypeImportComposer<IEditorFactory>(VsAppShell.Current.CompositionService); var instancefactory = importComposer.GetImport(diskBuffer.ContentType.TypeName); Debug.Assert(instancefactory != null); var documentFactoryImportComposer = new ContentTypeImportComposer<IVsEditorDocumentFactory>(VsAppShell.Current.CompositionService); var documentFactory = documentFactoryImportComposer.GetImport(diskBuffer.ContentType.TypeName); Debug.Assert(documentFactory != null); editorInstance = instancefactory.CreateEditorInstance(diskBuffer, documentFactory); } Debug.Assert(editorInstance != null); adapterService.SetDataBuffer(_textLines, editorInstance.ViewBuffer); } finally { cp.Unadvise(cookie); cookie = 0; _textLines = null; _hierarchy = null; _trackers.Remove(this); _trackers = null; } return VSConstants.S_OK; }
/// <summary> /// Retrieves all services of a particular type available for the content type. /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="contentType">Content (file) type such as 'R' or 'Markdown'</param> /// <returns>Collection of service instances, if any</returns> public IEnumerable <T> GetAllServices <T>(string contentType) where T : class { var importComposer = new ContentTypeImportComposer <T>(_compositionService); return(importComposer.GetAll(contentType)); }
/// <summary> /// Locates services for a content type /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="contentType">Content (file) type such as 'R' or 'Markdown'</param> /// <returns>Service instance, if any</returns> public T GetService <T>(string contentType) where T : class { var importComposer = new ContentTypeImportComposer <T>(_compositionService); return(importComposer.GetImport(contentType)); }