VisualStudioLspSolutionProvider.cs 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

using System;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.LanguageClient
{
    [Export(typeof(ILspSolutionProvider)), Shared]
20
    internal class VisualStudioLspSolutionProvider : ILspSolutionProvider
21
    {
D
David Barbet 已提交
22 23
        private readonly VisualStudioWorkspace _visualStudioWorkspace;
        private readonly MiscellaneousFilesWorkspace _miscellaneousFilesWorkspace;
24 25 26 27 28 29 30 31 32

        [ImportingConstructor]
        [Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
        public VisualStudioLspSolutionProvider(VisualStudioWorkspace visualStudioWorkspace, MiscellaneousFilesWorkspace miscellaneousFilesWorkspace)
        {
            _visualStudioWorkspace = visualStudioWorkspace;
            _miscellaneousFilesWorkspace = miscellaneousFilesWorkspace;
        }

D
David Barbet 已提交
33
        public Solution GetCurrentSolutionForMainWorkspace()
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
        {
            return _visualStudioWorkspace.CurrentSolution;
        }

        public ImmutableArray<Document> GetDocuments(Uri documentUri)
        {
            // First check the VS workspace for matching documents.
            var documents = _visualStudioWorkspace.CurrentSolution.GetDocuments(documentUri);
            if (documents.IsEmpty)
            {
                // If there's none in the VS workspace, then check the misc files workspace.
                documents = _miscellaneousFilesWorkspace.CurrentSolution.GetDocuments(documentUri);
            }

            return documents;
        }
50 51 52 53 54 55 56 57 58 59 60 61 62

        public ImmutableArray<TextDocument> GetTextDocuments(Uri documentUri)
        {
            // First check the VS workspace for matching documents.
            var documents = _visualStudioWorkspace.CurrentSolution.GetTextDocuments(documentUri);
            if (documents.IsEmpty)
            {
                // If there's none in the VS workspace, then check the misc files workspace.
                documents = _miscellaneousFilesWorkspace.CurrentSolution.GetTextDocuments(documentUri);
            }

            return documents;
        }
63 64
    }
}