private void CreateCodeActionResolver( out CSharpCodeActionParams codeActionParams, out DefaultCSharpCodeActionResolver csharpCodeActionResolver, IClientLanguageServer languageServer = null, DocumentVersionCache documentVersionCache = null, RazorFormattingService razorFormattingService = null) { var documentPath = "c:/Test.razor"; var documentUri = new Uri(documentPath); var contents = string.Empty; var codeDocument = CreateCodeDocument(contents, documentPath); codeActionParams = new CSharpCodeActionParams() { Data = new JObject(), RazorFileUri = documentUri }; languageServer ??= CreateLanguageServer(); documentVersionCache ??= CreateDocumentVersionCache(); razorFormattingService ??= CreateRazorFormattingService(documentUri); csharpCodeActionResolver = new DefaultCSharpCodeActionResolver( new DefaultForegroundDispatcher(), CreateDocumentResolver(documentPath, codeDocument), languageServer, razorFormattingService, documentVersionCache); }
public DefaultCSharpCodeActionResolver( ForegroundDispatcher foregroundDispatcher, DocumentResolver documentResolver, IClientLanguageServer languageServer, RazorFormattingService razorFormattingService, DocumentVersionCache documentVersionCache) : base(languageServer) { if (foregroundDispatcher is null) { throw new ArgumentNullException(nameof(foregroundDispatcher)); } if (documentResolver is null) { throw new ArgumentNullException(nameof(documentResolver)); } if (razorFormattingService is null) { throw new ArgumentNullException(nameof(razorFormattingService)); } if (documentVersionCache is null) { throw new ArgumentNullException(nameof(documentVersionCache)); } _foregroundDispatcher = foregroundDispatcher; _documentResolver = documentResolver; _razorFormattingService = razorFormattingService; _documentVersionCache = documentVersionCache; }
public DefaultGeneratedDocumentPublisher( ForegroundDispatcher foregroundDispatcher, IClientLanguageServer server, ILoggerFactory loggerFactory) { if (foregroundDispatcher is null) { throw new ArgumentNullException(nameof(foregroundDispatcher)); } if (server is null) { throw new ArgumentNullException(nameof(server)); } if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } _foregroundDispatcher = foregroundDispatcher; _server = server; _logger = loggerFactory.CreateLogger <DefaultGeneratedDocumentPublisher>(); _publishedCSharpData = new Dictionary <string, PublishData>(FilePathComparer.Instance); _publishedHtmlData = new Dictionary <string, PublishData>(FilePathComparer.Instance); }
internal LanguageServer( Connection connection, IResponseRouter responseRouter, IOptions <LanguageServerOptions> options, ILanguageServerConfiguration configuration, ServerInfo serverInfo, ILspServerReceiver receiver, ISerializer serializer, IServiceProvider serviceProvider, ISupportedCapabilities supportedCapabilities, TextDocumentIdentifiers textDocumentIdentifiers, IEnumerable <OnLanguageServerInitializeDelegate> initializeDelegates, IEnumerable <OnLanguageServerInitializedDelegate> initializedDelegates, IEnumerable <OnLanguageServerStartedDelegate> startedDelegates, IEnumerable <IOnLanguageServerStarted> startedHandlers, IServerWorkDoneManager serverWorkDoneManager, ITextDocumentLanguageServer textDocumentLanguageServer, IClientLanguageServer clientLanguageServer, IGeneralLanguageServer generalLanguageServer, IWindowLanguageServer windowLanguageServer, IWorkspaceLanguageServer workspaceLanguageServer, LanguageProtocolSettingsBag languageProtocolSettingsBag, SharedHandlerCollection handlerCollection, IProgressManager progressManager, ILanguageServerWorkspaceFolderManager workspaceFolderManager, IEnumerable <IOnLanguageServerInitialize> initializeHandlers, IEnumerable <IOnLanguageServerInitialized> initializedHandlers ) : base(handlerCollection, responseRouter) { Configuration = configuration; _connection = connection; _serverInfo = serverInfo; _serverReceiver = receiver; _serializer = serializer; _supportedCapabilities = supportedCapabilities; _textDocumentIdentifiers = textDocumentIdentifiers; _initializeDelegates = initializeDelegates; _initializedDelegates = initializedDelegates; _startedDelegates = startedDelegates; _startedHandlers = startedHandlers; WorkDoneManager = serverWorkDoneManager; _settingsBag = languageProtocolSettingsBag; Services = serviceProvider; _collection = handlerCollection; // We need to at least create Window here in case any handler does logging in their constructor TextDocument = textDocumentLanguageServer; Client = clientLanguageServer; General = generalLanguageServer; Window = windowLanguageServer; Workspace = workspaceLanguageServer; ProgressManager = progressManager; WorkspaceFolderManager = workspaceFolderManager; _initializeHandlers = initializeHandlers; _initializedHandlers = initializedHandlers; _concurrency = options.Value.Concurrency; _disposable.Add(_collection.Add(this)); }
// Need to have a lazy server here because if we try to resolve the server it creates types which create a DefaultTagHelperDescriptionFactory, and we end up StackOverflowing. // This lazy can be avoided in the future by using an upcoming ILanguageServerSettings interface, but it doesn't exist/work yet. public DefaultTagHelperDescriptionFactory(IClientLanguageServer languageServer) { if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } LanguageServer = languageServer; }
public CSharpCodeActionResolver(IClientLanguageServer languageServer) { if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } _languageServer = languageServer; }
public DefaultWorkspaceDirectoryPathResolver(IClientLanguageServer languageServer) { if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } _languageServer = languageServer; }
public DefaultClientNotifierService(IClientLanguageServer languageServer) { if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } _languageServer = languageServer; _initializedCompletionSource = new TaskCompletionSource <bool>(); }
private DefaultRazorHoverInfoService GetDefaultRazorHoverInfoService(IClientLanguageServer languageServer = null) { if (languageServer is null) { languageServer = LanguageServer; } var tagHelperDescriptionFactory = new DefaultTagHelperDescriptionFactory(languageServer); return(new DefaultRazorHoverInfoService(TagHelperFactsService, tagHelperDescriptionFactory, HtmlFactsService)); }
public FormattingDiagnosticValidationPass( RazorDocumentMappingService documentMappingService, FilePathNormalizer filePathNormalizer, IClientLanguageServer server, ILoggerFactory loggerFactory) : base(documentMappingService, filePathNormalizer, server) { if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } _logger = loggerFactory.CreateLogger <FormattingDiagnosticValidationPass>(); }
public DefaultRazorConfigurationService(IClientLanguageServer languageServer, ILoggerFactory loggerFactory) { if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } if (loggerFactory is null) { throw new ArgumentNullException(nameof(loggerFactory)); } _server = languageServer; _logger = loggerFactory.CreateLogger <DefaultRazorConfigurationService>(); }
internal static IDisposable RegisterHandlers( IObservable <Unit> initializeComplete, IClientLanguageServer client, IServerWorkDoneManager serverWorkDoneManager, ISupportedCapabilities supportedCapabilities, IEnumerable <ILspHandlerDescriptor> collection ) { var descriptors = new List <ILspHandlerDescriptor>(); foreach (var descriptor in collection) { if ( descriptor is LspHandlerDescriptor lspHandlerDescriptor && (lspHandlerDescriptor.TypeDescriptor is { } &&
public DefaultWorkspaceSemanticTokensRefreshPublisher(IClientLanguageServer languageServer, ErrorReporter errorReporter) { if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } if (errorReporter is null) { throw new ArgumentNullException(nameof(errorReporter)); } _languageServer = languageServer; _workQueue = new BatchingWorkQueue(s_debounceTimeSpan, StringComparer.Ordinal, errorReporter: errorReporter); }
public CodeActionEndpoint( RazorDocumentMappingService documentMappingService, IEnumerable <RazorCodeActionProvider> razorCodeActionProviders, IEnumerable <CSharpCodeActionProvider> csharpCodeActionProviders, ForegroundDispatcher foregroundDispatcher, DocumentResolver documentResolver, IClientLanguageServer languageServer, LanguageServerFeatureOptions languageServerFeatureOptions) { _documentMappingService = documentMappingService ?? throw new ArgumentNullException(nameof(documentMappingService)); _razorCodeActionProviders = razorCodeActionProviders ?? throw new ArgumentNullException(nameof(razorCodeActionProviders)); _csharpCodeActionProviders = csharpCodeActionProviders ?? throw new ArgumentNullException(nameof(csharpCodeActionProviders)); _foregroundDispatcher = foregroundDispatcher ?? throw new ArgumentNullException(nameof(foregroundDispatcher)); _documentResolver = documentResolver ?? throw new ArgumentNullException(nameof(documentResolver)); _languageServer = languageServer ?? throw new ArgumentNullException(nameof(languageServer)); _languageServerFeatureOptions = languageServerFeatureOptions ?? throw new ArgumentNullException(nameof(languageServerFeatureOptions)); }
public RazorServerReadyPublisher( ForegroundDispatcher foregroundDispatcher, IClientLanguageServer languageServer) { if (foregroundDispatcher is null) { throw new ArgumentNullException(nameof(foregroundDispatcher)); } if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } _foregroundDispatcher = foregroundDispatcher; _languageServer = languageServer; }
public HtmlFormatter( IClientLanguageServer languageServer, FilePathNormalizer filePathNormalizer) { if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } if (filePathNormalizer is null) { throw new ArgumentNullException(nameof(filePathNormalizer)); } _server = languageServer; _filePathNormalizer = filePathNormalizer; }
public CSharpFormatter( RazorDocumentMappingService documentMappingService, IClientLanguageServer languageServer, FilePathNormalizer filePathNormalizer) { if (documentMappingService is null) { throw new ArgumentNullException(nameof(documentMappingService)); } if (languageServer is null) { throw new ArgumentNullException(nameof(languageServer)); } if (filePathNormalizer is null) { throw new ArgumentNullException(nameof(filePathNormalizer)); } _documentMappingService = documentMappingService; _server = languageServer; _filePathNormalizer = filePathNormalizer; try { var type = typeof(CSharpFormattingOptions).Assembly.GetType("Microsoft.CodeAnalysis.CSharp.Indentation.CSharpIndentationService", throwOnError: true); _indentationService = Activator.CreateInstance(type); var indentationService = type.GetInterface("IIndentationService"); _getIndentationMethod = indentationService.GetMethod("GetIndentation"); } catch (Exception ex) { throw new InvalidOperationException( "Error occured when creating an instance of Roslyn's IIndentationService. Roslyn may have changed in an unexpected way.", ex); } }
internal static IDisposable RegisterHandlers( IObservable <Unit> initializeComplete, IClientLanguageServer client, IServerWorkDoneManager serverWorkDoneManager, ISupportedCapabilities supportedCapabilities, IDisposable handlerDisposable ) { if (handlerDisposable is LspHandlerDescriptorDisposable lsp) { return(new CompositeDisposable( lsp, RegisterHandlers( initializeComplete, client, serverWorkDoneManager, supportedCapabilities, lsp.Descriptors ) )); } if (!(handlerDisposable is CompositeDisposable cd)) { return(Disposable.Empty); } cd.Add( RegisterHandlers( initializeComplete, client, serverWorkDoneManager, supportedCapabilities, cd.OfType <LspHandlerDescriptorDisposable>().SelectMany(z => z.Descriptors) ) ); return(cd); }
public FormattingPassBase( RazorDocumentMappingService documentMappingService, FilePathNormalizer filePathNormalizer, IClientLanguageServer server) { if (documentMappingService is null) { throw new ArgumentNullException(nameof(documentMappingService)); } if (filePathNormalizer is null) { throw new ArgumentNullException(nameof(filePathNormalizer)); } if (server is null) { throw new ArgumentNullException(nameof(server)); } DocumentMappingService = documentMappingService; CSharpFormatter = new CSharpFormatter(documentMappingService, server, filePathNormalizer); HtmlFormatter = new HtmlFormatter(server, filePathNormalizer); }
internal static IDisposable RegisterHandlers( IObservable <Unit> initializeComplete, IClientLanguageServer client, IServerWorkDoneManager serverWorkDoneManager, ISupportedCapabilities supportedCapabilities, IEnumerable <ILspHandlerDescriptor> collection ) { var descriptors = new List <ILspHandlerDescriptor>(); foreach (var descriptor in collection) { if (descriptor is LspHandlerDescriptor lspHandlerDescriptor && lspHandlerDescriptor.TypeDescriptor?.HandlerType != null && typeof(IDoesNotParticipateInRegistration).IsAssignableFrom(lspHandlerDescriptor.TypeDescriptor.HandlerType)) { continue; } descriptors.Add(descriptor); } return(DynamicallyRegisterHandlers(client, initializeComplete, serverWorkDoneManager, supportedCapabilities, descriptors)); }
internal static IDisposable DynamicallyRegisterHandlers( IClientLanguageServer client, IObservable <Unit> initializeComplete, IServerWorkDoneManager serverWorkDoneManager, ISupportedCapabilities supportedCapabilities, IReadOnlyList <ILspHandlerDescriptor> descriptors ) { if (descriptors.Count == 0) { return(Disposable.Empty); // No dynamic registrations supported by client. } var disposable = new CompositeDisposable(); var result = initializeComplete .LastOrDefaultAsync() .Select( _ => { var registrations = new List <Registration>(); foreach (var descriptor in descriptors) { if (descriptor.HasCapability && supportedCapabilities.AllowsDynamicRegistration(descriptor.CapabilityType)) { if (descriptor.RegistrationOptions is IWorkDoneProgressOptions wdpo) { wdpo.WorkDoneProgress = serverWorkDoneManager.IsSupported; } registrations.Add( new Registration { Id = descriptor.Id.ToString(), Method = descriptor.Method, RegisterOptions = descriptor.RegistrationOptions } ); } } return(registrations); } ) .SelectMany( registrations => Observable.FromAsync(ct => client.RegisterCapability(new RegistrationParams { Registrations = registrations }, ct)), (a, b) => a ) .Aggregate((z, b) => z) .Subscribe( registrations => { disposable.Add( Disposable.Create( () => { client.UnregisterCapability( new UnregistrationParams { Unregisterations = registrations } ).ToObservable().Subscribe(); } ) ); } ); disposable.Add(result); return(disposable); }
public SemanticTokensRefreshWorkItem(IClientLanguageServer languageServer) { _languageServer = languageServer; }
internal LanguageServer( Connection connection, IResponseRouter responseRouter, IOptions <LanguageServerOptions> options, ILanguageServerConfiguration configuration, ServerInfo serverInfo, ILspServerReceiver receiver, ISerializer serializer, IResolverContext resolverContext, ISupportedCapabilities supportedCapabilities, TextDocumentIdentifiers textDocumentIdentifiers, IEnumerable <OnLanguageServerInitializeDelegate> initializeDelegates, IEnumerable <OnLanguageServerInitializedDelegate> initializedDelegates, IEnumerable <OnLanguageServerStartedDelegate> startedDelegates, IEnumerable <IOnLanguageServerStarted> startedHandlers, IServerWorkDoneManager serverWorkDoneManager, ITextDocumentLanguageServer textDocumentLanguageServer, IClientLanguageServer clientLanguageServer, IGeneralLanguageServer generalLanguageServer, IWindowLanguageServer windowLanguageServer, IWorkspaceLanguageServer workspaceLanguageServer, LanguageProtocolSettingsBag languageProtocolSettingsBag, SharedHandlerCollection handlerCollection, IProgressManager progressManager, ILanguageServerWorkspaceFolderManager workspaceFolderManager, IEnumerable <IOnLanguageServerInitialize> initializeHandlers, IEnumerable <IOnLanguageServerInitialized> initializedHandlers, IEnumerable <IRegistrationOptionsConverter> registrationOptionsConverters, InstanceHasStarted instanceHasStarted ) : base(handlerCollection, responseRouter) { Configuration = configuration; _connection = connection; _serverInfo = serverInfo; _serverReceiver = receiver; _serializer = serializer; _supportedCapabilities = supportedCapabilities; _textDocumentIdentifiers = textDocumentIdentifiers; _initializeDelegates = initializeDelegates; _initializedDelegates = initializedDelegates; _startedDelegates = startedDelegates; _startedHandlers = startedHandlers; WorkDoneManager = serverWorkDoneManager; _settingsBag = languageProtocolSettingsBag; Services = _resolverContext = resolverContext; _collection = handlerCollection; // We need to at least create Window here in case any handler does logging in their constructor TextDocument = textDocumentLanguageServer; Client = clientLanguageServer; General = generalLanguageServer; Window = windowLanguageServer; Workspace = workspaceLanguageServer; ProgressManager = progressManager; WorkspaceFolderManager = workspaceFolderManager; _initializeHandlers = initializeHandlers; _initializedHandlers = initializedHandlers; _registrationOptionsConverters = registrationOptionsConverters; _instanceHasStarted = instanceHasStarted; _concurrency = options.Value.Concurrency; _capabilityTypes = options .Value.Assemblies .SelectMany(z => z.ExportedTypes) .Where(z => z.IsClass && !z.IsAbstract) .Where(z => typeof(ICapability).IsAssignableFrom(z)) .Where(z => z.GetCustomAttributes <CapabilityKeyAttribute>().Any()) .ToLookup(z => string.Join(".", z.GetCustomAttribute <CapabilityKeyAttribute>().Keys)); _disposable.Add(_collection.Add(this)); }