public override Task <Unit> Handle(DidCloseTextDocumentParams notification, CancellationToken token)
        {
            // Find and close the file in the current session
            var fileToClose = _workspaceService.GetFile(notification.TextDocument.Uri);

            if (fileToClose != null)
            {
                _workspaceService.CloseFile(fileToClose);
                _analysisService.ClearMarkers(fileToClose);
            }

            _logger.LogTrace("Finished closing document.");
            return(Unit.Task);
        }
        public async Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken)
        {
            LanguageServerSettingsWrapper incomingSettings = request.Settings.ToObject <LanguageServerSettingsWrapper>();

            if (incomingSettings == null)
            {
                return(await Unit.Task.ConfigureAwait(false));
            }

            bool oldLoadProfiles          = _configurationService.CurrentSettings.EnableProfileLoading;
            bool oldScriptAnalysisEnabled =
                _configurationService.CurrentSettings.ScriptAnalysis.Enable ?? false;
            string oldScriptAnalysisSettingsPath =
                _configurationService.CurrentSettings.ScriptAnalysis?.SettingsPath;

            _configurationService.CurrentSettings.Update(
                incomingSettings.Powershell,
                _workspaceService.WorkspacePath,
                _logger);

            if (!this._profilesLoaded &&
                _configurationService.CurrentSettings.EnableProfileLoading &&
                oldLoadProfiles != _configurationService.CurrentSettings.EnableProfileLoading)
            {
                await _powerShellContextService.LoadHostProfilesAsync().ConfigureAwait(false);

                this._profilesLoaded = true;
            }

            // Wait until after profiles are loaded (or not, if that's the
            // case) before starting the interactive console.
            if (!this._consoleReplStarted)
            {
                // Start the interactive terminal
                _powerShellContextService.ConsoleReader.StartCommandLoop();
                this._consoleReplStarted = true;
            }

            // If there is a new settings file path, restart the analyzer with the new settings.
            bool   settingsPathChanged = false;
            string newSettingsPath     = _configurationService.CurrentSettings.ScriptAnalysis.SettingsPath;

            if (!string.Equals(oldScriptAnalysisSettingsPath, newSettingsPath, StringComparison.OrdinalIgnoreCase))
            {
                if (_analysisService != null)
                {
                    _analysisService.SettingsPath = newSettingsPath;
                    settingsPathChanged           = true;
                }
            }

            // If script analysis settings have changed we need to clear & possibly update the current diagnostic records.
            if ((oldScriptAnalysisEnabled != _configurationService.CurrentSettings.ScriptAnalysis?.Enable) || settingsPathChanged)
            {
                // If the user just turned off script analysis or changed the settings path, send a diagnostics
                // event to clear the analysis markers that they already have.
                if (!_configurationService.CurrentSettings.ScriptAnalysis.Enable.Value || settingsPathChanged)
                {
                    foreach (var scriptFile in _workspaceService.GetOpenedFiles())
                    {
                        _analysisService.ClearMarkers(scriptFile);
                    }
                }
            }

            // Convert the editor file glob patterns into an array for the Workspace
            // Both the files.exclude and search.exclude hash tables look like (glob-text, is-enabled):
            // "files.exclude" : {
            //     "Makefile": true,
            //     "*.html": true,
            //     "build/*": true
            // }
            var excludeFilePatterns = new List <string>();

            if (incomingSettings.Files?.Exclude != null)
            {
                foreach (KeyValuePair <string, bool> patternEntry in incomingSettings.Files.Exclude)
                {
                    if (patternEntry.Value)
                    {
                        excludeFilePatterns.Add(patternEntry.Key);
                    }
                }
            }
            if (incomingSettings.Search?.Exclude != null)
            {
                foreach (KeyValuePair <string, bool> patternEntry in incomingSettings.Files.Exclude)
                {
                    if (patternEntry.Value && !excludeFilePatterns.Contains(patternEntry.Key))
                    {
                        excludeFilePatterns.Add(patternEntry.Key);
                    }
                }
            }
            _workspaceService.ExcludeFilesGlob = excludeFilePatterns;

            // Convert the editor file search options to Workspace properties
            if (incomingSettings.Search?.FollowSymlinks != null)
            {
                _workspaceService.FollowSymlinks = incomingSettings.Search.FollowSymlinks;
            }

            return(await Unit.Task.ConfigureAwait(false));
        }