Skip to content

Commit 641dc95

Browse files
committed
Change 'undeclared variable' diagnostic severity from warning to hint
1 parent 020aa75 commit 641dc95

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2121
- Language Server: `<<set>>` statements now offer variable names in their code completions.
2222
- Language Server: hovering smart variables now shows their definition.
2323
- Language Server: Make compilation asynchronous
24+
- Language Server: 'Undeclared variable' warnings have had their severity reduced to "hint".
2425

2526
### Removed
2627

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
using MoreLinq;
3+
using Newtonsoft.Json.Linq;
4+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Range = OmniSharp.Extensions.LanguageServer.Protocol.Models.Range;
8+
9+
namespace YarnLanguageServer.Diagnostics
10+
{
11+
internal static class Hints
12+
{
13+
public static IEnumerable<Diagnostic> GetHints(YarnFileData yarnFile, Configuration? configuration)
14+
{
15+
var results = Enumerable.Empty<Diagnostic>();
16+
17+
results = results.Concat(UndeclaredVariables(yarnFile));
18+
19+
return results;
20+
}
21+
private static IEnumerable<Diagnostic> UndeclaredVariables(YarnFileData yarnFile)
22+
{
23+
var project = yarnFile.Project;
24+
25+
if (project == null)
26+
{
27+
// No project, so no diagnostics we can produce
28+
return Enumerable.Empty<Diagnostic>();
29+
}
30+
31+
// Find all variable references in this file where the declaration,
32+
// if any, is an implicit one. If it is, then we should suggest that
33+
// the user create a declaration for it.
34+
var undeclaredVariables = yarnFile.VariableReferences
35+
.Where(@ref => project.FindVariables(@ref.Text)
36+
.FirstOrDefault()?
37+
.IsImplicit ?? false
38+
);
39+
40+
return undeclaredVariables.Select(v => new Diagnostic
41+
{
42+
Message = "Variable should be declared",
43+
Severity = DiagnosticSeverity.Hint,
44+
Range = PositionHelper.GetRange(yarnFile.LineStarts, v),
45+
Code = nameof(YarnDiagnosticCode.YRNMsngVarDec),
46+
Data = JToken.FromObject(v.Text),
47+
});
48+
}
49+
}
50+
}

YarnSpinner.LanguageServer/src/Server/Diagnostics/Warnings.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public static IEnumerable<Diagnostic> GetWarnings(YarnFileData yarnFile, Configu
1515

1616
results = results.Concat(UnknownCommands(yarnFile));
1717
results = results.Concat(UndefinedFunctions(yarnFile, configuration));
18-
results = results.Concat(UndeclaredVariables(yarnFile));
1918
results = results.Concat(UndefinedJumpDestination(yarnFile));
2019

2120
return results;
@@ -82,34 +81,7 @@ private static IEnumerable<Diagnostic> UndefinedFunctions(YarnFileData yarnFile,
8281
}
8382
}
8483

85-
private static IEnumerable<Diagnostic> UndeclaredVariables(YarnFileData yarnFile)
86-
{
87-
var project = yarnFile.Project;
88-
89-
if (project == null)
90-
{
91-
// No project, so no diagnostics we can produce
92-
return Enumerable.Empty<Diagnostic>();
93-
}
94-
95-
// Find all variable references in this file where the declaration,
96-
// if any, is an implicit one. If it is, then we should suggest that
97-
// the user create a declaration for it.
98-
var undeclaredVariables = yarnFile.VariableReferences
99-
.Where(@ref => project.FindVariables(@ref.Text)
100-
.FirstOrDefault()?
101-
.IsImplicit ?? false
102-
);
10384

104-
return undeclaredVariables.Select(v => new Diagnostic
105-
{
106-
Message = "Variable should be declared",
107-
Severity = DiagnosticSeverity.Warning,
108-
Range = PositionHelper.GetRange(yarnFile.LineStarts, v),
109-
Code = nameof(YarnDiagnosticCode.YRNMsngVarDec),
110-
Data = JToken.FromObject(v.Text),
111-
});
112-
}
11385

11486
private static IEnumerable<Diagnostic> UndefinedJumpDestination(YarnFileData yarnFile)
11587
{

YarnSpinner.LanguageServer/src/Server/Workspace/Workspace.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ internal Dictionary<Uri, IEnumerable<Diagnostic>> GetDiagnostics()
316316
// Add warnings for this file
317317
diags = diags.Concat(Warnings.GetWarnings(file, this.Configuration));
318318

319+
// Add hints for this file
320+
diags = diags.Concat(Hints.GetHints(file, this.Configuration));
321+
319322
// Add the resulting list to the dictionary.
320323
result[uri] = diags;
321324
}

0 commit comments

Comments
 (0)