This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
/
Copy pathTestLanguageServices.cs
48 lines (38 loc) · 1.64 KB
/
TestLanguageServices.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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Razor;
namespace Microsoft.CodeAnalysis.Host
{
internal class TestLanguageServices : HostLanguageServices
{
private readonly HostWorkspaceServices _workspaceServices;
private readonly IEnumerable<ILanguageService> _languageServices;
public TestLanguageServices(HostWorkspaceServices workspaceServices, IEnumerable<ILanguageService> languageServices)
{
if (workspaceServices == null)
{
throw new ArgumentNullException(nameof(workspaceServices));
}
if (languageServices == null)
{
throw new ArgumentNullException(nameof(languageServices));
}
_workspaceServices = workspaceServices;
_languageServices = languageServices;
}
public override HostWorkspaceServices WorkspaceServices => _workspaceServices;
public override string Language => RazorLanguage.Name;
public override TLanguageService GetService<TLanguageService>()
{
var service = _languageServices.OfType<TLanguageService>().FirstOrDefault();
if (service == null)
{
throw new InvalidOperationException($"Test Razor language services not configured properly, missing language service '{typeof(TLanguageService).FullName}'.");
}
return service;
}
}
}