Example #1
0
        internal virtual void DidChangeConfiguration(LSP.Implementation.LanguageClient client)
        {
            var param = new DidChangeConfigurationParams();

            param.settings = new object();
            client.Send.WorkspaceDidChangeConfiguration(param);
        }
        protected async Task HandleDidChangeConfigurationNotification(
            DidChangeConfigurationParams <SettingsWrapper> configChangeParams,
            EventContext eventContext)
        {
            bool oldScriptAnalysisEnabled =
                this.currentSettings.ScriptAnalysis.Enable.HasValue;

            this.currentSettings.Update(
                configChangeParams.Settings.Powershell);

            if (oldScriptAnalysisEnabled != this.currentSettings.ScriptAnalysis.Enable)
            {
                // If the user just turned off script analysis, send a diagnostics
                // event to clear the analysis markers that they already have
                if (!this.currentSettings.ScriptAnalysis.Enable.Value)
                {
                    ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0];

                    foreach (var scriptFile in editorSession.Workspace.GetOpenedFiles())
                    {
                        await PublishScriptDiagnostics(
                            scriptFile,
                            emptyAnalysisDiagnostics,
                            eventContext);
                    }
                }
            }
        }
Example #3
0
        public async Task ChangeConfigurationTest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestHelper testHelper = new TestHelper())
                {
                    bool connected = await testHelper.Connect(queryTempFile.FilePath, ConnectionTestUtils.LocalhostConnection);

                    Assert.True(connected, "Connection was not successful");

                    Thread.Sleep(500);

                    var settings = new SqlToolsSettings();
                    settings.SqlTools.IntelliSense.EnableIntellisense = false;
                    DidChangeConfigurationParams <SqlToolsSettings> configParams = new DidChangeConfigurationParams <SqlToolsSettings>()
                    {
                        Settings = settings
                    };

                    await testHelper.RequestChangeConfigurationNotification(configParams);

                    Thread.Sleep(2000);

                    await testHelper.Disconnect(queryTempFile.FilePath);
                }
        }
        public override async Task DidChangeConfiguration(DidChangeConfigurationParams @params, CancellationToken cancellationToken)
        {
            _disposableBag.ThrowIfDisposed();

            if (Analyzer == null)
            {
                LogMessage(MessageType.Error, "Change configuration notification sent to uninitialized server");
                return;
            }

            var reanalyze = true;

            if (@params.settings != null)
            {
                if (@params.settings is ServerSettings settings)
                {
                    reanalyze = HandleConfigurationChanges(settings);
                }
                else
                {
                    LogMessage(MessageType.Error, "change configuration notification sent unsupported settings");
                    return;
                }
            }

            if (reanalyze)
            {
                await ReloadModulesAsync(cancellationToken);
            }
        }
        public async Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken)
        {
            _logger.LogTrace("Settings changed. Updating the server.");

            await _optionsMonitor.UpdateAsync();

            return(new Unit());
        }
Example #6
0
File: App.cs Project: 5l1v3r1/Aphid
 protected override void DidChangeConfiguration(DidChangeConfigurationParams @params)
 {
     _maxNumberOfProblems = @params?.settings?.languageServerExample?.maxNumberOfProblems ?? 100;
     foreach (var document in _documents.All)
     {
         ValidateTextDocument(document);
     }
 }
Example #7
0
 protected override void DidChangeConfiguration(DidChangeConfigurationParams @params)
 {
     _maxNumberOfProblems = @params?.settings?.languageServerExample?.maxNumberOfProblems ?? _maxNumberOfProblems;
     Logger.Instance.Log($"maxNumberOfProblems is set to {_maxNumberOfProblems}.");
     foreach (var document in _documents.All)
     {
         ValidateTextDocument(document);
     }
 }
Example #8
0
        protected override void DidChangeConfiguration(DidChangeConfigurationParams @params)
        {
            _validator.UpdateConfig(@params.settings);

            foreach (var document in _documents.All)
            {
                ValidateTextDocument(document);
            }
        }
        /// <summary>
        /// Handles the configuration change event
        /// </summary>
        internal async Task HandleDidChangeConfigurationNotification(
            DidChangeConfigurationParams <TConfig> configChangeParams,
            EventContext eventContext)
        {
            Logger.Write(LogLevel.Verbose, "HandleDidChangeConfigurationNotification");

            // Propagate the changes to the event handlers
            var configUpdateTasks = ConfigChangeCallbacks.Select(
                t => t(configChangeParams.Settings, CurrentSettings, eventContext));
            await Task.WhenAll(configUpdateTasks);
        }
        public Task <Unit> Handle(DidChangeConfigurationParams configChangeParams, CancellationToken token)
        {
            var json = configChangeParams.Settings?.SelectToken("ostw") as JObject;

            if (json != null)
            {
                var config = json.ToObject <RawConfiguration>();
                I18n.I18n.LoadLanguage(config.GetOutputLanguage());
            }

            return(Unit.Task);
        }
        public Task <Unit> Handle(DidChangeConfigurationParams configChangeParams, CancellationToken token)
        {
            var json = configChangeParams.Settings?.SelectToken("ostw") as JObject;

            if (json != null)
            {
                dynamic config = json;

                ReferencesCodeLens   = config.codelens.references;
                ImplementsCodeLens   = config.codelens.implements;
                ElementCountCodeLens = config.codelens.elementCount;
                OutputLanguage       = GetOutputLanguage(config.outputLanguage);
                LanguageInfo.LoadLanguage(OutputLanguage);
                OptimizeOutput = config.optimizeOutput;
            }

            return(Unit.Task);

            OutputLanguage GetOutputLanguage(string languageString)
            {
                switch (languageString)
                {
                case "English": return(OutputLanguage.enUS);

                case "German": return(OutputLanguage.deDE);

                case "Spanish (Castilian)": return(OutputLanguage.esES);

                case "Spanish (Mexico)": return(OutputLanguage.esMX);

                case "French": return(OutputLanguage.frFR);

                case "Italian": return(OutputLanguage.itIT);

                case "Japanese": return(OutputLanguage.jaJP);

                case "Korean": return(OutputLanguage.koKR);

                case "Polish": return(OutputLanguage.plPL);

                case "Portuguese": return(OutputLanguage.ptBR);

                case "Russian": return(OutputLanguage.ruRU);

                case "Chinese (S)": return(OutputLanguage.zhCN);

                case "Chinese (T)": return(OutputLanguage.zhTW);

                default: return(OutputLanguage.enUS);
                }
            }
        }
 public override void OnDidChangeConfiguration(DidChangeConfigurationParams parameters)
 {
     if (parameters.settings is Newtonsoft.Json.Linq.JArray)
     {
         Newtonsoft.Json.Linq.JArray array     = parameters.settings as Newtonsoft.Json.Linq.JArray;
         IEnumerable <string>        arguments = array.Select(t => t.ToString());
         typeCobolWorkspace.DidChangeConfigurationParams(arguments);
     }
     else
     {
         typeCobolWorkspace.DidChangeConfigurationParams(parameters.settings.ToString());
     }
 }
        public void SendSettings(DidChangeConfigurationParams parameter)
        {
            this.CurrentSettings = parameter.Settings.ToString();
            this.NotifyPropertyChanged(nameof(CurrentSettings));

            JToken parsedSettings = JToken.Parse(this.CurrentSettings);
            int    newMaxProblems = parsedSettings.Children().First().Values <int>("maxNumberOfProblems").First();

            if (this.maxProblems != newMaxProblems)
            {
                this.maxProblems = newMaxProblems;
            }
        }
        public async Task Handle_UpdatesOptions()
        {
            // Arrange
            var optionsMonitor = new TestRazorLSPOptionsMonitor(ConfigurationService, Cache);
            var endpoint       = new RazorConfigurationEndpoint(optionsMonitor, LoggerFactory);
            var request        = new DidChangeConfigurationParams();

            // Act
            await endpoint.Handle(request, CancellationToken.None);

            // Assert
            Assert.True(optionsMonitor.Called, "UpdateAsync was not called.");
        }
Example #15
0
        public async Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken)
        {
            // null means we need to re-read the configuration
            // https://github.com/Microsoft/vscode-languageserver-node/issues/380
            if (request.Settings == null || request.Settings.Type == JTokenType.Null)
            {
                await GetWorkspaceConfiguration();

                return(Unit.Value);
            }

            ParseClientConfiguration(request.Settings);
            OnReload();
            return(Unit.Value);
        }
Example #16
0
        public void DidChangeConfiguration(DidChangeConfigurationParams @params, CancellationToken cancellationToken)
        {
            _disposableBag.ThrowIfDisposed();
            switch (@params.settings)
            {
            case ServerSettings settings:
                Settings = settings;
                _symbolHierarchyMaxSymbols = Settings.analysis.symbolsHierarchyMaxSymbols;
                _completionSource.Options  = Settings.completion;
                break;

            default:
                _log?.Log(TraceEventType.Error, "change configuration notification sent unsupported settings");
                break;
            }
        }
        public void DidChangeConfiguration(DidChangeConfigurationParams @params, CancellationToken cancellationToken)
        {
            _disposableBag.ThrowIfDisposed();
            switch (@params.settings)
            {
            case ServerSettings settings: {
                if (HandleConfigurationChanges(settings))
                {
                    RestartAnalysis();
                }
                break;
            }

            default:
                _log?.Log(TraceEventType.Error, "change configuration notification sent unsupported settings");
                break;
            }
        }
        public void SimpleTest(string expected)
        {
            var model = new DidChangeConfigurationParams()
            {
                Settings = new Dictionary <string, BooleanNumberString>()
                {
                    { "abc", 1 },
                    { "def", "a" },
                    { "ghi", true },
                }
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = JsonConvert.DeserializeObject <DidChangeConfigurationParams>(expected);

            deresult.ShouldBeEquivalentTo(model);
        }
Example #19
0
        public Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken)
        {
            if (_capability == null)
            {
                return(Unit.Task);
            }
            // null means we need to re-read the configuration
            // https://github.com/Microsoft/vscode-languageserver-node/issues/380
            if (request.Settings == null || request.Settings.Type == JTokenType.Null)
            {
                _triggerChange.OnNext(System.Reactive.Unit.Default);
                return(Unit.Task);
            }

            Data.Clear();
            _configurationConverter.ParseClientConfiguration(Data, request.Settings);
            OnReload();
            return(Unit.Task);
        }
        public void SimpleTest(string expected)
        {
            var model = new DidChangeConfigurationParams()
            {
                Settings = JObject.FromObject(new Dictionary <string, object>()
                {
                    { "abc", 1 },
                    { "def", "a" },
                    { "ghi", true },
                })
            };
            var result = Fixture.SerializeObject(model);

            result.Should().Be(expected);

            var deresult = new Serializer(ClientVersion.Lsp3).DeserializeObject <DidChangeConfigurationParams>(expected);

            deresult.Should().BeEquivalentTo(model);
        }
        public void SendSettings(DidChangeConfigurationParams parameter)
        {
            this.CurrentSettings = parameter.Settings.ToString();
            this.NotifyPropertyChanged(nameof(CurrentSettings));

            try
            {
                JToken parsedSettings = JToken.Parse(this.CurrentSettings);
                int    newMaxProblems = parsedSettings.Children().First().Values <int>("maxNumberOfProblems").First();
                if (this.maxProblems != newMaxProblems)
                {
                    this.maxProblems = newMaxProblems;
                    this.SendDiagnostics();
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log("Error reading settings: " + ex.Message);
            }
        }
        async Task SendConfigurationSettings()
        {
            var settings = LanguageClientConfigurationSettingsProvider.GetSettings(
                client.ConfigurationSections,
                client.GetType());

            if (settings == null)
            {
                return;
            }

            Log("Sending '{0}' message.", Methods.WorkspaceDidChangeConfigurationName);

            var message = new DidChangeConfigurationParams {
                Settings = settings
            };

            await jsonRpc.NotifyWithParameterObjectAsync(Methods.WorkspaceDidChangeConfigurationName, message);

            Log("Configuration sent.", Id);
        }
Example #23
0
        public Task DidChangeConfiguration(JToken token)
        {
            var settings = new LanguageServerSettings();

            var rootSection   = token["settings"];
            var pythonSection = rootSection?["python"];
            var autoComplete  = pythonSection?["autoComplete"];

            if (autoComplete != null)
            {
                var showAdvancedMembers = autoComplete["showAdvancedMembers"] as JValue;
                settings.SuppressAdvancedMembers = showAdvancedMembers == null ||
                                                   (showAdvancedMembers.Type == JTokenType.Boolean && !showAdvancedMembers.ToObject <bool>());
            }
            var p = new DidChangeConfigurationParams()
            {
                settings = settings
            };

            return(_server.DidChangeConfiguration(p));
        }
Example #24
0
        /// <summary>
        /// Handles the configuration change event
        /// </summary>
        internal async Task HandleDidChangeConfigurationNotification(
            DidChangeConfigurationParams <TConfig> configChangeParams,
            EventContext eventContext)
        {
            try
            {
                Logger.Instance.Write(LogLevel.Verbose, "HandleDidChangeConfigurationNotification");

                // Propagate the changes to the event handlers
                var configUpdateTasks = ConfigChangeCallbacks.Select(
                    t => t(configChangeParams.Settings, CurrentSettings, eventContext));
                await Task.WhenAll(configUpdateTasks);
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(LogLevel.Error, "Unknown error " + ex.ToString());
                // Swallow exceptions here to prevent us from crashing
                // TODO: this probably means the ScriptFile model is in a bad state or out of sync with the actual file; we should recover here
                return;
            }
        }
Example #25
0
 public abstract Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken);
        public override async Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken)
        {
            LanguageServerSettingsWrapper incomingSettings = request.Settings.ToObject <LanguageServerSettingsWrapper>();

            _logger.LogTrace("Handling DidChangeConfiguration");
            if (incomingSettings is null || incomingSettings.Powershell is null)
            {
                _logger.LogTrace("Incoming settings were null");
                return(await Unit.Task.ConfigureAwait(false));
            }

            SendFeatureChangesTelemetry(incomingSettings);

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

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

            // We need to load the profiles if:
            // - Profile loading is configured, AND
            //   - Profiles haven't been loaded before, OR
            //   - The profile loading configuration just changed
            bool loadProfiles = _configurationService.CurrentSettings.EnableProfileLoading &&
                                (!_profilesLoaded || !profileLoadingPreviouslyEnabled);

            if (!_psesHost.IsRunning)
            {
                _logger.LogTrace("Starting command loop");

                if (loadProfiles)
                {
                    _logger.LogTrace("Loading profiles...");
                }

                await _psesHost.TryStartAsync(new HostStartOptions { LoadProfiles = loadProfiles }, CancellationToken.None).ConfigureAwait(false);

                if (loadProfiles)
                {
                    _profilesLoaded = true;
                    _logger.LogTrace("Loaded!");
                }
            }

            // TODO: Load profiles when the host is already running
            if (!_cwdSet)
            {
                if (!string.IsNullOrEmpty(_configurationService.CurrentSettings.Cwd) &&
                    Directory.Exists(_configurationService.CurrentSettings.Cwd))
                {
                    _logger.LogTrace($"Setting CWD (from config) to {_configurationService.CurrentSettings.Cwd}");
                    await _psesHost.SetInitialWorkingDirectoryAsync(
                        _configurationService.CurrentSettings.Cwd,
                        CancellationToken.None).ConfigureAwait(false);
                }
                else if (_workspaceService.WorkspacePath is not null &&
                         Directory.Exists(_workspaceService.WorkspacePath))
                {
                    _logger.LogTrace($"Setting CWD (from workspace) to {_workspaceService.WorkspacePath}");
                    await _psesHost.SetInitialWorkingDirectoryAsync(
                        _workspaceService.WorkspacePath,
                        CancellationToken.None).ConfigureAwait(false);
                }
                else
                {
                    _logger.LogTrace("Tried to set CWD but in bad state");
                }

                _cwdSet = true;
            }
        }                                       // Does nothing

        public abstract Task DidChangeConfiguration(DidChangeConfigurationParams @params, CancellationToken cancellationToken);
Example #28
0
 public override Task <Unit> Handle(DidChangeConfigurationParams request, CancellationToken cancellationToken) => _handler.Invoke(request, cancellationToken);
        protected async Task HandleDidChangeConfigurationNotification(
            DidChangeConfigurationParams<SettingsWrapper> configChangeParams,
            EventContext eventContext)
        {
            bool oldScriptAnalysisEnabled =
                this.currentSettings.ScriptAnalysis.Enable.HasValue;

            this.currentSettings.Update(
                configChangeParams.Settings.Powershell);

            if (oldScriptAnalysisEnabled != this.currentSettings.ScriptAnalysis.Enable)
            {
                // If the user just turned off script analysis, send a diagnostics
                // event to clear the analysis markers that they already have
                if (!this.currentSettings.ScriptAnalysis.Enable.Value)
                {
                    ScriptFileMarker[] emptyAnalysisDiagnostics = new ScriptFileMarker[0];

                    foreach (var scriptFile in editorSession.Workspace.GetOpenedFiles())
                    {
                        await PublishScriptDiagnostics(
                            scriptFile,
                            emptyAnalysisDiagnostics,
                            eventContext);
                    }
                }
            }
        }
 public static void DidChangeConfiguration(this ILanguageClientWorkspace router, DidChangeConfigurationParams @params)
 {
     router.SendNotification(WorkspaceNames.DidChangeConfiguration, @params);
 }
 /// <summary>
 /// Request a configuration change notification
 /// </summary>
 public async Task RequestChangeConfigurationNotification(DidChangeConfigurationParams <SqlToolsSettings> configParams)
 {
     await Driver.SendEvent(DidChangeConfigurationNotification <SqlToolsSettings> .Type, configParams);
 }