Skip to content

Commit 2514e79

Browse files
committed
support ---@module no-require
1 parent 689bcf9 commit 2514e79

File tree

15 files changed

+96
-12
lines changed

15 files changed

+96
-12
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ private void AnalyzeGeneralDeclaration(LuaSyntaxElement attachedElement, List<Lu
6565
declaration.Feature |= DeclarationFeature.Async;
6666
break;
6767
}
68+
case LuaDocTagMappingSyntax mappingSyntax:
69+
{
70+
if (mappingSyntax.Name is { RepresentText: { } name })
71+
{
72+
declaration.Name = name;
73+
}
74+
75+
break;
76+
}
6877
}
6978
}
7079
}
@@ -147,9 +156,9 @@ private IEnumerable<LuaDeclaration> FindDeclarations(LuaSyntaxElement element)
147156
{
148157
switch (funcStatSyntax)
149158
{
150-
case { IsLocal: true, LocalName.Name: { } name }:
159+
case { IsLocal: true, LocalName: { } name }:
151160
{
152-
if (declarationContext.GetAttachedDeclaration(funcStatSyntax.LocalName) is { } luaDeclaration)
161+
if (declarationContext.GetAttachedDeclaration(name) is { } luaDeclaration)
153162
{
154163
yield return luaDeclaration;
155164
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ public void WalkIn(LuaSyntaxElement node)
178178
AnalyzeSimpleTag(overloadSyntax);
179179
break;
180180
}
181+
case LuaDocTagMappingSyntax mappingSyntax:
182+
{
183+
AnalyzeSimpleTag(mappingSyntax);
184+
break;
185+
}
181186
}
182187
}
183188

EmmyLua/CodeAnalysis/Compilation/Analyzer/DeclarationAnalyzer/DeclarationWalker/TagDocWalker.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ private void AnalyzeTagModule(LuaDocTagModuleSyntax moduleSyntax)
172172
{
173173
Compilation.Workspace.ModuleManager.AddVirtualModule(DocumentId, moduleName);
174174
}
175+
else if (moduleSyntax.Action is { Text: "no-require" })
176+
{
177+
Compilation.Workspace.ModuleManager.AddDisableRequire(DocumentId);
178+
}
175179
}
176180

177181
private void AnalyzeTagDiagnostic(LuaDocTagDiagnosticSyntax diagnosticSyntax)

EmmyLua/CodeAnalysis/Compilation/Declaration/LuaDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class LuaDeclaration(
4040
)
4141
: IDeclaration
4242
{
43-
public string Name { get; } = name;
43+
public string Name { get; internal set; } = name;
4444

4545
public LuaType Type => Info.DeclarationType ?? Builtin.Unknown;
4646

EmmyLua/CodeAnalysis/Compilation/Infer/DeclarationInfer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace EmmyLua.CodeAnalysis.Compilation.Infer;
66

77
public static class DeclarationInfer
88
{
9-
109
public static LuaType InferLocalName(LuaLocalNameSyntax localName, SearchContext context)
1110
{
1211
var symbol = context.FindDeclaration(localName);

EmmyLua/CodeAnalysis/Compile/Grammar/Doc/Tags.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public static CompleteMarker Tag(LuaDocParser p)
9595
{
9696
return TagModule(p);
9797
}
98+
case LuaTokenKind.TkTagMapping:
99+
{
100+
return TagMapping(p);
101+
}
98102
case LuaTokenKind.TkTagMeta:
99103
{
100104
return SimpleTag(p, LuaSyntaxKind.DocMeta);
@@ -709,7 +713,19 @@ private static CompleteMarker TagModule(LuaDocParser p)
709713
p.Bump();
710714
try
711715
{
712-
p.Expect(LuaTokenKind.TkString);
716+
if (p.Current is LuaTokenKind.TkString)
717+
{
718+
p.Bump();
719+
}
720+
else if (p.Current is LuaTokenKind.TkName)
721+
{
722+
p.Bump();
723+
}
724+
else
725+
{
726+
throw new UnexpectedTokenException("expected <name> or <string>", p.Current);
727+
}
728+
713729
DescriptionParser.Description(p);
714730
return m.Complete(p, LuaSyntaxKind.DocModule);
715731
}
@@ -719,6 +735,23 @@ private static CompleteMarker TagModule(LuaDocParser p)
719735
}
720736
}
721737

738+
private static CompleteMarker TagMapping(LuaDocParser p)
739+
{
740+
p.SetState(LuaDocLexerState.Normal);
741+
var m = p.Marker();
742+
p.Bump();
743+
try
744+
{
745+
p.Expect(LuaTokenKind.TkName);
746+
DescriptionParser.Description(p);
747+
return m.Complete(p, LuaSyntaxKind.DocMapping);
748+
}
749+
catch (UnexpectedTokenException e)
750+
{
751+
return m.Fail(p, LuaSyntaxKind.DocMapping, e.Message);
752+
}
753+
}
754+
722755
private static void ExtensionTypeList(LuaDocParser p)
723756
{
724757
p.Bump();

EmmyLua/CodeAnalysis/Compile/Lexer/LuaDocLexer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ private static LuaTokenKind ToTag(ReadOnlySpan<char> text)
4848
"async" => LuaTokenKind.TkTagAsync,
4949
"cast" => LuaTokenKind.TkTagCast,
5050
"deprecated" => LuaTokenKind.TkTagDeprecated,
51-
"private" or "protected" or "public" or "package" => LuaTokenKind.TkTagVisibility,
52-
// TODO internal
51+
"private" or "protected" or "public" or "package" or "internal" => LuaTokenKind.TkTagVisibility,
5352
"diagnostic" => LuaTokenKind.TkTagDiagnostic,
5453
"meta" => LuaTokenKind.TkTagMeta,
5554
"version" => LuaTokenKind.TkTagVersion,
5655
"as" => LuaTokenKind.TkTagAs,
5756
"nodiscard" => LuaTokenKind.TkTagNodiscard,
5857
"operator" => LuaTokenKind.TkTagOperator,
58+
"mapping" => LuaTokenKind.TkTagMapping,
5959
_ => LuaTokenKind.TkTagOther
6060
};
6161
}
@@ -64,7 +64,7 @@ private static LuaTokenKind ToVisibilityOrName(ReadOnlySpan<char> text)
6464
{
6565
return text switch
6666
{
67-
"private" or "protected" or "public" or "package" => LuaTokenKind.TkDocVisibility,
67+
"private" or "protected" or "public" or "package" or "internal" => LuaTokenKind.TkDocVisibility,
6868
_ => LuaTokenKind.TkName
6969
};
7070
}

EmmyLua/CodeAnalysis/Syntax/Kind/LuaSyntaxKind.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public enum LuaSyntaxKind : ushort
7474
DocNodiscard,
7575
DocOperator,
7676
DocModule,
77+
DocMapping,
7778

7879
DocDetailField,
7980
DocBody,

EmmyLua/CodeAnalysis/Syntax/Kind/LuaTokenKind.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public enum LuaTokenKind : ushort
111111
TkTagAs, // as
112112
TkTagNodiscard, // nodiscard
113113
TkTagOperator, // operator
114+
TkTagMapping, // mapping
114115

115116
TkDocOr, // |
116117
TkDocContinue, // ---

EmmyLua/CodeAnalysis/Syntax/Node/SyntaxFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static LuaSyntaxElement CreateSyntax(int index, LuaSyntaxTree tree)
7171
LuaSyntaxKind.DocNodiscard => new LuaDocTagNodiscardSyntax(index, tree),
7272
LuaSyntaxKind.DocOperator => new LuaDocTagOperatorSyntax(index, tree),
7373
LuaSyntaxKind.DocMeta => new LuaDocTagMetaSyntax(index, tree),
74+
LuaSyntaxKind.DocMapping => new LuaDocTagMappingSyntax(index, tree),
7475
LuaSyntaxKind.TypeArray => new LuaDocArrayTypeSyntax(index, tree),
7576
LuaSyntaxKind.TypeUnion => new LuaDocUnionTypeSyntax(index, tree),
7677
LuaSyntaxKind.TypeFun => new LuaDocFuncTypeSyntax(index, tree),

0 commit comments

Comments
 (0)