XFEExtension.NetCore.ServerInteractive
[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig
关注
0
Fork
0
Star
0
返回提交历史
Added
XFEExtension.NetCore.ServerInteractive.SourceGenerator/AnalyzerReleases.Shipped.md
+3
-0
Added
XFEExtension.NetCore.ServerInteractive.SourceGenerator/AnalyzerReleases.Unshipped.md
+11
-0
Modified
XFEExtension.NetCore.ServerInteractive.SourceGenerator/EntryPointGenerator.cs
+6
-72
Added
XFEExtension.NetCore.ServerInteractive.SourceGenerator/Models/LocationInfo.cs
+28
-0
Added
XFEExtension.NetCore.ServerInteractive.SourceGenerator/Models/MethodCandidate.cs
+25
-0
XFEstudio/XFEExtension.NetCore.ServerInteractive
优化源生成器内容
ec52189
代码差异
5 个文件
+73
-72
@@ -0,0 +1,3 @@
1
; Shipped analyzer releases
2
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3
@@ -0,0 +1,11 @@
1
; Unshipped analyzer release
2
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3
4
### New Rules
5
6
Rule ID | Category | Severity | Notes
7
--------|----------|----------|-------
8
XFE0003 | XFEServerInteractive | Error | EntryPointGenerator, [Documentation](https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0003)
9
XFE0004 | XFEServerInteractive | Error | EntryPointGenerator, [Documentation](https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0004)
10
XFE0005 | XFEServerInteractive | Error | EntryPointGenerator, [Documentation](https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0005)
11
XFE0006 | XFEServerInteractive | Error | EntryPointGenerator, [Documentation](https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0006)
@@ -6,6 +6,7 @@ using System.Collections.Generic;
6
6
using System.Collections.Immutable;
7
7
using System.Linq;
8
8
using System.Text;
9
using XFEExtension.NetCore.ServerInteractive.SourceGenerator.Models;
9
10
10
11
namespace XFEExtension.NetCore.ServerInteractive.SourceGenerator;
11
12
@@ -22,7 +23,7 @@ public class EntryPointGenerator : IIncrementalGenerator
22
23
messageFormat: "类'{0}'必须声明为partial以便增量生成器可以生成入口点代码",
23
24
category: "XFEServerInteractive",
24
25
defaultSeverity: DiagnosticSeverity.Error,
25
helpLinkUri: "",
26
helpLinkUri: "https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0003",
26
27
isEnabledByDefault: true);
27
28
28
29
private static readonly DiagnosticDescriptor MethodMustBeParameterlessRule = new(
@@ -31,6 +32,7 @@ public class EntryPointGenerator : IIncrementalGenerator
31
32
messageFormat: "方法'{0}'标记了[EntryPoint]但包含参数,入口点方法必须是无参数的",
32
33
category: "XFEServerInteractive",
33
34
defaultSeverity: DiagnosticSeverity.Error,
35
helpLinkUri: "https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0004",
34
36
isEnabledByDefault: true);
35
37
36
38
private static readonly DiagnosticDescriptor InvalidReturnTypeRule = new(
@@ -39,6 +41,7 @@ public class EntryPointGenerator : IIncrementalGenerator
39
41
messageFormat: "方法'{0}'的返回类型'{1}'无效,入口点方法必须返回void或Task",
40
42
category: "XFEServerInteractive",
41
43
defaultSeverity: DiagnosticSeverity.Error,
44
helpLinkUri: "https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0005",
42
45
isEnabledByDefault: true);
43
46
44
47
private static readonly DiagnosticDescriptor InvalidPathCharactersRule = new(
@@ -47,6 +50,7 @@ public class EntryPointGenerator : IIncrementalGenerator
47
50
messageFormat: "入口点路径'{0}'包含无效字符(引号或反斜杠),这些字符不允许在路径中使用",
48
51
category: "XFEServerInteractive",
49
52
defaultSeverity: DiagnosticSeverity.Error,
53
helpLinkUri: "https://docs.xfegzs.com/View/Errors%2FServerInteractive%2FXFE0006",
50
54
isEnabledByDefault: true);
51
55
52
56
public void Initialize(IncrementalGeneratorInitializationContext context)
@@ -63,7 +67,7 @@ public class EntryPointGenerator : IIncrementalGenerator
63
67
64
68
// 生成源代码
65
69
context.RegisterSourceOutput(compilationAndMethods,
66
static (spc, source) => Execute(source.Left, source.Right!, spc));
70
static (spc, source) => Execute(source.Left, source.Right, spc));
67
71
}
68
72
69
73
private static bool IsCandidateMethod(SyntaxNode node) => node is MethodDeclarationSyntax { AttributeLists.Count: > 0 };
@@ -276,74 +280,4 @@ namespace {namespaceName}
276
280
{
277
281
return value.Replace("\\", "\\\\").Replace("\"", "\\\"");
278
282
}
279
280
/// <summary>
281
/// 轻量级位置信息,避免在增量生成器缓存中持有SyntaxTree引用
282
/// </summary>
283
private readonly struct LocationInfo
284
{
285
public string FilePath { get; }
286
public TextSpan TextSpan { get; }
287
public LinePositionSpan LineSpan { get; }
288
289
private LocationInfo(string filePath, TextSpan textSpan, LinePositionSpan lineSpan)
290
{
291
FilePath = filePath;
292
TextSpan = textSpan;
293
LineSpan = lineSpan;
294
}
295
296
public static LocationInfo From(Location location)
297
{
298
var mappedSpan = location.GetMappedLineSpan();
299
return new LocationInfo(
300
mappedSpan.Path ?? "",
301
location.SourceSpan,
302
mappedSpan.Span);
303
}
304
305
public Location ToLocation()
306
{
307
return Location.Create(FilePath, TextSpan, LineSpan);
308
}
309
}
310
311
/// <summary>
312
/// 方法候选信息,包含验证所需的所有数据
313
/// </summary>
314
private class MethodCandidate
315
{
316
public string Namespace { get; }
317
public string ClassName { get; }
318
public string MethodName { get; }
319
public string Path { get; }
320
public bool IsAsync { get; }
321
public bool IsContainingTypePartial { get; }
322
public int ParameterCount { get; }
323
public bool HasValidReturnType { get; }
324
public string ReturnTypeName { get; }
325
public LocationInfo MethodLocation { get; }
326
public LocationInfo ClassLocation { get; }
327
public string TypeParameters { get; }
328
public string TypeConstraints { get; }
329
330
public MethodCandidate(string namespaceName, string className, string methodName, string path, bool isAsync,
331
bool isContainingTypePartial, int parameterCount, bool hasValidReturnType, string returnTypeName,
332
LocationInfo methodLocation, LocationInfo classLocation, string typeParameters, string typeConstraints)
333
{
334
Namespace = namespaceName;
335
ClassName = className;
336
MethodName = methodName;
337
Path = path;
338
IsAsync = isAsync;
339
IsContainingTypePartial = isContainingTypePartial;
340
ParameterCount = parameterCount;
341
HasValidReturnType = hasValidReturnType;
342
ReturnTypeName = returnTypeName;
343
MethodLocation = methodLocation;
344
ClassLocation = classLocation;
345
TypeParameters = typeParameters;
346
TypeConstraints = typeConstraints;
347
}
348
}
349
283
}
@@ -0,0 +1,28 @@
1
using Microsoft.CodeAnalysis;
2
using Microsoft.CodeAnalysis.Text;
3
4
namespace XFEExtension.NetCore.ServerInteractive.SourceGenerator.Models;
5
6
/// <summary>
7
/// 轻量级位置信息,避免在增量生成器缓存中持有SyntaxTree引用
8
/// </summary>
9
public readonly struct LocationInfo(string filePath, TextSpan textSpan, LinePositionSpan lineSpan)
10
{
11
public string FilePath { get; } = filePath;
12
public TextSpan TextSpan { get; } = textSpan;
13
public LinePositionSpan LineSpan { get; } = lineSpan;
14
15
public static LocationInfo From(Location location)
16
{
17
var mappedSpan = location.GetMappedLineSpan();
18
return new LocationInfo(
19
mappedSpan.Path,
20
location.SourceSpan,
21
mappedSpan.Span);
22
}
23
24
public Location ToLocation()
25
{
26
return Location.Create(FilePath, TextSpan, LineSpan);
27
}
28
}
@@ -0,0 +1,25 @@
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
5
namespace XFEExtension.NetCore.ServerInteractive.SourceGenerator.Models;
6
7
/// <summary>
8
/// 方法候选信息,包含验证所需的所有数据
9
/// </summary>
10
public class MethodCandidate(string namespaceName, string className, string methodName, string path, bool isAsync, bool isContainingTypePartial, int parameterCount, bool hasValidReturnType, string returnTypeName, LocationInfo methodLocation, LocationInfo classLocation, string typeParameters, string typeConstraints)
11
{
12
public string Namespace { get; } = namespaceName;
13
public string ClassName { get; } = className;
14
public string MethodName { get; } = methodName;
15
public string Path { get; } = path;
16
public bool IsAsync { get; } = isAsync;
17
public bool IsContainingTypePartial { get; } = isContainingTypePartial;
18
public int ParameterCount { get; } = parameterCount;
19
public bool HasValidReturnType { get; } = hasValidReturnType;
20
public string ReturnTypeName { get; } = returnTypeName;
21
public LocationInfo MethodLocation { get; } = methodLocation;
22
public LocationInfo ClassLocation { get; } = classLocation;
23
public string TypeParameters { get; } = typeParameters;
24
public string TypeConstraints { get; } = typeConstraints;
25
}