Skip to content

Commit c98e0a4

Browse files
committed
support @mapping annotation
1 parent 2514e79 commit c98e0a4

File tree

7 files changed

+43
-35
lines changed

7 files changed

+43
-35
lines changed

EmmyLua.LanguageServer/Completion/CompleteProvider/DocProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class DocProvider : ICompleteProviderBase
1212
[
1313
"class", "enum", "interface", "alias", "module", "field", "param", "return", "see", "deprecated",
1414
"type", "overload", "generic", "async", "cast", "private", "protected", "public", "operator",
15-
"meta", "version", "as", "nodiscard", "diagnostic", // "package",
15+
"meta", "version", "as", "nodiscard", "diagnostic", "mapping",// "package",
1616
];
1717

1818
private List<string> Actions { get; } = ["disable-next-line", "disable", "enable"];

EmmyLua.LanguageServer/Server/Render/Renderer/LuaCommentRenderer.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private static void RenderCommentDescription(IEnumerable<LuaCommentSyntax>? comm
1717
foreach (var comment in comments)
1818
{
1919
// renderContext.AddSeparator();
20-
renderContext.AppendLine();
20+
renderContext.Append("\n\n");
2121
renderContext.Append(comment.CommentText);
2222
}
2323
}
@@ -126,12 +126,6 @@ public static void RenderFunctionDocComment(MethodInfo methodInfo, LuaRenderCont
126126
{
127127
if (tagParam.Description is { CommentText: {} commentText })
128128
{
129-
// var detailList = details.ToList();
130-
// if (detailList.Count == 0)
131-
// {
132-
// continue;
133-
// }
134-
135129
var renderString = new StringBuilder();
136130
// var nameLength = 0;
137131
if (tagParam.Name is { RepresentText: { } name })
@@ -147,29 +141,14 @@ public static void RenderFunctionDocComment(MethodInfo methodInfo, LuaRenderCont
147141

148142
// var detailIndent = " - ";
149143
renderString.Append($" - {commentText}");
150-
// for (var index = 0; index < detailList.Count; index++)
151-
// {
152-
// var detail = detailList[index];
153-
// renderString.Append($"{detailIndent}{detail.RepresentText}");
154-
// if (index < detailList.Count - 1)
155-
// {
156-
// renderString.Append("\n\n");
157-
// }
158-
//
159-
// if (index == 0 && detailList.Count > 1)
160-
// {
161-
// detailIndent = new string(' ', 7 + nameLength + 3); // 8 spaces + nameLength + 3 spaces
162-
// }
163-
// }
164-
165144
tagRenderList.Add(renderString.ToString());
166145
}
167146

168147
}
169148

170149
if (tagRenderList.Count > 0)
171150
{
172-
renderContext.AppendLine();
151+
renderContext.Append("\n\n");
173152
foreach (var tagRender in tagRenderList)
174153
{
175154
renderContext.Append(tagRender);

EmmyLua.LanguageServer/Server/Render/Renderer/LuaDeclarationRenderer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ private static void RenderDocFieldDeclaration(LuaDeclaration declaration, DocFie
215215
{
216216
var visibility = declaration.Visibility switch
217217
{
218-
DeclarationVisibility.Public => " public",
219-
DeclarationVisibility.Protected => " protected",
220-
DeclarationVisibility.Private => " private",
218+
DeclarationVisibility.Public => "",
219+
DeclarationVisibility.Protected => "protected ",
220+
DeclarationVisibility.Private => "private ",
221221
_ => ""
222222
};
223-
renderContext.Append($"(field){visibility} {declaration.Name} : ");
223+
renderContext.Append($"{visibility}(field) {declaration.Name} : ");
224224
LuaTypeRenderer.RenderType(docFieldInfo.DeclarationType, renderContext);
225225
});
226226
LuaCommentRenderer.RenderDocFieldComment(docFieldInfo, renderContext);
@@ -233,13 +233,13 @@ private static void RenderTableFieldDeclaration(LuaDeclaration declaration, Tabl
233233
{
234234
var visibility = declaration.Visibility switch
235235
{
236-
DeclarationVisibility.Public => "public ",
236+
DeclarationVisibility.Public => "",
237237
DeclarationVisibility.Protected => "protected ",
238238
DeclarationVisibility.Private => "private ",
239239
_ => ""
240240
};
241241

242-
renderContext.Append($"{visibility} {declaration.Name} : ");
242+
renderContext.Append($"{visibility}{declaration.Name} : ");
243243
LuaTypeRenderer.RenderType(tableFieldInfo.DeclarationType, renderContext);
244244
if (tableFieldInfo.TableFieldPtr.ToNode(renderContext.SearchContext) is
245245
{ IsValue: false, Value: LuaLiteralExprSyntax expr })

EmmyLua/CodeAnalysis/Compilation/Analyzer/DeclarationAnalyzer/AttachDeclarationAnalyzer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private void AnalyzeGeneralDeclaration(LuaSyntaxElement attachedElement, List<Lu
7070
if (mappingSyntax.Name is { RepresentText: { } name })
7171
{
7272
declaration.Name = name;
73+
declarationContext.Db.AddMapping(declaration.UniqueId, name);
7374
}
7475

7576
break;

EmmyLua/CodeAnalysis/Compilation/Index/WorkspaceIndex.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class WorkspaceIndex
3232

3333
private Dictionary<LuaDocumentId, LuaDeclarationTree> DocumentDeclarationTrees { get; } = new();
3434

35+
private UniqueIndex<SyntaxElementId, string> MappingName { get; } = new();
36+
3537
public void Remove(LuaDocumentId documentId)
3638
{
3739
TypeIndex.Remove(documentId);
@@ -196,6 +198,11 @@ public void AddGenericParam(LuaDocumentId documentId, string name, LuaDeclaratio
196198
TypeIndex.AddGenericParam(documentId, name, luaDeclaration);
197199
}
198200

201+
public void AddMapping(SyntaxElementId id, string name)
202+
{
203+
MappingName.Update(id.DocumentId, id, name);
204+
}
205+
199206
#endregion
200207

201208
#region Query
@@ -366,5 +373,10 @@ public IEnumerable<LuaDeclaration> QueryAllMembers()
366373
return TypeIndex.QueryAllMembers();
367374
}
368375

376+
public string? QueryMapping(SyntaxElementId id)
377+
{
378+
return MappingName.Query(id);
379+
}
380+
369381
#endregion
370382
}

EmmyLua/CodeAnalysis/Compilation/Search/Members.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,16 @@ public IEnumerable<IDeclaration> FindMember(LuaType luaType, LuaIndexExprSyntax
320320
}
321321

322322
var notFounded = true;
323-
if (indexExpr is { Name: { } name })
323+
var mappingName = context.Compilation.Db.QueryMapping(indexExpr.UniqueId);
324+
if (mappingName is not null)
325+
{
326+
foreach (var declaration in FindMember(luaType, mappingName))
327+
{
328+
notFounded = false;
329+
yield return declaration;
330+
}
331+
}
332+
else if (indexExpr is { Name: { } name })
324333
{
325334
foreach (var declaration in FindMember(luaType, name))
326335
{

EmmyLua/CodeAnalysis/Compilation/Search/References.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private IEnumerable<ReferenceResult> LocalReferences(LuaDeclaration declaration,
4545
var luaReferences = context.Compilation.Db.QueryLocalReferences(declaration);
4646
foreach (var luaReference in luaReferences)
4747
{
48-
if (luaReference.Ptr.ToNode(context) is {} element)
48+
if (luaReference.Ptr.ToNode(context) is { } element)
4949
{
5050
references.Add(new ReferenceResult(element.Location, element, luaReference.Kind));
5151
}
@@ -77,7 +77,7 @@ private IEnumerable<ReferenceResult> FieldReferences(LuaDeclaration declaration,
7777
var indexExprs = context.Compilation.Db.QueryIndexExprReferences(fieldName, context);
7878
foreach (var indexExpr in indexExprs)
7979
{
80-
if (context.FindDeclaration(indexExpr) == declaration && indexExpr.KeyElement is {} keyElement)
80+
if (context.FindDeclaration(indexExpr) == declaration && indexExpr.KeyElement is { } keyElement)
8181
{
8282
references.Add(new ReferenceResult(keyElement.Location, keyElement));
8383
}
@@ -100,12 +100,19 @@ private IEnumerable<ReferenceResult> MethodReferences(LuaDeclaration declaration
100100
}
101101
default:
102102
{
103+
var results = new List<ReferenceResult>();
104+
var mappingName = context.Compilation.Db.QueryMapping(methodInfo.IndexPtr.UniqueId);
105+
if (mappingName is not null)
106+
{
107+
results.AddRange(FieldReferences(declaration, mappingName));
108+
}
109+
103110
if (methodInfo.IndexPtr.ToNode(context) is { Name: { } name })
104111
{
105-
return FieldReferences(declaration, name);
112+
results.AddRange(FieldReferences(declaration, name));
106113
}
107114

108-
break;
115+
return results;
109116
}
110117
}
111118

0 commit comments

Comments
 (0)