File: Program.cs

package info (click to toggle)
node-playwright 1.38.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,728 kB
  • sloc: javascript: 114,018; sh: 899; java: 372; xml: 247; cs: 118; python: 29; makefile: 12
file content (43 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

var codeSnippetsPath = args[args.Length - 1];
var codeSnippets = JsonSerializer.Deserialize<List<CodeSnippet>>(File.ReadAllText(codeSnippetsPath));
if (codeSnippets == null)
{
    Console.WriteLine("Error: codeSnippets is null");
    return;
}
var output = new List<object>();

foreach (var codeSnippet in codeSnippets)
{
    var tree = CSharpSyntaxTree.ParseText(codeSnippet.code);
    var syntaxErrors = tree.GetDiagnostics()
        .Where(diag => diag.Severity == DiagnosticSeverity.Error)
        .ToList();
    if (syntaxErrors.Any())
    {
        output.Add(new
        {
            status = "error",
            error = string.Join("\n", syntaxErrors.Select(diag => diag.GetMessage()))
        });
    }
    else
    {
        output.Add(new
        {
            status = "ok"
        });
    }
}

Console.WriteLine(JsonSerializer.Serialize(output));

record CodeSnippet(string filePath, string codeLang, string code);