22using EmmyLua . CodeAnalysis . Compilation . Declaration ;
33using EmmyLua . CodeAnalysis . Compilation . Infer ;
44using EmmyLua . CodeAnalysis . Compilation . Search ;
5- using EmmyLua . CodeAnalysis . Compilation . Semantic . Render ;
6- using EmmyLua . CodeAnalysis . Compilation . Semantic . Render . Renderer ;
5+ // using EmmyLua.CodeAnalysis.Compilation.Semantic.Render;
6+ // using EmmyLua.CodeAnalysis.Compilation.Semantic.Render.Renderer;
77using EmmyLua . CodeAnalysis . Document ;
88using EmmyLua . CodeAnalysis . Syntax . Node . SyntaxNodes ;
99using EmmyLua . CodeAnalysis . Workspace . Module ;
1010
1111namespace EmmyLua . Cli . DocGenerator . Markdown ;
1212
13- public class ModuleDoc
14- {
15- private SearchContext SearchContext { get ; }
16-
17- private LuaRenderContext RenderContext { get ; }
18-
19- private LuaRenderBuilder RenderBuilder { get ; }
20-
21- private ModuleIndex ModuleIndex { get ; }
22-
23- private LuaRenderFeature Feature { get ; } = new LuaRenderFeature ( )
24- {
25- ShowTypeLink = false ,
26- ExpandAlias = false ,
27- } ;
28-
29- public ModuleDoc ( LuaCompilation compilation , ModuleIndex moduleIndex )
30- {
31- SearchContext = new SearchContext ( compilation , new SearchContextFeatures ( ) ) ;
32- RenderBuilder = new LuaRenderBuilder ( SearchContext ) ;
33- ModuleIndex = moduleIndex ;
34- RenderContext = new LuaRenderContext ( SearchContext , Feature ) ;
35- }
36-
37- public string Build ( )
38- {
39- RenderContext . AddH1Title ( $ "module { ModuleIndex . ModulePath } ") ;
40- var document = SearchContext . Compilation . Workspace . GetDocument ( ModuleIndex . DocumentId ) ;
41- if ( document is null )
42- {
43- return RenderContext . GetText ( ) ;
44- }
45-
46- RenderModuleDescription ( document ) ;
47- RenderContext . AppendLine ( ) ;
48-
49- RenderContext . AddH2Title ( "Public members:" ) ;
50- RenderContext . AddSeparator ( ) ;
51- RenderModuleMembers ( document ) ;
52-
53- return RenderContext . GetText ( ) ;
54- }
55-
56- private void RenderModuleDescription ( LuaDocument document )
57- {
58- RenderContext . Append ( RenderBuilder . RenderModule ( document , Feature ) ) ;
59- }
60-
61- private IEnumerable < LuaFuncStatSyntax > GetModuleStats ( LuaDocument document )
62- {
63- if ( document . SyntaxTree . SyntaxRoot . Block is { StatList : { } statList } )
64- {
65- foreach ( var funcStat in statList . OfType < LuaFuncStatSyntax > ( ) )
66- {
67- yield return funcStat ;
68- }
69- }
70- }
71-
72- private void RenderModuleMembers ( LuaDocument document )
73- {
74- foreach ( var funcStat in GetModuleStats ( document ) )
75- {
76- if ( funcStat is { NameElement . Parent : { } node } )
77- {
78- var declaration = SearchContext . FindDeclaration ( node ) ;
79- if ( declaration is LuaDeclaration luaDeclaration )
80- {
81- RenderFuncDeclaration ( luaDeclaration , funcStat ) ;
82- RenderContext . AddSeparator ( ) ;
83- }
84- }
85- }
86- }
87-
88- private void RenderFuncDeclaration ( LuaDeclaration declaration , LuaFuncStatSyntax funcStat )
89- {
90- if ( declaration . IsLocal || declaration . IsPrivate )
91- {
92- return ;
93- }
94-
95- var asyncText = declaration . IsAsync ? "async " : string . Empty ;
96-
97- if ( declaration . Info is MethodInfo methodInfo )
98- {
99- if ( methodInfo . IndexPtr . ToNode ( SearchContext ) is { } indexExpr )
100- {
101- RenderContext . WrapperLua ( ( ) =>
102- {
103- RenderContext . Append ( $ "{ asyncText } function { indexExpr . Text } ") ;
104- LuaTypeRenderer . RenderFunc ( methodInfo . Method , RenderContext ) ;
105- } ) ;
106- }
107- else if ( methodInfo . NamePtr . ToNode ( SearchContext ) is { } nameExpr )
108- {
109- RenderContext . WrapperLua ( ( ) =>
110- {
111- RenderContext . Append ( $ "{ asyncText } function { nameExpr . Text } ") ;
112- LuaTypeRenderer . RenderFunc ( methodInfo . Method , RenderContext ) ;
113- } ) ;
114- }
115-
116- var comments = funcStat . Comments ;
117- foreach ( var comment in comments )
118- {
119- if ( comment . CommentText is { Length : > 0 } commentText )
120- {
121- RenderContext . Append ( commentText ) ;
122- }
123-
124- RenderContext . AppendLine ( ) ;
125- }
126- }
127- }
128- }
13+ // public class ModuleDoc
14+ // {
15+ // private SearchContext SearchContext { get; }
16+ //
17+ // private LuaRenderContext RenderContext { get; }
18+ //
19+ // private LuaRenderBuilder RenderBuilder { get; }
20+ //
21+ // private ModuleIndex ModuleIndex { get; }
22+ //
23+ // private LuaRenderFeature Feature { get; } = new LuaRenderFeature()
24+ // {
25+ // ShowTypeLink = false,
26+ // ExpandAlias = false,
27+ // };
28+ //
29+ // public ModuleDoc(LuaCompilation compilation, ModuleIndex moduleIndex)
30+ // {
31+ // SearchContext = new SearchContext(compilation, new SearchContextFeatures());
32+ // RenderBuilder = new LuaRenderBuilder(SearchContext);
33+ // ModuleIndex = moduleIndex;
34+ // RenderContext = new LuaRenderContext(SearchContext, Feature);
35+ // }
36+ //
37+ // public string Build()
38+ // {
39+ // RenderContext.AddH1Title($"module {ModuleIndex.ModulePath}");
40+ // var document = SearchContext.Compilation.Workspace.GetDocument(ModuleIndex.DocumentId);
41+ // if (document is null)
42+ // {
43+ // return RenderContext.GetText();
44+ // }
45+ //
46+ // RenderModuleDescription(document);
47+ // RenderContext.AppendLine();
48+ //
49+ // RenderContext.AddH2Title("Public members:");
50+ // RenderContext.AddSeparator();
51+ // RenderModuleMembers(document);
52+ //
53+ // return RenderContext.GetText();
54+ // }
55+ //
56+ // private void RenderModuleDescription(LuaDocument document)
57+ // {
58+ // RenderContext.Append(RenderBuilder.RenderModule(document, Feature));
59+ // }
60+ //
61+ // private IEnumerable<LuaFuncStatSyntax> GetModuleStats(LuaDocument document)
62+ // {
63+ // if (document.SyntaxTree.SyntaxRoot.Block is { StatList: { } statList })
64+ // {
65+ // foreach (var funcStat in statList.OfType<LuaFuncStatSyntax>())
66+ // {
67+ // yield return funcStat;
68+ // }
69+ // }
70+ // }
71+ //
72+ // private void RenderModuleMembers(LuaDocument document)
73+ // {
74+ // foreach (var funcStat in GetModuleStats(document))
75+ // {
76+ // if (funcStat is { NameElement.Parent: { } node })
77+ // {
78+ // var declaration = SearchContext.FindDeclaration(node);
79+ // if (declaration is LuaDeclaration luaDeclaration)
80+ // {
81+ // RenderFuncDeclaration(luaDeclaration, funcStat);
82+ // RenderContext.AddSeparator();
83+ // }
84+ // }
85+ // }
86+ // }
87+ //
88+ // private void RenderFuncDeclaration(LuaDeclaration declaration, LuaFuncStatSyntax funcStat)
89+ // {
90+ // if (declaration.IsLocal || declaration.IsPrivate)
91+ // {
92+ // return;
93+ // }
94+ //
95+ // var asyncText = declaration.IsAsync ? "async " : string.Empty;
96+ //
97+ // if (declaration.Info is MethodInfo methodInfo)
98+ // {
99+ // if (methodInfo.IndexPtr.ToNode(SearchContext) is { } indexExpr)
100+ // {
101+ // RenderContext.WrapperLua(() =>
102+ // {
103+ // RenderContext.Append($"{asyncText}function {indexExpr.Text}");
104+ // LuaTypeRenderer.RenderFunc(methodInfo.Method, RenderContext);
105+ // });
106+ // }
107+ // else if (methodInfo.NamePtr.ToNode(SearchContext) is { } nameExpr)
108+ // {
109+ // RenderContext.WrapperLua(() =>
110+ // {
111+ // RenderContext.Append($"{asyncText}function {nameExpr.Text}");
112+ // LuaTypeRenderer.RenderFunc(methodInfo.Method, RenderContext);
113+ // });
114+ // }
115+ //
116+ // var comments = funcStat.Comments;
117+ // foreach (var comment in comments)
118+ // {
119+ // if (comment.CommentText is { Length: > 0 } commentText)
120+ // {
121+ // RenderContext.Append(commentText);
122+ // }
123+ //
124+ // RenderContext.AppendLine();
125+ // }
126+ // }
127+ // }
128+ // }
0 commit comments