Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit 2b58358

Browse files
author
Mikhail Arkhipov
authored
Wire up restart of analysis on changes in configuration (#684)
* Wire up config changes * Fix error * Log null settings
1 parent 5421d08 commit 2b58358

File tree

9 files changed

+45
-39
lines changed

9 files changed

+45
-39
lines changed

src/Analysis/Ast/Impl/Analyzer/Symbols/FunctionEvaluator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ private void DeclareParameters(bool declareVariables) {
149149

150150
// Declare parameters in scope
151151
IMember defaultValue = null;
152-
var meaningfuleDefautValue = false;
153152
for (var i = skip; i < FunctionDefinition.Parameters.Length; i++) {
154153
var isGeneric = false;
155154
var p = FunctionDefinition.Parameters[i];

src/Analysis/Ast/Test/Microsoft.Python.Analysis.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<None Remove="app.config" />
2424
</ItemGroup>
2525
<ItemGroup>
26-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
26+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
2727
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
2828
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
2929
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />

src/Core/Test/Microsoft.Python.Core.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
<None Remove="app.config" />
2828
</ItemGroup>
2929
<ItemGroup>
30-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
30+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
3131
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
32-
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
33-
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
32+
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
33+
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
3434
<PackageReference Include="MicroBuild.Core" Version="0.3.0">
3535
<PrivateAssets>all</PrivateAssets>
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

src/LanguageServer/Impl/Implementation/Server.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,18 @@ public Task Shutdown() {
154154
return Task.CompletedTask;
155155
}
156156

157-
public async Task DidChangeConfiguration(DidChangeConfigurationParams @params, CancellationToken cancellationToken) {
157+
public void DidChangeConfiguration(DidChangeConfigurationParams @params, CancellationToken cancellationToken) {
158158
_disposableBag.ThrowIfDisposed();
159-
160-
var reanalyze = true;
161-
if (@params.settings != null) {
162-
if (@params.settings is ServerSettings settings) {
163-
reanalyze = HandleConfigurationChanges(settings);
164-
} else {
165-
_log?.Log(TraceEventType.Error, "change configuration notification sent unsupported settings");
166-
return;
159+
switch (@params.settings) {
160+
case ServerSettings settings: {
161+
if (HandleConfigurationChanges(settings)) {
162+
RestartAnalysis();
163+
}
164+
break;
167165
}
166+
default:
167+
_log?.Log(TraceEventType.Error, "change configuration notification sent unsupported settings");
168+
break;
168169
}
169170
}
170171
#endregion
@@ -198,5 +199,25 @@ private bool HandleConfigurationChanges(ServerSettings newSettings) {
198199
return false;
199200
}
200201
#endregion
202+
203+
public void NotifyPackagesChanged(CancellationToken cancellationToken) {
204+
var interpreter = _services.GetService<IPythonInterpreter>();
205+
_log?.Log(TraceEventType.Information, Resources.ReloadingModules);
206+
// No need to reload typeshed resolution since it is a static storage.
207+
// User does can add stubs while application is running, but it is
208+
// by design at this time that the app should be restarted.
209+
interpreter.ModuleResolution.ReloadAsync(cancellationToken).ContinueWith(t => {
210+
_log?.Log(TraceEventType.Information, Resources.Done);
211+
_log?.Log(TraceEventType.Information, Resources.RestartingAnalysis);
212+
RestartAnalysis();
213+
}, cancellationToken).DoNotWait();
214+
215+
}
216+
217+
private void RestartAnalysis() {
218+
foreach (var doc in _rdt) {
219+
doc.Reset(null);
220+
}
221+
}
201222
}
202223
}

src/LanguageServer/Impl/LanguageServer.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
using System;
1818
using System.Collections.Generic;
1919
using System.Diagnostics;
20-
using System.Linq;
2120
using System.Threading;
2221
using System.Threading.Tasks;
2322
using Microsoft.Python.Analysis;
2423
using Microsoft.Python.Analysis.Diagnostics;
2524
using Microsoft.Python.Analysis.Documents;
26-
using Microsoft.Python.Analysis.Modules;
2725
using Microsoft.Python.Core;
2826
using Microsoft.Python.Core.Disposables;
2927
using Microsoft.Python.Core.Idle;
@@ -126,7 +124,7 @@ public async Task DidChangeConfiguration(JToken token, CancellationToken cancell
126124
GetSetting(analysis, "information", Array.Empty<string>()),
127125
GetSetting(analysis, "disabled", Array.Empty<string>()));
128126

129-
await _server.DidChangeConfiguration(new DidChangeConfigurationParams { settings = settings }, cancellationToken);
127+
_server.DidChangeConfiguration(new DidChangeConfigurationParams { settings = settings }, cancellationToken);
130128
}
131129
}
132130

@@ -383,27 +381,15 @@ private void HandlePathWatchChange(JToken section, CancellationToken cancellatio
383381
var logger = _services.GetService<ILogger>();
384382
_pathsWatcher = new PathsWatcher(
385383
_initParams.initializationOptions.searchPaths,
386-
() => {
387-
logger.Log(TraceEventType.Information, Resources.ReloadingModules);
388-
// No need to reload typeshed resolution since it is a static storage.
389-
// User does can add stubs while application is running, but it is
390-
// by design at this time that the app should be restarted.
391-
interpreter.ModuleResolution.ReloadAsync(cancellationToken).ContinueWith(t => {
392-
logger.Log(TraceEventType.Information, Resources.Done);
393-
logger.Log(TraceEventType.Information, Resources.RestartingAnalysis);
394-
var rdt = _services.GetService<IRunningDocumentTable>();
395-
foreach (var doc in rdt) {
396-
doc.Reset(null);
397-
}
398-
}, cancellationToken).DoNotWait();
399-
},
384+
() =>_server.NotifyPackagesChanged(cancellationToken),
400385
_services.GetService<ILogger>()
401386
);
402387

403388
_watchSearchPaths = true;
404389
_searchPaths = _initParams.initializationOptions.searchPaths;
405390
}
406391
}
392+
407393
private static CancellationToken GetToken(CancellationToken original)
408394
=> Debugger.IsAttached ? CancellationToken.None : original;
409395

src/LanguageServer/Impl/Microsoft.Python.LanguageServer.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
3131
</PackageReference>
3232
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="2.2.0" />
33-
<PackageReference Include="NewtonSoft.Json" Version="11.0.2" />
34-
<PackageReference Include="StreamJsonRpc" Version="2.0.102-beta" />
33+
<PackageReference Include="NewtonSoft.Json" Version="12.0.1" />
34+
<PackageReference Include="StreamJsonRpc" Version="2.0.146" />
3535
</ItemGroup>
3636
<ItemGroup Condition="$(AnalysisReference) != ''">
3737
<Reference Include="Microsoft.Python.Analysis.Engine">

src/LanguageServer/Test/Microsoft.Python.LanguageServer.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<None Remove="app.config" />
2424
</ItemGroup>
2525
<ItemGroup>
26-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
26+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
2727
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
2828
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
2929
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />

src/Parsing/Test/Microsoft.Python.Parsing.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
<None Remove="app.config" />
2828
</ItemGroup>
2929
<ItemGroup>
30-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
30+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
3131
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
32-
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
33-
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
32+
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
33+
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
3434
<PackageReference Include="MicroBuild.Core" Version="0.3.0">
3535
<PrivateAssets>all</PrivateAssets>
3636
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

src/UnitTests/Core/Impl/UnitTests.Core.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<Import Project="..\..\..\..\build\NetStandard.settings" />
88
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
99
<ItemGroup>
10-
<PackageReference Include="FluentAssertions" Version="5.4.1" />
11-
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
10+
<PackageReference Include="FluentAssertions" Version="5.4.0" />
11+
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
1212
<PackageReference Include="MicroBuild.Core" Version="0.3.0">
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

0 commit comments

Comments
 (0)