public override bool TryGetWorkspace(ITextBuffer textBuffer, out Workspace workspace)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            // We do a best effort approach in this method to get the workspace that belongs to the TextBuffer.
            // Below we try and find the project and then the solution that contains the given text buffer. If
            // we're able to find both the project and solution then we use the solution to look up the corresponding
            // Workspace using MonoDevelops TypeSystemService.

            var hostProject = (DotNetProject)_projectService.GetHostProject(textBuffer);

            if (hostProject == null)
            {
                // Does not have a host project.
                workspace = null;
                return(false);
            }

            var hostSolution = hostProject.ParentSolution;

            if (hostSolution == null)
            {
                // Project does not have a solution
                workspace = null;
                return(false);
            }

            return(TryGetWorkspace(hostSolution, out workspace));
        }
        public override bool TryGetWorkspace(ITextBuffer textBuffer, out Workspace workspace)
        {
            if (textBuffer == null)
            {
                throw new ArgumentNullException(nameof(textBuffer));
            }

            // We do a best effort approach in this method to get the workspace that belongs to the TextBuffer.
            // Below we try and find the project and then the solution that contains the given text buffer. If
            // we're able to find both the project and solution then we use the solution to look up the corresponding
            // Workspace using MonoDevelops TypeSystemService.

            var hostProject = (DotNetProject)_projectService.GetHostProject(textBuffer);

            if (hostProject == null)
            {
                // Does not have a host project.
                workspace = null;
                return(false);
            }

            var hostSolution = hostProject.ParentSolution;

            if (hostSolution == null)
            {
                // Project does not have a solution
                workspace = null;
                return(false);
            }

            workspace = TypeSystemService.GetWorkspace(hostSolution);

            // Workspace cannot be null at this point. If TypeSystemService.GetWorkspace isn't able to find a corresponding
            // workspace it returns an empty workspace. Therefore, in order to see if we have a valid workspace we need to
            // cross-check it against the list of active non-empty workspaces.

            if (!TypeSystemService.AllWorkspaces.Contains(workspace))
            {
                // We were returned the empty workspace which is equivalent to us not finding a valid workspace for our text buffer.
                workspace = null;
                return(false);
            }

            return(true);
        }