Exemplo n.º 1
0
 private void EnsureLanguageProjectionBuffer()
 {
     if (_languageProjectionBuffer == null)
     {
         ProjectionBufferManager service = ServiceManager.GetService <ProjectionBufferManager>(_viewBuffer);
         if (service != null)
         {
             if (Path.GetExtension(_fullPath) == ".vbhtml")
             {
                 _languageProjectionBuffer = (service.GetProjectionBuffer(".vb") as LanguageProjectionBuffer);
             }
             else
             {
                 _languageProjectionBuffer = (service.GetProjectionBuffer(".cs") as LanguageProjectionBuffer);
             }
         }
     }
     if (_linePragmaReader == null)
     {
         if (Path.GetExtension(_fullPath) == ".vbhtml")
         {
             _linePragmaReader = EmbeddedLanguageLinePragmaReaderFactory.Create("vb");
             return;
         }
         _linePragmaReader = EmbeddedLanguageLinePragmaReaderFactory.Create("c#");
     }
 }
        private void PopulateLanguageBuffer(IContentType contentType, IEnumerable <CodeLineArtifact> artifacts)
        {
            var pBuffer = ProjectionBufferManager.GetProjectionBuffer(contentType);

            var embedder = Mef.GetImport <ICodeLanguageEmbedder>(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);
                }
            }
        }
Exemplo n.º 3
0
        private IProjectionBuffer CreateProjectionBuffer(ITextDataModel dataModel)
        {
            var projectionBufferManager = new ProjectionBufferManager(
                dataModel.DataBuffer,
                ProjectionBufferFactory,
                ContentTypeRegistryService,
                Hlsl.HlslConstants.ContentTypeName);

            return(projectionBufferManager.ViewBuffer);
        }
Exemplo n.º 4
0
        public MdEditorDocument(IEditorBuffer editorBuffer, IServiceContainer services)
        {
            _services = services;

            EditorBuffer = editorBuffer;
            EditorBuffer.AddService(this);

            var textBuffer = editorBuffer.As <ITextBuffer>();

            _projectionBufferManager = new ProjectionBufferManager(textBuffer, services, MdProjectionContentTypeDefinition.ContentType, RContentTypeDefinition.ContentType);
            ContainedLanguageHandler = new RLanguageHandler(textBuffer, _projectionBufferManager, services);
            ContainedLanguageHost    = new RContainedLanguageHost(this, _projectionBufferManager.ContainedLanguageBuffer);
        }
Exemplo n.º 5
0
        public static string GetFilePath(this ITextView textView)
        {
            string path = null;

            if (textView != null && !textView.IsClosed)
            {
                if (textView.TextBuffer is IProjectionBuffer)
                {
                    var pbm = ProjectionBufferManager.FromTextBuffer(textView.TextBuffer);
                    path = pbm?.DiskBuffer.GetFilePath();
                }
                if (string.IsNullOrEmpty(path))
                {
                    path = textView.TextBuffer.GetFilePath();
                }
            }
            return(path);
        }
Exemplo n.º 6
0
        public ProjectionEditorInstance(ITextBuffer diskBuffer, IEditorDocumentFactory documentFactory)
        {
            if (diskBuffer == null)
            {
                throw new ArgumentNullException(nameof(diskBuffer));
            }
            if (documentFactory == null)
            {
                throw new ArgumentNullException(nameof(documentFactory));
            }

            DiskBuffer = diskBuffer;
            _document  = documentFactory.CreateDocument(this);

            var projectionBufferManager = ProjectionBufferManager.FromTextBuffer(diskBuffer);

            ViewBuffer = projectionBufferManager.ViewBuffer;

            ServiceManager.AddService <IEditorInstance>(this, DiskBuffer);
        }
Exemplo n.º 7
0
        public CodeBackgroundTextAdornment(
            IWpfTextView view,
            IClassificationFormatMapService classificationFormatMapService,
            IClassificationTypeRegistryService classificationTypeRegistry) {

            _view = view;
            _layer = view.GetAdornmentLayer("CodeBackgroundTextAdornment");

            _classificationTypeRegistry = classificationTypeRegistry;
            _classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(view);

            // Advise to events
            _classificationFormatMap.ClassificationFormatMappingChanged += OnClassificationFormatMappingChanged;
            _view.LayoutChanged += OnLayoutChanged;
            _view.Closed += OnClosed;

            var projectionBufferManager = ProjectionBufferManager.FromTextBuffer(view.TextBuffer);
            if (projectionBufferManager != null) {
                projectionBufferManager.MappingsChanged += OnMappingsChanged;
                _contanedLanguageHandler = projectionBufferManager.DiskBuffer.GetService<IContainedLanguageHandler>();
            }

            FetchColors();
        }
Exemplo n.º 8
0
        private static IEditorBuffer CreateViewBuffer(ITextBuffer diskBuffer, ITextDocumentFactoryService textDocumentFactoryService)
        {
            var projectionBufferManager = ProjectionBufferManager.FromTextBuffer(diskBuffer);

            return(new EditorBuffer(projectionBufferManager.ViewBuffer, textDocumentFactoryService));
        }