Example #1
0
        public override void InitializeService(IServiceHost serviceHost)
        {
            // get a handle on the SettingsService
            SettingsService = this.ServiceProvider.GetService <SettingsService <LanguageServerSettings> >();
            Debug.Assert(SettingsService != null, "SettingsService instance not set");

            SettingsService.RegisterConfigChangeCallback(HandleDidChangeConfigurationNotification);

            // get a handle on the WorkspaceService
            WorkspaceService = this.ServiceProvider.GetService <WorkspaceService>();
            Debug.Assert(WorkspaceService != null, "WorkspaceService instance not set");

            // register a callback to handle document changes
            WorkspaceService.RegisterTextDocChangeCallback(HandleDidChangeTextDocumentNotification);

            // Register an initialization handler that retrieves the initial settings
            serviceHost.RegisterInitializeTask(async(parameters, context) =>
            {
                Logger.Instance.Write(LogLevel.Verbose, "Initializing service");

                context.SendEvent(
                    DidChangeConfigurationNotification <LanguageServerSettings> .Type,
                    new DidChangeConfigurationParams <LanguageServerSettings>
                {
                    Settings = new LanguageServerSettings()
                }
                    );

                await Task.FromResult(0);
            });
        }
Example #2
0
        public override void InitializeService(IServiceHost serviceHost)
        {
            serviceHost.SetAsyncEventHandler(DidChangeTextDocumentNotification.Type, HandleDidChangeTextDocumentNotification);
            serviceHost.SetAsyncEventHandler(DidOpenTextDocumentNotification.Type, HandleDidOpenTextDocumentNotification);
            serviceHost.SetAsyncEventHandler(DidCloseTextDocumentNotification.Type, HandleDidCloseTextDocumentNotification);

            // Register an initialization handler that sets the workspace path
            serviceHost.RegisterInitializeTask(async(parameters, context) =>
            {
                Logger.Instance.Write(LogLevel.Verbose, "Initializing workspace service");

                // Create a workspace that will handle state for the session
                Workspace = new Workspace(parameters.Capabilities);

                // we only support a single workspace path
                if (parameters.WorkspaceFolders != null)
                {
                    Workspace.WorkspacePath = parameters.WorkspaceFolders.First().Uri;
                }
                else
                {
                    Workspace.WorkspacePath = parameters.RootUri;
                }

                await Task.FromResult(0);
            });

            // Register a shutdown request that disposes the workspace
            serviceHost.RegisterShutdownTask(async(parameters, context) =>
            {
                Logger.Instance.Write(LogLevel.Verbose, "Shutting down workspace service");

                if (Workspace != null)
                {
                    Workspace.Dispose();
                    Workspace = null;
                }

                await Task.FromResult(0);
            });
        }