forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.cs
141 lines (128 loc) · 6.23 KB
/
Server.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Bicep.Core;
using Bicep.Core.Analyzers.Interfaces;
using Bicep.Core.Analyzers.Linter;
using Bicep.Core.Analyzers.Linter.ApiVersions;
using Bicep.Core.Configuration;
using Bicep.Core.Emit;
using Bicep.Core.Features;
using Bicep.Core.FileSystem;
using Bicep.Core.Registry;
using Bicep.Core.Registry.Auth;
using Bicep.Core.Semantics.Namespaces;
using Bicep.Core.Tracing;
using Bicep.Core.TypeSystem.Az;
using Bicep.Core.Workspaces;
using Bicep.Decompiler;
using Bicep.LanguageServer.CompilationManager;
using Bicep.LanguageServer.Completions;
using Bicep.LanguageServer.Configuration;
using Bicep.LanguageServer.Deploy;
using Bicep.LanguageServer.Extensions;
using Bicep.LanguageServer.Handlers;
using Bicep.LanguageServer.ParamsHandlers;
using Bicep.LanguageServer.Providers;
using Bicep.LanguageServer.Registry;
using Bicep.LanguageServer.Snippets;
using Bicep.LanguageServer.Telemetry;
using Bicep.LanguageServer.Utils;
using Microsoft.Extensions.DependencyInjection;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.Window;
using OmniSharp.Extensions.LanguageServer.Server;
using System;
using System.Diagnostics;
using System.IO.Abstractions;
using System.Threading;
using System.Threading.Tasks;
using OmnisharpLanguageServer = OmniSharp.Extensions.LanguageServer.Server.LanguageServer;
namespace Bicep.LanguageServer
{
public class Server : IDisposable
{
private readonly OmnisharpLanguageServer server;
public Server(Action<LanguageServerOptions> onOptionsFunc)
{
BicepDeploymentsInterop.Initialize();
server = OmnisharpLanguageServer.PreInit(options =>
{
options
.WithHandler<BicepTextDocumentSyncHandler>()
.WithHandler<BicepDocumentSymbolHandler>()
.WithHandler<BicepDefinitionHandler>()
.WithHandler<BicepDeploymentGraphHandler>()
.WithHandler<BicepReferencesHandler>()
.WithHandler<BicepDocumentHighlightHandler>()
.WithHandler<BicepDocumentFormattingHandler>()
.WithHandler<BicepRenameHandler>()
.WithHandler<BicepHoverHandler>()
.WithHandler<BicepCompletionHandler>()
.WithHandler<BicepCodeActionHandler>()
.WithHandler<BicepCreateConfigFileHandler>()
.WithHandler<BicepDidChangeWatchedFilesHandler>()
.WithHandler<BicepEditLinterRuleCommandHandler>()
.WithHandler<BicepGetRecommendedConfigLocationHandler>()
.WithHandler<BicepSignatureHelpHandler>()
.WithHandler<BicepSemanticTokensHandler>()
.WithHandler<BicepParamsDefinitionHandler>()
.WithHandler<BicepTelemetryHandler>()
.WithHandler<BicepBuildCommandHandler>()
.WithHandler<BicepGenerateParamsCommandHandler>()
.WithHandler<BicepDeploymentStartCommandHandler>()
// Base handler (ExecuteTypedResponseCommandHandlerBase) is serial. This blocks other commands on the client side.
// To avoid the above issue, we'll change the RequestProcessType to parallel
.WithHandler<BicepDeploymentWaitForCompletionCommandHandler>(new JsonRpcHandlerOptions() { RequestProcessType = RequestProcessType.Parallel })
.WithHandler<BicepDecompileCommandHandler>()
.WithHandler<BicepDecompileSaveCommandHandler>()
.WithHandler<BicepDeploymentScopeRequestHandler>()
.WithHandler<BicepDeploymentParametersHandler>()
.WithHandler<ImportKubernetesManifestHandler>()
.WithHandler<BicepForceModulesRestoreCommandHandler>()
.WithHandler<BicepRegistryCacheRequestHandler>()
.WithHandler<InsertResourceHandler>()
.WithServices(RegisterServices);
onOptionsFunc(options);
});
}
public async Task RunAsync(CancellationToken cancellationToken)
{
await server.Initialize(cancellationToken);
server.LogInfo($"Running on processId {Environment.ProcessId}");
if (FeatureProvider.TracingEnabled)
{
Trace.Listeners.Add(new ServerLogTraceListener(server));
}
using (FeatureProvider.TracingEnabled ? AzureEventSourceListenerFactory.Create(FeatureProvider.TracingVerbosity) : null)
{
var scheduler = server.GetRequiredService<IModuleRestoreScheduler>();
scheduler.Start();
await server.WaitForExit;
}
}
private static void RegisterServices(IServiceCollection services)
{
// using type based registration so dependencies can be injected automatically
// without manually constructing up the graph
services
.AddBicepCore()
.AddSingleton<ISnippetsProvider, SnippetsProvider>()
.AddSingleton<ITelemetryProvider, TelemetryProvider>()
.AddSingleton<ICompilationManager, BicepCompilationManager>()
.AddSingleton<ICompilationProvider, BicepCompilationProvider>()
.AddSingleton<ISymbolResolver, BicepSymbolResolver>()
.AddSingleton<ICompletionProvider, BicepCompletionProvider>()
.AddSingleton<IModuleRestoreScheduler, ModuleRestoreScheduler>()
.AddSingleton<IAzResourceProvider, AzResourceProvider>()
.AddSingleton<IBicepConfigChangeHandler, BicepConfigChangeHandler>()
.AddSingleton<IDeploymentCollectionProvider, DeploymentCollectionProvider>()
.AddSingleton<IDeploymentOperationsCache, DeploymentOperationsCache>()
.AddSingleton<IDeploymentFileCompilationCache, DeploymentFileCompilationCache>()
.AddSingleton<IClientCapabilitiesProvider, ClientCapabilitiesProvider>();
}
public void Dispose()
{
server.Dispose();
}
}
}