Пример #1
0
        public ContainedDocument(
            AbstractContainedLanguage containedLanguage,
            SourceCodeKind sourceCodeKind,
            Workspace workspace,
            IVsHierarchy hierarchy,
            uint itemId,
            IComponentModel componentModel,
            IFormattingRule vbHelperFormattingRule)
        {
            Contract.ThrowIfNull(containedLanguage);

            _containedLanguage = containedLanguage;
            _sourceCodeKind    = sourceCodeKind;
            _componentModel    = componentModel;
            _workspace         = workspace;
            _optionService     = _workspace.Services.GetService <IOptionService>();
            _hostType          = GetHostType();

            var rdt = (IVsRunningDocumentTable)componentModel.GetService <SVsServiceProvider>().GetService(typeof(SVsRunningDocumentTable));

            IVsHierarchy sharedHierarchy;
            uint         itemIdInSharedHierarchy;
            var          isSharedHierarchy = LinkedFileUtilities.TryGetSharedHierarchyAndItemId(hierarchy, itemId, out sharedHierarchy, out itemIdInSharedHierarchy);

            var filePath = isSharedHierarchy
                ? rdt.GetMonikerForHierarchyAndItemId(sharedHierarchy, itemIdInSharedHierarchy)
                : rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId);

            // we couldn't look up the document moniker in RDT for a hierarchy/item pair
            // Since we only use this moniker as a key, we could fall back to something else, like the document name.
            if (filePath == null)
            {
                Debug.Assert(false, "Could not get the document moniker for an item in its hierarchy.");
                filePath = hierarchy.GetDocumentNameForHierarchyAndItemId(itemId);
            }

            if (Project.Hierarchy != null)
            {
                string moniker;
                Project.Hierarchy.GetCanonicalName(itemId, out moniker);
                _itemMoniker = moniker;
            }

            this.Key     = new DocumentKey(Project, filePath);
            this.Id      = DocumentId.CreateNewId(Project.Id, filePath);
            this.Folders = containedLanguage.Project.GetFolderNames(itemId);
            this.Loader  = TextLoader.From(containedLanguage.SubjectBuffer.AsTextContainer(), VersionStamp.Create(), filePath);
            _differenceSelectorService = componentModel.GetService <ITextDifferencingSelectorService>();
            _snapshotTracker           = new ReiteratedVersionSnapshotTracker(_containedLanguage.SubjectBuffer);
            _vbHelperFormattingRule    = vbHelperFormattingRule;
        }
Пример #2
0
        protected void AddFile(string filename, SourceCodeKind sourceCodeKind)
        {
            bool getIsCurrentContext(IVisualStudioHostDocument document) => LinkedFileUtilities.IsCurrentContextHierarchy(document, RunningDocumentTable);

            var itemid = Hierarchy?.TryGetItemId(filename) ?? VSConstants.VSITEMID_NIL;

            var folderNames = ImmutableArray <string> .Empty;

            if (itemid != VSConstants.VSITEMID_NIL)
            {
                folderNames = GetFolderNamesFromHierarchy(itemid);
            }

            AddFile(filename, sourceCodeKind, getIsCurrentContext, folderNames);
        }
Пример #3
0
        public ContainedDocument(
            AbstractContainedLanguage containedLanguage,
            SourceCodeKind sourceCodeKind,
            Workspace workspace,
            IVsHierarchy hierarchy,
            uint itemId,
            IComponentModel componentModel,
            IFormattingRule vbHelperFormattingRule)
        {
            Contract.ThrowIfNull(containedLanguage);

            _containedLanguage = containedLanguage;
            _sourceCodeKind    = sourceCodeKind;
            _componentModel    = componentModel;
            _workspace         = workspace;
            _optionService     = _workspace.Services.GetService <IOptionService>();
            _hostType          = GetHostType();

            var rdt      = (IVsRunningDocumentTable)componentModel.GetService <SVsServiceProvider>().GetService(typeof(SVsRunningDocumentTable));
            var filePath = rdt.GetMonikerForHierarchyAndItemId(hierarchy, itemId);

            this.SharedHierarchy = hierarchy == null ? null : LinkedFileUtilities.GetSharedHierarchyForItem(hierarchy, itemId);

            if (Project.Hierarchy != null)
            {
                string moniker;
                Project.Hierarchy.GetCanonicalName(itemId, out moniker);
                _itemMoniker = moniker;
            }

            this.Key     = new DocumentKey(Project, filePath);
            this.Id      = DocumentId.CreateNewId(Project.Id, filePath);
            this.Folders = containedLanguage.Project.GetFolderNames(itemId);
            this.Loader  = TextLoader.From(containedLanguage.SubjectBuffer.AsTextContainer(), VersionStamp.Create(), filePath);
            _differenceSelectorService = componentModel.GetService <ITextDifferencingSelectorService>();
            _snapshotTracker           = new ReiteratedVersionSnapshotTracker(_containedLanguage.SubjectBuffer);
            _vbHelperFormattingRule    = vbHelperFormattingRule;
        }
Пример #4
0
        protected void AddFile(string filename, SourceCodeKind sourceCodeKind)
        {
            Func <IVisualStudioHostDocument, bool> getIsCurrentContext = document => LinkedFileUtilities.IsCurrentContextHierarchy(document, RunningDocumentTable);

            AddFile(filename, sourceCodeKind, getIsCurrentContext, GetFolderNamesFromHierarchy);
        }
Пример #5
0
 public void AddAdditionalFile(string additionalFilePath)
 {
     AddAdditionalFile(additionalFilePath, getIsInCurrentContext: document => LinkedFileUtilities.IsCurrentContextHierarchy(document, RunningDocumentTable));
 }
Пример #6
0
 private bool IsSupported(Project project)
 {
     // TODO: figure out a proper way to support project K scenario where we can't use path as a unique key
     // https://github.com/dotnet/roslyn/issues/1860
     return(!LinkedFileUtilities.IsProjectKProject(project));
 }