feat(adminui): script document formatting (NormalizeWhitespace)
This commit is contained in:
@@ -325,6 +325,21 @@ public sealed class ScriptAnalysisService
|
||||
}
|
||||
catch (Exception ex) { _logger?.LogWarning(ex, "Script signature help failed."); return empty; }
|
||||
}
|
||||
public FormatResponse Format(FormatRequest req) => new(req.Code); // Task 8
|
||||
public FormatResponse Format(FormatRequest req) // Task 8
|
||||
{
|
||||
if (string.IsNullOrEmpty(req.Code)) return new FormatResponse(req.Code);
|
||||
try
|
||||
{
|
||||
var code = Normalize(req.Code);
|
||||
var tree = CSharpSyntaxTree.ParseText(code,
|
||||
new CSharpParseOptions(LanguageVersion.Latest, kind: SourceCodeKind.Script));
|
||||
var formatted = tree.GetRoot().NormalizeWhitespace(indentation: " ", eol: "\n").ToFullString();
|
||||
return new FormatResponse(formatted);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new FormatResponse(req.Code);
|
||||
}
|
||||
}
|
||||
public InlayHintsResponse InlayHints(InlayHintsRequest req) => new(Array.Empty<InlayHint>()); // Task 8 (stays empty)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user