Updated Upsilon library, support for warnings

This commit is contained in:
Deukhoofd 2018-11-28 16:56:07 +01:00
parent 34751d9edc
commit b1b863d5a3
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
4 changed files with 33 additions and 9 deletions

View File

@ -50,9 +50,9 @@ namespace UpsilonLanguageServer
using (var script = Executor.ParseInput(content, Options)) using (var script = Executor.ParseInput(content, Options))
{ {
session.SourceText = script.ScriptString; session.SourceText = script.ScriptString;
if (script.Diagnostics.Messages.Count > 0) if (script.Diagnostics.Errors.Count > 0)
{ {
foreach (var error in script.Diagnostics.Messages) foreach (var error in script.Diagnostics.Errors)
{ {
diag.Add(ConvertToVsCodeDiagnostic(error)); diag.Add(ConvertToVsCodeDiagnostic(error));
} }
@ -61,12 +61,16 @@ namespace UpsilonLanguageServer
} }
var bound = script.Bind(); var bound = script.Bind();
foreach (var error in script.Diagnostics.Messages) foreach (var error in script.Diagnostics.Errors)
{ {
diag.Add(ConvertToVsCodeDiagnostic(error)); diag.Add(ConvertToVsCodeDiagnostic(error));
} }
foreach (var warning in script.Diagnostics.Warnings)
{
diag.Add(ConvertToVsCodeDiagnostic(warning));
}
if (script.Diagnostics.Messages.Count == 0) if (script.Diagnostics.Errors.Count == 0)
{ {
session.Bound = bound; session.Bound = bound;
} }
@ -80,17 +84,32 @@ namespace UpsilonLanguageServer
} }
} }
private static Diagnostic ConvertToVsCodeDiagnostic(DiagnosticsMessage error) private static Diagnostic ConvertToVsCodeDiagnostic(DiagnosticsMessage message)
{ {
var (startPosition, startPositionOnLine) = error.GetStartLine(); var (startPosition, startPositionOnLine) = message.GetStartLine();
var (endPosition, endPositionOnLine) = error.GetEndLine(); var (endPosition, endPositionOnLine) = message.GetEndLine();
var sourceString = error.Diagnostics.ScriptString; var sourceString = message.Diagnostics.ScriptString;
if (endPosition >= sourceString.GetLineCount()) if (endPosition >= sourceString.GetLineCount())
endPosition = sourceString.GetLineCount(); endPosition = sourceString.GetLineCount();
var range = new Range(startPosition, startPositionOnLine, endPosition, var range = new Range(startPosition, startPositionOnLine, endPosition,
endPositionOnLine); endPositionOnLine);
return new Diagnostic(DiagnosticSeverity.Error, range, error.AtError(), "ERR001", error.Message);
DiagnosticSeverity severity;
switch (message.DiagnosticLevel)
{
case DiagnosticLevel.Error:
severity = DiagnosticSeverity.Error;
break;
case DiagnosticLevel.Warning:
severity = DiagnosticSeverity.Warning;
break;
default:
severity = DiagnosticSeverity.Information;
break;
}
return new Diagnostic(severity, range, message.AtError(), "ERR001", message.Message);
} }
} }
} }

View File

@ -41,6 +41,11 @@ namespace UpsilonLanguageServer.Services
{ {
contents.Append($"\n\n{string.Join(" \n", varSymbol.VariableSymbol.CommentValue)}"); contents.Append($"\n\n{string.Join(" \n", varSymbol.VariableSymbol.CommentValue)}");
} }
if (varSymbol.VariableSymbol is FunctionVariableSymbol fVar)
{
contents.Append($"\n\nReturns: {fVar.ResultType}");
}
} }
return new Hover() return new Hover()