public void RemoveProject(AbstractProject project)
        {
            _typeScriptProjects.Remove(project.Id);

            project.VisualStudioProject.RemoveFromWorkspace();
            project.VisualStudioProject = null;
        }
Ejemplo n.º 2
0
 internal bool ContainsProject(AbstractProject project)
 {
     lock (_gate)
     {
         return(_projectMap.ContainsKey(project.Id));
     }
 }
            /// <summary>
            /// Creates a <see cref="StandardTextDocument"/>.
            /// <para>Note: getFolderNames maps from a VSITEMID to the folders this document should be contained in.</para>
            /// </summary>
            public StandardTextDocument(
                DocumentProvider documentProvider,
                AbstractProject project,
                DocumentKey documentKey,
                Func <uint, IReadOnlyList <string> > getFolderNames,
                SourceCodeKind sourceCodeKind,
                IVsFileChangeEx fileChangeService,
                ITextBuffer openTextBuffer,
                DocumentId id,
                EventHandler updatedOnDiskHandler,
                EventHandler <bool> openedHandler,
                EventHandler <bool> closingHandler)
            {
                Contract.ThrowIfNull(documentProvider);

                this.Project = project;
                this.Id      = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
                _itemMoniker = documentKey.Moniker;

                var itemid = this.GetItemId();

                this.Folders = itemid == (uint)VSConstants.VSITEMID.Nil
                    ? SpecializedCollections.EmptyReadOnlyList <string>()
                    : getFolderNames(itemid);

                _documentProvider = documentProvider;

                this.Key            = documentKey;
                this.SourceCodeKind = sourceCodeKind;
                _fileChangeTracker  = new FileChangeTracker(fileChangeService, this.FilePath);
                _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk;

                _openTextBuffer  = openTextBuffer;
                _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer);

                // The project system does not tell us the CodePage specified in the proj file, so
                // we use null to auto-detect.
                _doNotAccessDirectlyLoader = new FileTextLoader(documentKey.Moniker, defaultEncoding: null);

                // If we aren't already open in the editor, then we should create a file change notification
                if (openTextBuffer == null)
                {
                    _fileChangeTracker.StartFileChangeListeningAsync();
                }

                if (updatedOnDiskHandler != null)
                {
                    UpdatedOnDisk += updatedOnDiskHandler;
                }

                if (openedHandler != null)
                {
                    Opened += openedHandler;
                }

                if (closingHandler != null)
                {
                    Closing += closingHandler;
                }
            }
Ejemplo n.º 4
0
        private AbstractProject TryFindExistingProjectForProjectReference(string projectReferencePath, ImmutableArray <MetadataReference> metadataReferences)
        {
            // NOTE: ImmutableProjects might contain projects for other languages like
            // Xaml, or Typescript where the project file ends up being identical.
            AbstractProject candidate = null;

            foreach (var existingProject in ImmutableProjects)
            {
                if (existingProject.Language != LanguageNames.CSharp && existingProject.Language != LanguageNames.VisualBasic)
                {
                    continue;
                }

                if (!StringComparer.OrdinalIgnoreCase.Equals(existingProject.ProjectFilePath, projectReferencePath))
                {
                    continue;
                }

                // There might be multiple projects that have the same project file path and language in the case of
                // cross-targeted .NET Core project.  To support that, we'll try to find the one with the output path
                // that matches one of the metadata references we're trying to add.  If we don't find any, then we'll
                // settle one with a matching project file path.
                candidate = candidate ?? existingProject;
                if (metadataReferences.Contains(mr => StringComparer.OrdinalIgnoreCase.Equals(GetReferencePath(mr), existingProject.BinOutputPath)))
                {
                    return(existingProject);
                }
            }

            return(candidate);
        }
Ejemplo n.º 5
0
 public ShimDocument(AbstractProject hostProject, DocumentId id, string filePath, SourceCodeKind sourceCodeKind = SourceCodeKind.Regular)
 {
     Project        = hostProject;
     Id             = id ?? DocumentId.CreateNewId(hostProject.Id, filePath);
     FilePath       = filePath;
     SourceCodeKind = sourceCodeKind;
 }
Ejemplo n.º 6
0
        private ProjectItem AddDocumentToProjectItems(
            AbstractProject hostProject,
            ProjectItems projectItems,
            DocumentId documentId,
            string folderPath,
            string documentName,
            SourceCodeKind sourceCodeKind,
            SourceText initialText,
            string filePath,
            bool isAdditionalDocument)
        {
            if (filePath == null)
            {
                var baseName   = Path.GetFileNameWithoutExtension(documentName);
                var extension  = isAdditionalDocument ? Path.GetExtension(documentName) : GetPreferredExtension(hostProject, sourceCodeKind);
                var uniqueName = projectItems.GetUniqueName(baseName, extension);
                filePath = Path.Combine(folderPath, uniqueName);
            }

            if (initialText != null)
            {
                using (var writer = new StreamWriter(filePath, append: false, encoding: initialText.Encoding ?? Encoding.UTF8))
                {
                    initialText.Write(writer);
                }
            }

            using (var documentIdHint = DeferredState.ProjectTracker.DocumentProvider.ProvideDocumentIdHint(filePath, documentId))
            {
                return(projectItems.AddFromFile(filePath));
            }
        }
        public void AddProject(AbstractProject project)
        {
            project.VisualStudioProject = _projectFactory.CreateAndAddToWorkspace(project.ProjectSystemName, project.Language);
            project.UpdateVisualStudioProjectProperties();

            _typeScriptProjects[project.Id] = project;
        }
Ejemplo n.º 8
0
 internal void GetProjectData(ProjectId projectId, out AbstractProject hostProject, out IVsHierarchy hierarchy, out EnvDTE.Project project)
 {
     if (!TryGetProjectData(projectId, out hostProject, out hierarchy, out project))
     {
         throw new ArgumentException(string.Format(ServicesVSResources.Could_not_find_project_0, projectId));
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Attempts to get single project by given output binary filePath.
        /// </summary>
        /// <remarks>This method may be called on a background thread.</remarks>
        internal bool TryGetProjectByBinPath(string filePath, out AbstractProject project)
        {
            lock (_gate)
            {
                project = null;
                if (!_projectsByBinPath.TryGetValue(filePath, out var projects))
                {
                    // Workaround https://github.com/dotnet/roslyn/issues/20412 by checking to see if */ref/A.dll can be
                    // adjusted to */A.dll - only handles the default location for reference assemblies during a build.
                    if (!HACK_StripRefDirectoryFromPath(filePath, out string binFilePath) ||
                        !_projectsByBinPath.TryGetValue(binFilePath, out projects))
                    {
                        return(false);
                    }
                }

                // If for some reason we have more than one referencing project, it's ambiguous so bail
                if (projects.Length == 1)
                {
                    project = projects[0];
                    return(true);
                }

                return(false);
            }
        }
Ejemplo n.º 10
0
        public DocumentKey(AbstractProject hostProject, string moniker)
        {
            Contract.ThrowIfNull(hostProject);
            Contract.ThrowIfNull(moniker);

            _hostProject = hostProject;
            _moniker     = moniker;
        }
Ejemplo n.º 11
0
        internal void NotifyNonDocumentOpenedForProject(AbstractProject project)
        {
            AssertIsForeground();

            var abstractProject = (AbstractProject)project;

            StartPushingToWorkspaceAndNotifyOfOpenDocuments(SpecializedCollections.SingletonEnumerable(abstractProject));
        }
Ejemplo n.º 12
0
        private bool TryGetProjectData(ProjectId projectId, out AbstractProject hostProject, out IVsHierarchy hierarchy, out EnvDTE.Project project)
        {
            hierarchy = null;
            project   = null;

            return(this.TryGetHostProject(projectId, out hostProject) &&
                   this.TryGetHierarchy(projectId, out hierarchy) &&
                   hierarchy.TryGetProject(out project));
        }
Ejemplo n.º 13
0
 internal void RemoveProject(AbstractProject project)
 {
     // If we've already told this host about it, then we need to remove it. Otherwise, this host has no
     // further work to do.
     if (_pushedProjects.Remove(project))
     {
         this.Host.OnProjectRemoved(project.Id);
     }
 }
            /// <summary>
            /// Creates a <see cref="StandardTextDocument"/>.
            /// </summary>
            public StandardTextDocument(
                DocumentProvider documentProvider,
                AbstractProject project,
                DocumentKey documentKey,
                ImmutableArray <string> folderNames,
                SourceCodeKind sourceCodeKind,
                IVsFileChangeEx fileChangeService,
                ITextBuffer openTextBuffer,
                DocumentId id,
                EventHandler updatedOnDiskHandler,
                EventHandler <bool> openedHandler,
                EventHandler <bool> closingHandler)
                : base(documentProvider.ThreadingContext)
            {
                Contract.ThrowIfNull(documentProvider);

                this.Project = project;
                this.Id      = id ?? DocumentId.CreateNewId(project.Id, documentKey.Moniker);
                _itemMoniker = documentKey.Moniker;

                this.Folders = folderNames;

                _documentProvider = documentProvider;

                this.Key            = documentKey;
                this.SourceCodeKind = sourceCodeKind;
                _fileChangeTracker  = new FileChangeTracker(fileChangeService, this.FilePath);
                _fileChangeTracker.UpdatedOnDisk += OnUpdatedOnDisk;

                _openTextBuffer  = openTextBuffer;
                _snapshotTracker = new ReiteratedVersionSnapshotTracker(openTextBuffer);

                // The project system does not tell us the CodePage specified in the proj file, so
                // we use null to auto-detect.
                _doNotAccessDirectlyLoader = new FileChangeTrackingTextLoader(_fileChangeTracker, new FileTextLoader(documentKey.Moniker, defaultEncoding: null));

                // If we aren't already open in the editor, then we should create a file change notification
                if (openTextBuffer == null)
                {
                    _fileChangeTracker.StartFileChangeListeningAsync();
                }

                if (updatedOnDiskHandler != null)
                {
                    UpdatedOnDisk += updatedOnDiskHandler;
                }

                if (openedHandler != null)
                {
                    Opened += openedHandler;
                }

                if (closingHandler != null)
                {
                    Closing += closingHandler;
                }
            }
Ejemplo n.º 15
0
        public AbstractContainedLanguage(
            AbstractProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            this.Project = project;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Remove a project from the workspace.
        /// </summary>
        internal void RemoveProject(AbstractProject project)
        {
            Contract.ThrowIfFalse(_projectMap.Remove(project.Id));

            UpdateProjectBinPath(project, project.TryGetBinOutputPath(), null);

            if (project.PushingChangesToWorkspaceHosts)
            {
                NotifyWorkspaceHosts(host => host.OnProjectRemoved(project.Id));
            }
        }
Ejemplo n.º 17
0
        public void AddProject(AbstractProject project)
        {
            var provider = (IProjectCodeModelProvider)project;
            var fcms = provider.ProjectCodeModel.GetCachedFileCodeModelInstances();

            foreach (var fcm in fcms)
            {
                var globalNodeKeys = fcm.Object.GetCurrentNodeKeys();

                _nodeKeysMap.Add(fcm, globalNodeKeys);
            }
        }
Ejemplo n.º 18
0
 public IVisualStudioHostDocument TryGetDocumentForFile(
     AbstractProject hostProject,
     string filePath,
     SourceCodeKind sourceCodeKind,
     Func <ITextBuffer, bool> canUseTextBuffer,
     Func <uint, IReadOnlyList <string> > getFolderNames,
     EventHandler updatedOnDiskHandler  = null,
     EventHandler <bool> openedHandler  = null,
     EventHandler <bool> closingHandler = null)
 {
     return(new ShimDocument(hostProject, DocumentId.CreateNewId(hostProject.Id), filePath, sourceCodeKind));
 }
Ejemplo n.º 19
0
        internal void UpdateProjectBinPath(AbstractProject project, string oldBinPathOpt, string newBinPathOpt)
        {
            if (oldBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(oldBinPathOpt, () => _projectsByBinPath.MultiRemove(oldBinPathOpt, project));
            }

            if (newBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(newBinPathOpt, () => _projectsByBinPath.MultiAdd(newBinPathOpt, project));
            }
        }
Ejemplo n.º 20
0
        public void AddProject(AbstractProject project)
        {
            var provider = (IProjectCodeModelProvider)project;
            IEnumerable<ComHandle<EnvDTE80.FileCodeModel2, FileCodeModel>> fcms = provider.ProjectCodeModel.GetFileCodeModelInstances();

            foreach (var fcm in fcms)
            {
                var globalNodeKeys = fcm.Object.GetCurrentNodeKeys();

                _nodeKeysMap.Add(fcm, globalNodeKeys);
            }
        }
Ejemplo n.º 21
0
        internal void AddProjectByBinPath(string filePath, AbstractProject project)
        {
            lock (_gate)
            {
                if (!_projectsByBinPath.TryGetValue(filePath, out var projects))
                {
                    projects = ImmutableArray <AbstractProject> .Empty;
                }

                _projectsByBinPath[filePath] = projects.Add(project);
            }
        }
Ejemplo n.º 22
0
        public VsReadOnlyDocumentTracker(IEditAndContinueWorkspaceService encService, IVsEditorAdaptersFactoryService adapters, AbstractProject vsProject)
            : base(assertIsForeground: true)
        {
            Debug.Assert(encService.DebuggingSession != null);

            _encService = encService;
            _adapters = adapters;
            _workspace = encService.DebuggingSession.InitialSolution.Workspace;
            _vsProject = vsProject;

            _workspace.DocumentOpened += OnDocumentOpened;
            UpdateWorkspaceDocuments();
        }
Ejemplo n.º 23
0
        public void RemoveProject(AbstractProject project)
        {
            _projects.Remove(project.Id);

            if (project.ExplicitId != null)
            {
                Workspace.OnProjectRemoved(project.ExplicitId);
            }
            else
            {
                project.VisualStudioProject.RemoveFromWorkspace();
                project.VisualStudioProject = null;
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Remove a project from the workspace.
        /// </summary>
        internal void RemoveProject(AbstractProject project)
        {
            Contract.ThrowIfFalse(_projectMap.Remove(project.Id));

            UpdateProjectBinPath(project, project.TryGetBinOutputPath(), null);

            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                foreach (var hostState in _workspaceHosts)
                {
                    hostState.RemoveProject(project);
                }
            }
        }
Ejemplo n.º 25
0
        /// <remarks>
        /// <para>The optional project is used to obtain an <see cref="IVsProject"/> 1nstance. When this instance is
        /// provided, Visual Studio will use <see cref="IVsProject.IsDocumentInProject"/> to attempt to locate the
        /// specified file within a project. If no project is specified, Visual Studio falls back to using
        /// <see cref="IVsUIShellOpenDocument4.IsDocumentInAProject2"/>, which performs a much slower query of all
        /// projects in the solution.</para>
        /// </remarks>
        public InvisibleEditor(IServiceProvider serviceProvider, string filePath, AbstractProject projectOpt, bool needsSave, bool needsUndoDisabled)
        {
            _serviceProvider = serviceProvider;
            _filePath        = filePath;
            _needsSave       = needsSave;

            var invisibleEditorManager = (IIntPtrReturningVsInvisibleEditorManager)serviceProvider.GetService(typeof(SVsInvisibleEditorManager));
            var vsProject          = TryGetProjectOfHierarchy(projectOpt?.Hierarchy);
            var invisibleEditorPtr = IntPtr.Zero;

            Marshal.ThrowExceptionForHR(invisibleEditorManager.RegisterInvisibleEditor(filePath, vsProject, 0, null, out invisibleEditorPtr));

            try
            {
                _invisibleEditor = (IVsInvisibleEditor)Marshal.GetUniqueObjectForIUnknown(invisibleEditorPtr);

                var docDataPtr = IntPtr.Zero;
                Marshal.ThrowExceptionForHR(_invisibleEditor.GetDocData(fEnsureWritable: needsSave ? 1 : 0, riid: typeof(IVsTextLines).GUID, ppDocData: out docDataPtr));

                try
                {
                    var docData = Marshal.GetObjectForIUnknown(docDataPtr);
                    _vsTextLines = docData as IVsTextLines;
                    var vsTextBuffer = (IVsTextBuffer)docData;
                    var editorAdapterFactoryService = serviceProvider.GetMefService <IVsEditorAdaptersFactoryService>();
                    _buffer = editorAdapterFactoryService.GetDocumentBuffer(vsTextBuffer);
                    if (needsUndoDisabled)
                    {
                        Marshal.ThrowExceptionForHR(vsTextBuffer.GetUndoManager(out _manager));
                        Marshal.ThrowExceptionForHR((_manager as IVsUndoState).IsEnabled(out var isEnabled));
                        _needsUndoRestored = isEnabled != 0;
                        if (_needsUndoRestored)
                        {
                            _manager.DiscardFrom(null); // Discard the undo history for this document
                            _manager.Enable(0);         // Disable Undo for this document
                        }
                    }
                }
                finally
                {
                    Marshal.Release(docDataPtr);
                }
            }
            finally
            {
                // We need to clean up the extra reference we have, now that we have an RCW holding onto the object.
                Marshal.Release(invisibleEditorPtr);
            }
        }
Ejemplo n.º 26
0
        public void AddProject(AbstractProject project)
        {
            var creationInfo = new VisualStudioProjectCreationInfo
            {
                AssemblyName = project.AssemblyName,
                FilePath     = project.ProjectFilePath,
                Hierarchy    = project.Hierarchy,
                ProjectGuid  = project.Guid,
            };

            project.VisualStudioProject = _projectFactory.CreateAndAddToWorkspace(project.ProjectSystemName, project.Language, creationInfo);
            project.UpdateVisualStudioProjectProperties();

            _typeScriptProjects[project.Id] = project;
        }
Ejemplo n.º 27
0
        internal bool TryGetProjectByBinPath(string filePath, out AbstractProject project)
        {
            var projectsWithBinPath = _workspace.CurrentSolution.Projects.Where(p => string.Equals(p.OutputFilePath, filePath, StringComparison.OrdinalIgnoreCase)).ToList();

            if (projectsWithBinPath.Count == 1)
            {
                project = new StubProject(this, projectsWithBinPath[0]);
                return(true);
            }
            else
            {
                project = null;
                return(false);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Updates the project tracker and referencing projects for binary output path change for the given project.
        /// </summary>
        internal void UpdateProjectBinPath(AbstractProject project, string oldBinPathOpt, string newBinPathOpt)
        {
            // UpdateProjectBinPath is defensively executed on the foreground thread as it calls back into referencing projects to perform metadata to P2P reference conversions.
            AssertIsForeground();

            if (oldBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(oldBinPathOpt, () => RemoveProjectByBinPath(oldBinPathOpt, project));
            }

            if (newBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(newBinPathOpt, () => AddProjectByBinPath(newBinPathOpt, project));
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Add a project to the workspace.
        /// </summary>
        internal void AddProject(AbstractProject project)
        {
            _projectMap.Add(project.Id, project);

            UpdateProjectBinPath(project, null, project.TryGetBinOutputPath());

            if (_solutionLoadComplete)
            {
                StartPushingToWorkspaceAndNotifyOfOpenDocuments(SpecializedCollections.SingletonEnumerable(project));
            }
            else
            {
                _projectsLoadedThisBatch.Add(project);
            }
        }
Ejemplo n.º 30
0
 internal void RemoveProjectByBinPath(string filePath, AbstractProject project)
 {
     lock (_gate)
     {
         if (_projectsByBinPath.TryGetValue(filePath, out var projects) && projects.Contains(project))
         {
             if (projects.Length == 1)
             {
                 _projectsByBinPath.Remove(filePath);
             }
             else
             {
                 _projectsByBinPath[filePath] = projects.Remove(project);
             }
         }
     }
 }
Ejemplo n.º 31
0
        private ProjectItem AddDocumentToProject(
            AbstractProject hostProject,
            EnvDTE.Project project,
            DocumentId documentId,
            string documentName,
            SourceCodeKind sourceCodeKind,
            SourceText initialText    = null,
            string filePath           = null,
            bool isAdditionalDocument = false)
        {
            if (!project.TryGetFullPath(out var folderPath))
            {
                // TODO(cyrusn): Throw an appropriate exception here.
                throw new Exception(ServicesVSResources.Could_not_find_location_of_folder_on_disk);
            }

            return(AddDocumentToProjectItems(hostProject, project.ProjectItems, documentId, folderPath, documentName, sourceCodeKind, initialText, filePath, isAdditionalDocument));
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Attempts to get single project by given output binary filePath.
        /// </summary>
        /// <remarks>This method may be called on a background thread.</remarks>
        internal bool TryGetProjectByBinPath(string filePath, out AbstractProject project)
        {
            lock (_gate)
            {
                project = null;
                if (_projectsByBinPath.TryGetValue(filePath, out var projects))
                {
                    // If for some reason we have more than one referencing project, it's ambiguous so bail
                    if (projects.Length == 1)
                    {
                        project = projects[0];
                        return(true);
                    }
                }

                return(false);
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Remove a project from the workspace.
        /// </summary>
        internal void RemoveProject(AbstractProject project)
        {
            AssertIsForeground();

            lock (_gate)
            {
                Contract.ThrowIfFalse(_projectMap.Remove(project.Id));
            }

            UpdateProjectBinPath(project, project.BinOutputPath, null);

            if (_pushedProjects.Contains(project))
            {
                NotifyWorkspace(workspace => workspace.OnProjectRemoved(project.Id));

                _pushedProjects.Remove(project);
            }
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Remove a project from the workspace.
        /// </summary>
        internal void RemoveProject(AbstractProject project)
        {
            AssertIsForeground();

            lock (_gate)
            {
                Contract.ThrowIfFalse(_projectMap.Remove(project.Id));
            }

            UpdateProjectBinPath(project, project.BinOutputPath, null);

            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                foreach (var hostState in _workspaceHosts)
                {
                    hostState.RemoveProject(project);
                }
            }
        }
            private void AddToPushListIfNeeded(AbstractProject project, List<AbstractProject> inOrderToPush, HashSet<AbstractProject> visited)
            {
                if (_pushedProjects.Contains(project))
                {
                    return;
                }

                if (!visited.Add(project))
                {
                    return;
                }

                foreach (var projectReference in project.GetCurrentProjectReferences())
                {
                    AddToPushListIfNeeded(_tracker._projectMap[projectReference.ProjectId], inOrderToPush, visited);
                }

                inOrderToPush.Add(project);
            }
            private void AddToPushListIfNeeded(AbstractProject project, List<AbstractProject> inOrderToPush, HashSet<AbstractProject> visited)
            {
                AssertIsForeground();                
                Contract.ThrowIfFalse(_tracker.ContainsProject(project));

                // Bail out if any of the following is true:
                //  1. We have already started pushing changes for this project OR
                //  2. We have already visited this project in a prior recursive call                
                if (_pushedProjects.Contains(project) || !visited.Add(project))
                {
                    return;
                }

                foreach (var projectReference in project.GetCurrentProjectReferences())
                {
                    AddToPushListIfNeeded(_tracker.GetProject(projectReference.ProjectId), inOrderToPush, visited);
                }

                inOrderToPush.Add(project);
            }
Ejemplo n.º 37
0
        /// <summary>
        /// Remove a project from the workspace.
        /// </summary>
        internal void RemoveProject(AbstractProject project)
        {
            Contract.ThrowIfFalse(_projectMap.Remove(project.Id));

            UpdateProjectBinPath(project, project.TryGetBinOutputPath(), null);

            if (project.PushingChangesToWorkspaceHosts)
            {
                NotifyWorkspaceHosts(host => host.OnProjectRemoved(project.Id));
            }
        }
 /// <summary>
 /// Updates the project tracker and referencing projects for binary output path change for the given project.
 /// If invoked on the foreground thread, the update is executed right away.
 /// Otherwise, update is scheduled on foreground task scheduler.
 /// </summary>
 /// <remarks>This method may be called on a background thread.</remarks>
 internal void UpdateProjectBinPath(AbstractProject project, string oldBinPathOpt, string newBinPathOpt)
 {
     ExecuteOrScheduleForegroundAffinitizedAction(() => UpdateProjectBinPath_Foreground(project, oldBinPathOpt, newBinPathOpt));
 }
Ejemplo n.º 39
0
 internal bool ContainsProject(AbstractProject project)
 {
     lock (_gate)
     {
         return _projectMap.ContainsKey(project.Id);
     }
 }
Ejemplo n.º 40
0
        internal void UpdateProjectBinPath(AbstractProject project, string oldBinPathOpt, string newBinPathOpt)
        {
            if (oldBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(oldBinPathOpt, () => _projectsByBinPath.MultiRemove(oldBinPathOpt, project));
            }

            if (newBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(newBinPathOpt, () => _projectsByBinPath.MultiAdd(newBinPathOpt, project));
            }
        }
        internal void AddProjectByBinPath(string filePath, AbstractProject project)
        {
            lock (_gate)
            {
                if (!_projectsByBinPath.TryGetValue(filePath, out var projects))
                {
                    projects = ImmutableArray<AbstractProject>.Empty;
                }

                _projectsByBinPath[filePath] = projects.Add(project);
            }
        }
 internal void RemoveProjectByBinPath(string filePath, AbstractProject project)
 {
     lock (_gate)
     {
         if (_projectsByBinPath.TryGetValue(filePath, out var projects) && projects.Contains(project))
         {
             if (projects.Length == 1)
             {
                 _projectsByBinPath.Remove(filePath);
             }
             else
             {
                 _projectsByBinPath[filePath] = projects.Remove(project);
             }
         }
     }
 }
        internal void UpdateProjectBinPath_Foreground(AbstractProject project, string oldBinPathOpt, string newBinPathOpt)
        {
            // UpdateProjectBinPath is defensively executed on the foreground thread as it calls back into referencing projects to perform metadata to P2P reference conversions.
            AssertIsForeground();

            if (oldBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(oldBinPathOpt, () => RemoveProjectByBinPath(oldBinPathOpt, project));
            }

            if (newBinPathOpt != null)
            {
                UpdateReferencesForBinPathChange(newBinPathOpt, () => AddProjectByBinPath(newBinPathOpt, project));
            }
        }
        /// <summary>
        /// Attempts to get single project by given output binary filePath.
        /// </summary>
        /// <remarks>This method may be called on a background thread.</remarks>
        internal bool TryGetProjectByBinPath(string filePath, out AbstractProject project)
        {
            lock (_gate)
            {
                project = null;
                if (_projectsByBinPath.TryGetValue(filePath, out var projects))
                {
                    // If for some reason we have more than one referencing project, it's ambiguous so bail
                    if (projects.Length == 1)
                    {
                        project = projects[0];
                        return true;
                    }
                }

                return false;
            }
        }
 internal void RemoveProject(AbstractProject project)
 {
     // If we've already told this host about it, then we need to remove it. Otherwise, this host has no
     // further work to do.
     if (_pushedProjects.Remove(project))
     {
         this.Host.OnProjectRemoved(project.Id);
     }
 }
Ejemplo n.º 46
0
        /// <summary>
        /// Add a project to the workspace.
        /// </summary>
        internal void AddProject(AbstractProject project)
        {
            _projectMap.Add(project.Id, project);

            UpdateProjectBinPath(project, null, project.TryGetBinOutputPath());

            if (_solutionLoadComplete)
            {
                StartPushingToWorkspaceAndNotifyOfOpenDocuments(SpecializedCollections.SingletonEnumerable(project));
            }
            else
            {
                _projectsLoadedThisBatch.Add(project);
            }
        }
Ejemplo n.º 47
0
 internal CodeModelProjectCache(AbstractProject project, IServiceProvider serviceProvider, HostLanguageServices languageServices, VisualStudioWorkspace workspace)
 {
     _project = project;
     _state = new CodeModelState(serviceProvider, languageServices, workspace);
 }
        internal VsENCRebuildableProjectImpl(AbstractProject project)
        {
            _vsProject = project;

            _encService = _vsProject.VisualStudioWorkspace.Services.GetService<IEditAndContinueWorkspaceService>();
            _trackingService = _vsProject.VisualStudioWorkspace.Services.GetService<IActiveStatementTrackingService>();
            _notifications = _vsProject.VisualStudioWorkspace.Services.GetService<INotificationService>();

            _debugEncNotify = (IDebugEncNotify)project.ServiceProvider.GetService(typeof(ShellInterop.SVsShellDebugger));

            var componentModel = (IComponentModel)project.ServiceProvider.GetService(typeof(SComponentModel));
            _diagnosticProvider = componentModel.GetService<EditAndContinueDiagnosticUpdateSource>();
            _editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();

            Debug.Assert(_encService != null);
            Debug.Assert(_trackingService != null);
            Debug.Assert(_diagnosticProvider != null);
            Debug.Assert(_editorAdaptersFactoryService != null);
        }
Ejemplo n.º 49
0
        protected void UpdateProjectReferenceAliases(AbstractProject referencedProject, ImmutableArray<string> aliases)
        {
            AssertIsForeground();

            var projectReference = GetCurrentProjectReferences().Single(r => r.ProjectId == referencedProject.Id);

            var newProjectReference = new ProjectReference(referencedProject.Id, aliases, projectReference.EmbedInteropTypes);

            // Is this a project with converted references? If so, make sure we track it
            string referenceBinPath = referencedProject.BinOutputPath;
            if (referenceBinPath != null && HasMetadataFileNameToConvertedProjectReference(referenceBinPath))
            {
                UpdateMetadataFileNameToConvertedProjectReference(referenceBinPath, newProjectReference);
            }

            // Remove the existing reference first
            RemoveProjectReference(projectReference);

            AddProjectReference(newProjectReference);
        }
Ejemplo n.º 50
0
        internal void TryProjectConversionForIntroducedOutputPath(string binPath, AbstractProject projectToReference)
        {
            AssertIsForeground();

            if (this.CanConvertToProjectReferences)
            {
                // We should not already have references for this, since we're only introducing the path for the first time
                Contract.ThrowIfTrue(HasMetadataFileNameToConvertedProjectReference(binPath));

                var metadataReference = TryGetCurrentMetadataReference(binPath);
                if (metadataReference != null)
                {
                    var projectReference = new ProjectReference(
                        projectToReference.Id,
                        metadataReference.Properties.Aliases,
                        metadataReference.Properties.EmbedInteropTypes);

                    if (CanAddProjectReference(projectReference))
                    {
                        RemoveMetadataReferenceCore(metadataReference, disposeReference: true);
                        AddProjectReference(projectReference);

                        AddMetadataFileNameToConvertedProjectReference(binPath, projectReference);
                    }
                }
            }
        }
Ejemplo n.º 51
0
        private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument)
        {
            vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile(
                project, ImmutableArray<string>.Empty, filePath, SourceCodeKind.Regular, tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType));

            return vsDocument != null;
        }
Ejemplo n.º 52
0
        protected void UpdateProjectReferenceAliases(AbstractProject referencedProject, ImmutableArray<string> aliases)
        {
            var projectReference = GetCurrentProjectReferences().Single(r => r.ProjectId == referencedProject.Id);

            var newProjectReference = new ProjectReference(referencedProject.Id, aliases, projectReference.EmbedInteropTypes);

            // Is this a project with converted references? If so, make sure we track it
            string referenceBinPath = referencedProject.TryGetBinOutputPath();
            if (referenceBinPath != null && _metadataFileNameToConvertedProjectReference.ContainsKey(referenceBinPath))
            {
                _metadataFileNameToConvertedProjectReference[referenceBinPath] = newProjectReference;
            }

            // Remove the existing reference first
            RemoveProjectReference(projectReference);

            AddProjectReference(newProjectReference);
        }
        /// <summary>
        /// Remove a project from the workspace.
        /// </summary>
        private void RemoveProject_Foreground(AbstractProject project)
        {
            AssertIsForeground();

            lock (_gate)
            {
                Contract.ThrowIfFalse(_projectMap.Remove(project.Id));
            }

            UpdateProjectBinPath_Foreground(project, project.BinOutputPath, null);

            using (Dispatcher.CurrentDispatcher.DisableProcessing())
            {
                foreach (var hostState in _workspaceHosts)
                {
                    hostState.RemoveProject(project);
                }
            }
        }
        private bool TryCreateXamlDocument(AbstractProject project, string filePath, out IVisualStudioHostDocument vsDocument)
        {
            vsDocument = _vsWorkspace.ProjectTracker.DocumentProvider.TryGetDocumentForFile(
                project, filePath, SourceCodeKind.Regular,
                tb => tb.ContentType.IsOfType(ContentTypeNames.XamlContentType),
                _ => SpecializedCollections.EmptyReadOnlyList<string>());

            return vsDocument != null;
        }
Ejemplo n.º 55
0
 public AbstractProjectCodeModel(AbstractProject project, VisualStudioWorkspaceImpl visualStudioWorkspace, IServiceProvider serviceProvider)
 {
     VSProject = project;
     VisualStudioWorkspace = visualStudioWorkspace;
     ServiceProvider = serviceProvider;
 }
Ejemplo n.º 56
0
        private static void StartPushingToWorkspaceAndNotifyOfOpenDocuments(AbstractProject project)
        {
            project.AssertIsForeground();

            // If a document is opened in a project but we haven't started pushing yet, we want to stop doing lazy
            // loading for this project and get it up to date so the user gets a fast experience there. If the file
            // was presented as open to us right away, then we'll never do this in OnDocumentOpened, so we should do
            // it here. It's important to do this after everything else happens in this method, so we don't get
            // strange ordering issues. It's still possible that this won't actually push changes if the workspace
            // host isn't ready to receive events yet.
            project.ProjectTracker.StartPushingToWorkspaceAndNotifyOfOpenDocuments(SpecializedCollections.SingletonEnumerable(project));
        }
        private void AddProject_Foreground(AbstractProject project)
        {
            AssertIsForeground();

            lock (_gate)
            {
                _projectMap.Add(project.Id, project);
            }

            // UpdateProjectBinPath is defensively executed on the foreground thread as it calls back into referencing projects to perform metadata to P2P reference conversions.
            UpdateProjectBinPath_Foreground(project, null, project.BinOutputPath);

            if (_solutionLoadComplete)
            {
                StartPushingToWorkspaceAndNotifyOfOpenDocuments_Foreground(SpecializedCollections.SingletonEnumerable(project));
            }
            else
            {
                _projectsLoadedThisBatch.Add(project);
            }
        }
 /// <summary>
 /// Remove a project from the workspace.
 /// </summary>
 internal void RemoveProject(AbstractProject project)
 {
     ExecuteOrScheduleForegroundAffinitizedAction(() => RemoveProject_Foreground(project));
 }
Ejemplo n.º 59
0
 public AbstractProjectCodeModel(AbstractProject project, VisualStudioWorkspace visualStudioWorkspace, IServiceProvider serviceProvider)
 {
     _vsProject = project;
     _visualStudioWorkspace = visualStudioWorkspace;
     _serviceProvider = serviceProvider;
 }