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

Commit e501c64

Browse files
Handle enableUnresolvedImportWarning and enableUseBeforeDefWarning options in PLS
1 parent efc669a commit e501c64

File tree

7 files changed

+40
-15
lines changed

7 files changed

+40
-15
lines changed

src/Analysis/Engine/Impl/Definitions/Diagnostic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class Diagnostic {
4848
}
4949

5050
public enum DiagnosticSeverity : int {
51-
Unspecified = 0,
51+
Suppressed = 0,
5252
Error = 1,
5353
Warning = 2,
5454
Information = 3,

src/Analysis/Engine/Test/LanguageServerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public async Task ParseIndentationDiagnostics() {
298298
DiagnosticSeverity.Error,
299299
DiagnosticSeverity.Warning,
300300
DiagnosticSeverity.Information,
301-
DiagnosticSeverity.Unspecified
301+
DiagnosticSeverity.Suppressed
302302
}) {
303303
// For now, these options have to be configured directly
304304
s.ParseQueue.InconsistentIndentation = tc;
@@ -317,7 +317,7 @@ await s.DidChangeTextDocument(new DidChangeTextDocumentParams {
317317
await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
318318

319319
var messages = GetDiagnostics(diags, mod).ToArray();
320-
if (tc == DiagnosticSeverity.Unspecified) {
320+
if (tc == DiagnosticSeverity.Suppressed) {
321321
messages.Should().BeEmpty();
322322
} else {
323323
messages.Should().OnlyContain($"{tc};inconsistent whitespace;Python;2;0;1");
@@ -359,7 +359,7 @@ public async Task DiagnosticsSettingChange() {
359359
await s.SendDidChangeConfiguration(newSettings);
360360

361361
await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
362-
GetDiagnostics(diags, u).Where(st => !st.StartsWith($"{DiagnosticSeverity.Unspecified}")).Should().BeEmpty();
362+
GetDiagnostics(diags, u).Where(st => !st.StartsWith($"{DiagnosticSeverity.Suppressed}")).Should().BeEmpty();
363363
}
364364
}
365365

src/LanguageServer/Core/Impl/Definitions/ServerSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void SetErrorSeverityOptions(string[] errors, string[] warnings, string[]
4848
_map[x] = DiagnosticSeverity.Error;
4949
}
5050
foreach (var x in disabled) {
51-
_map[x] = DiagnosticSeverity.Unspecified;
51+
_map[x] = DiagnosticSeverity.Suppressed;
5252
}
5353

5454
this.errors = errors;

src/LanguageServer/Core/Impl/Implementation/DiagnosticsErrorSink.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,18 @@ public void ProcessTaskComment(object sender, CommentEventArgs e) {
7272

7373
internal static DiagnosticSeverity GetSeverity(Severity severity) {
7474
switch (severity) {
75-
case Severity.Ignore: return DiagnosticSeverity.Unspecified;
75+
case Severity.Ignore: return DiagnosticSeverity.Suppressed;
7676
case Severity.Information: return DiagnosticSeverity.Information;
7777
case Severity.Warning: return DiagnosticSeverity.Warning;
7878
case Severity.Error: return DiagnosticSeverity.Error;
7979
case Severity.FatalError: return DiagnosticSeverity.Error;
80-
default: return DiagnosticSeverity.Unspecified;
80+
default: return DiagnosticSeverity.Suppressed;
8181
}
8282
}
8383

8484
internal static Severity GetSeverity(DiagnosticSeverity severity) {
8585
switch (severity) {
86-
case DiagnosticSeverity.Unspecified: return Severity.Ignore;
86+
case DiagnosticSeverity.Suppressed: return Severity.Ignore;
8787
case DiagnosticSeverity.Information: return Severity.Information;
8888
case DiagnosticSeverity.Warning: return Severity.Warning;
8989
case DiagnosticSeverity.Error: return Severity.Error;

src/LanguageServer/Impl/LanguageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ private void PublishPendingDiagnostics() {
423423
foreach (var kvp in list) {
424424
var parameters = new PublishDiagnosticsParams {
425425
uri = kvp.Key,
426-
diagnostics = kvp.Value.Where(d => d.severity != DiagnosticSeverity.Unspecified).ToArray()
426+
diagnostics = kvp.Value.Where(d => d.severity != DiagnosticSeverity.Suppressed).ToArray()
427427
};
428428
_rpc.NotifyWithParameterObjectAsync("textDocument/publishDiagnostics", parameters).DoNotWait();
429429
}

src/PTVS/Microsoft.PythonTools.Analyzer/Impl/Intellisense/AnalysisProtocol.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public sealed class InitializeRequest : Request<InitializeResponse> {
5959
public bool analyzeAllFiles;
6060
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
6161
public bool traceLogging;
62-
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
63-
public bool liveLinting;
6462
}
6563

6664
public sealed class InterpreterInfo {
@@ -824,6 +822,8 @@ public sealed class SetAnalysisOptionsRequest : Request<Response> {
824822

825823
public sealed class AnalysisOptions {
826824
public Severity indentationInconsistencySeverity;
825+
public bool enableUnresolvedImportWarning;
826+
public bool enableUseBeforeDefWarning;
827827
public Dictionary<string, DiagnosticSeverity> commentTokens;
828828
public Dictionary<string, int> analysisLimits;
829829
public LS.MessageType? traceLevel;

src/PTVS/Microsoft.PythonTools.Analyzer/Impl/Intellisense/OutOfProcProjectAnalyzer.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ await _server.Initialize(new LS.InitializeParams {
269269
},
270270
capabilities = new LS.ClientCapabilities {
271271
python = new LS.PythonClientCapabilities {
272-
manualFileLoad = !request.analyzeAllFiles,
273-
liveLinting = request.liveLinting
272+
manualFileLoad = !request.analyzeAllFiles
274273
},
275274
textDocument = new LS.TextDocumentClientCapabilities {
276275
completion = new LS.TextDocumentClientCapabilities.CompletionCapabilities {
@@ -1559,9 +1558,35 @@ private Response SetAnalysisOptions(AP.SetAnalysisOptionsRequest request) {
15591558
_server.ParseQueue.TaskCommentMap = Options.commentTokens;
15601559
_server.Analyzer.SetTypeStubPaths(Options.typeStubPaths ?? Enumerable.Empty<string>());
15611560

1561+
SetErrorMessagesSeverity();
1562+
15621563
return new Response();
15631564
}
15641565

1566+
private void SetErrorMessagesSeverity() {
1567+
var serverSettings = new LS.ServerSettings();
1568+
var warnings = new List<string>();
1569+
var disabled = new List<string>();
1570+
1571+
if (Options.enableUnresolvedImportWarning) {
1572+
warnings.Add(ErrorMessages.UnresolvedImportCode);
1573+
} else {
1574+
disabled.Add(ErrorMessages.UnresolvedImportCode);
1575+
}
1576+
1577+
if (Options.enableUseBeforeDefWarning) {
1578+
warnings.Add(ErrorMessages.UseBeforeDefCode);
1579+
} else {
1580+
disabled.Add(ErrorMessages.UseBeforeDefCode);
1581+
}
1582+
1583+
serverSettings.analysis.SetErrorSeverityOptions(Array.Empty<string>(), warnings.ToArray(), Array.Empty<string>(), disabled.ToArray());
1584+
1585+
_server.DidChangeConfiguration(new LS.DidChangeConfigurationParams {
1586+
settings = serverSettings
1587+
}, CancellationToken.None).DoNotWait();
1588+
}
1589+
15651590

15661591
public AP.AnalysisOptions Options { get; set; }
15671592

@@ -1570,7 +1595,7 @@ private void AnalysisQueue_Complete(object sender, EventArgs e) {
15701595
}
15711596

15721597
private void OnModulesChanged(object sender, EventArgs args) {
1573-
_server.DidChangeConfiguration(new LS.DidChangeConfigurationParams(), CancellationToken.None).DoNotWait();
1598+
_server.ReloadModulesAsync(CancellationToken.None).DoNotWait();
15741599
}
15751600

15761601
private void OnFileChanged(AP.FileChangedEvent e) {
@@ -1653,7 +1678,7 @@ private void OnPublishDiagnostics(object sender, LS.PublishDiagnosticsEventArgs
16531678
new AP.DiagnosticsEvent {
16541679
documentUri = e.uri,
16551680
version = e._version ?? -1,
1656-
diagnostics = e.diagnostics?.ToArray()
1681+
diagnostics = e.diagnostics?.Where(d => d.severity != DiagnosticSeverity.Suppressed).ToArray()
16571682
}
16581683
).DoNotWait();
16591684
}

0 commit comments

Comments
 (0)