-
Notifications
You must be signed in to change notification settings - Fork 4k
/
HostWorkspaceServices.cs
111 lines (96 loc) · 4.36 KB
/
HostWorkspaceServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// 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.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Host
{
/// <summary>
/// Per workspace services provided by the host environment.
/// </summary>
public abstract class HostWorkspaceServices
{
/// <summary>
/// The host services this workspace services originated from.
/// </summary>
/// <returns></returns>
public abstract HostServices HostServices { get; }
/// <summary>
/// The workspace corresponding to this workspace services instantiation
/// </summary>
public abstract Workspace Workspace { get; }
/// <summary>
/// Gets a workspace specific service provided by the host identified by the service type.
/// If the host does not provide the service, this method returns null.
/// </summary>
[return: MaybeNull]
public abstract TWorkspaceService GetService<TWorkspaceService>() where TWorkspaceService : IWorkspaceService;
/// <summary>
/// Gets a workspace specific service provided by the host identified by the service type.
/// If the host does not provide the service, this method throws <see cref="InvalidOperationException"/>.
/// </summary>
/// <exception cref="InvalidOperationException">The host does not provide the service.</exception>
[return: NotNull]
public TWorkspaceService GetRequiredService<TWorkspaceService>() where TWorkspaceService : IWorkspaceService
{
var service = GetService<TWorkspaceService>();
if (service == null)
{
throw new InvalidOperationException(string.Format(WorkspacesResources.Service_of_type_0_is_required_to_accomplish_the_task_but_is_not_available_from_the_workspace, typeof(TWorkspaceService).FullName));
}
return service;
}
/// <summary>
/// A service for storing information across that can be retrieved in a separate process.
/// </summary>
public virtual IPersistentStorageService PersistentStorage
{
get { return this.GetRequiredService<IPersistentStorageService>(); }
}
/// <summary>
/// A service for storing information in a temporary location that only lasts for the duration of the process.
/// </summary>
public virtual ITemporaryStorageService TemporaryStorage
{
get { return this.GetRequiredService<ITemporaryStorageService>(); }
}
/// <summary>
/// A factory that constructs <see cref="SourceText"/>.
/// </summary>
internal virtual ITextFactoryService TextFactory
{
get { return this.GetRequiredService<ITextFactoryService>(); }
}
/// <summary>
/// A list of language names for supported language services.
/// </summary>
public virtual IEnumerable<string> SupportedLanguages
{
get { return SpecializedCollections.EmptyEnumerable<string>(); }
}
/// <summary>
/// Returns true if the language is supported.
/// </summary>
public virtual bool IsSupported(string languageName)
{
return false;
}
/// <summary>
/// Gets the <see cref="HostLanguageServices"/> for the language name.
/// </summary>
/// <exception cref="NotSupportedException">Thrown if the language isn't supported.</exception>
public virtual HostLanguageServices GetLanguageServices(string languageName)
{
throw new NotSupportedException(string.Format(WorkspacesResources.The_language_0_is_not_supported, languageName));
}
public delegate bool MetadataFilter(IReadOnlyDictionary<string, object> metadata);
/// <summary>
/// Finds all language services of the corresponding type across all supported languages that match the filter criteria.
/// </summary>
public abstract IEnumerable<TLanguageService> FindLanguageServices<TLanguageService>(MetadataFilter filter);
}
}