Skip to content

Commit 743dc64

Browse files
committed
optimize semanticToken
1 parent c75facc commit 743dc64

File tree

3 files changed

+12
-56
lines changed

3 files changed

+12
-56
lines changed

EmmyLua.LanguageServer/SemanticToken/SemanticTokensAnalyzer.cs

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ public List<uint> Tokenize(SemanticModel semanticModel, bool isVscode, Cancellat
7373
var syntaxTree = document.SyntaxTree;
7474
try
7575
{
76-
foreach (var nodeOrToken in syntaxTree.SyntaxRoot.DescendantsWithToken)
76+
var commentNodeOrToken = syntaxTree.SyntaxRoot.Descendants.OfType<LuaCommentSyntax>()
77+
.SelectMany(it => it.DescendantsWithToken);
78+
foreach (var nodeOrToken in commentNodeOrToken)
7779
{
7880
if (cancellationToken.IsCancellationRequested)
7981
{
@@ -119,11 +121,6 @@ public List<uint> TokenizeByRange(SemanticModel semanticModel, bool isVscode, Do
119121
var sourceRange = range.ToSourceRange(document);
120122
foreach (var nodeOrToken in syntaxTree.SyntaxRoot.DescendantsInRange(sourceRange))
121123
{
122-
if (cancellationToken.IsCancellationRequested)
123-
{
124-
return [];
125-
}
126-
127124
switch (nodeOrToken)
128125
{
129126
case LuaSyntaxToken token:
@@ -138,6 +135,11 @@ public List<uint> TokenizeByRange(SemanticModel semanticModel, bool isVscode, Do
138135
}
139136
}
140137
}
138+
139+
if (cancellationToken.IsCancellationRequested)
140+
{
141+
return [];
142+
}
141143
}
142144
catch (OperationCanceledException)
143145
{
@@ -156,65 +158,19 @@ private void TokenizeToken(SemanticBuilderWrapper builder, LuaSyntaxToken token,
156158
var tokenKind = token.Kind;
157159
switch (tokenKind)
158160
{
159-
case LuaTokenKind.TkLocal:
160-
{
161-
if (isVscode)
162-
{
163-
return;
164-
}
165-
166-
builder.Push(token, SemanticTokenTypes.Keyword);
167-
break;
168-
}
169-
case LuaTokenKind.TkIf:
170-
case LuaTokenKind.TkElse:
171-
case LuaTokenKind.TkElseIf:
172-
case LuaTokenKind.TkEnd:
173-
case LuaTokenKind.TkFor:
174-
case LuaTokenKind.TkFunction:
175-
case LuaTokenKind.TkIn:
176-
case LuaTokenKind.TkRepeat:
177-
case LuaTokenKind.TkReturn:
178-
case LuaTokenKind.TkThen:
179-
case LuaTokenKind.TkUntil:
180-
case LuaTokenKind.TkGoto:
181-
case LuaTokenKind.TkWhile:
182-
case LuaTokenKind.TkBreak:
183-
case LuaTokenKind.TkDo:
184-
case LuaTokenKind.TkAnd:
185-
case LuaTokenKind.TkOr:
186-
{
187-
builder.Push(token, SemanticTokenTypes.Keyword);
188-
break;
189-
}
190161
case LuaTokenKind.TkString:
191162
case LuaTokenKind.TkLongString:
192163
{
193164
builder.Push(token, SemanticTokenTypes.String);
194165
break;
195166
}
167+
case LuaTokenKind.TkDocOr:
196168
case LuaTokenKind.TkConcat:
197169
case LuaTokenKind.TkEq:
198170
case LuaTokenKind.TkNe:
199171
case LuaTokenKind.TkLe:
200172
case LuaTokenKind.TkGe:
201-
case LuaTokenKind.TkShl:
202-
case LuaTokenKind.TkShr:
203-
case LuaTokenKind.TkBitXor:
204-
case LuaTokenKind.TkBitAnd:
205-
case LuaTokenKind.TkBitOr:
206-
case LuaTokenKind.TkPlus:
207-
case LuaTokenKind.TkMinus:
208-
case LuaTokenKind.TkMul:
209-
case LuaTokenKind.TkDiv:
210-
case LuaTokenKind.TkMod:
211-
case LuaTokenKind.TkPow:
212-
case LuaTokenKind.TkLen:
213-
case LuaTokenKind.TkIDiv:
214173
case LuaTokenKind.TkDocMatch:
215-
case LuaTokenKind.TkColon:
216-
case LuaTokenKind.TkDbColon:
217-
case LuaTokenKind.TkSemicolon:
218174
case LuaTokenKind.TkLeftBracket:
219175
case LuaTokenKind.TkRightBracket:
220176
case LuaTokenKind.TkLeftParen:
@@ -223,7 +179,6 @@ private void TokenizeToken(SemanticBuilderWrapper builder, LuaSyntaxToken token,
223179
case LuaTokenKind.TkRightBrace:
224180
case LuaTokenKind.TkDots:
225181
case LuaTokenKind.TkComma:
226-
case LuaTokenKind.TkAssign:
227182
case LuaTokenKind.TkDot:
228183
{
229184
builder.Push(token, SemanticTokenTypes.Operator);
@@ -275,7 +230,7 @@ private void TokenizeToken(SemanticBuilderWrapper builder, LuaSyntaxToken token,
275230
{
276231
if (!isVscode)
277232
{
278-
builder.Push(token, SemanticTokenTypes.Keyword, SemanticTokenModifiers.Documentation);
233+
builder.Push(token, SemanticTokenTypes.Decorator, SemanticTokenModifiers.Documentation);
279234
}
280235

281236
break;

EmmyLua/CodeAnalysis/Compilation/LuaCompilation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private void AnalyzeDirtyDocuments()
134134
foreach (var documentId in DirtyDocumentIds)
135135
{
136136
var document = Project.GetDocument(documentId);
137-
if (document is not null && document.Text.Length < Project.Features.DontIndexMaxFileSize)
137+
if (document is not null)
138138
{
139139
Diagnostics.ClearDiagnostic(document.Id);
140140
documents.Add(document);

EmmyLua/CodeAnalysis/Workspace/LuaFeatures.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class LuaFeatures
4848

4949
public bool InitStdLib { get; set; } = true;
5050

51+
// Invalid config
5152
public int DontIndexMaxFileSize { get; set; } = 1048576; // 1MB
5253

5354
public Encoding Encoding { get; set; } = Encoding.UTF8;

0 commit comments

Comments
 (0)