Пример #1
0
        public IVsTextLines GetPrimaryTextLines()
        {
            if (_bufferCoordinator == null)
            {
                return(null);
            }

            IVsTextLines buffer = null;

            _bufferCoordinator.GetPrimaryBuffer(out buffer);

            return(buffer);
        }
Пример #2
0
        public ContainedLanguage(
            IVsTextBufferCoordinator bufferCoordinator,
            IComponentModel componentModel,
            TProject project,
            IVsHierarchy hierarchy,
            uint itemid,
            TLanguageService languageService,
            SourceCodeKind sourceCodeKind,
            IFormattingRule vbHelperFormattingRule = null)
            : base(project)
        {
            this.BufferCoordinator = bufferCoordinator;
            this.ComponentModel    = componentModel;
            this.Project           = project;
            _languageService       = languageService;

            this.Workspace = componentModel.GetService <VisualStudioWorkspace>();
            _editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();

            // Get the ITextBuffer for the secondary buffer
            IVsTextLines secondaryTextLines;

            Marshal.ThrowExceptionForHR(bufferCoordinator.GetSecondaryBuffer(out secondaryTextLines));
            var secondaryVsTextBuffer = (IVsTextBuffer)secondaryTextLines;

            SetSubjectBuffer(_editorAdaptersFactoryService.GetDocumentBuffer(secondaryVsTextBuffer));

            var bufferTagAggregatorFactory = ComponentModel.GetService <IBufferTagAggregatorFactoryService>();

            _bufferTagAggregator = bufferTagAggregatorFactory.CreateTagAggregator <ITag>(SubjectBuffer);

            IVsTextLines primaryTextLines;

            Marshal.ThrowExceptionForHR(bufferCoordinator.GetPrimaryBuffer(out primaryTextLines));
            var primaryVsTextBuffer = (IVsTextBuffer)primaryTextLines;
            var dataBuffer          = (IProjectionBuffer)_editorAdaptersFactoryService.GetDataBuffer(primaryVsTextBuffer);

            SetDataBuffer(dataBuffer);

            this.ContainedDocument = new ContainedDocument(
                this, sourceCodeKind, this.Workspace, hierarchy, itemid, componentModel, vbHelperFormattingRule);

            // TODO: Can contained documents be linked or shared?
            this.Project.AddDocument(this.ContainedDocument, isCurrentContext: true);
        }