Debug error overlap with valid tokens
This commit is contained in:
@@ -170,18 +170,21 @@ public class SlangFormatter : ICodeFormatter
|
|||||||
if (line is null)
|
if (line is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 1. Get base syntax tokens
|
// 1. Get base syntax tokens, converting to a dictionary for ease in deduping error tokens
|
||||||
var allTokens = Marshal.TokenizeLine(line.Text);
|
var allTokensDict = Marshal.TokenizeLine(line.Text).ToDictionary((k) => k.Column);
|
||||||
|
|
||||||
// 2. Overlay error tokens if diagnostics exist for this line
|
// 2. Replace valid tokens with error tokens if present
|
||||||
if (dict.ContainsKey(lineIndex))
|
if (dict.ContainsKey(lineIndex))
|
||||||
{
|
{
|
||||||
foreach (var lineDiagnostic in dict[lineIndex])
|
foreach (var lineDiagnostic in dict[lineIndex])
|
||||||
{
|
{
|
||||||
allTokens.Add(
|
var column = Math.Abs((int)lineDiagnostic.Range.StartCol);
|
||||||
new SemanticToken(
|
L.Info(
|
||||||
|
$"Overwriting token at L:{lineIndex} C:{column} - Range:{lineDiagnostic.Range.EndCol - lineDiagnostic.Range.StartCol}"
|
||||||
|
);
|
||||||
|
allTokensDict[column] = new SemanticToken(
|
||||||
line: (int)lineIndex,
|
line: (int)lineIndex,
|
||||||
column: Math.Abs((int)lineDiagnostic.Range.StartCol),
|
column,
|
||||||
length: Math.Abs(
|
length: Math.Abs(
|
||||||
(int)(lineDiagnostic.Range.EndCol - lineDiagnostic.Range.StartCol)
|
(int)(lineDiagnostic.Range.EndCol - lineDiagnostic.Range.StartCol)
|
||||||
),
|
),
|
||||||
@@ -189,15 +192,15 @@ public class SlangFormatter : ICodeFormatter
|
|||||||
style: ICodeFormatter.ColorError,
|
style: ICodeFormatter.ColorError,
|
||||||
data: lineDiagnostic.Message,
|
data: lineDiagnostic.Message,
|
||||||
isError: true
|
isError: true
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var allTokens = allTokensDict.Values.ToList();
|
||||||
|
|
||||||
// 3. Update the line (this clears existing tokens and uses the list we just built)
|
// 3. Update the line (this clears existing tokens and uses the list we just built)
|
||||||
line.Update(allTokens);
|
line.Update(allTokens);
|
||||||
|
|
||||||
// 4. CRITICAL FIX: Re-attach metadata that Update() dropped
|
|
||||||
ReattachMetadata(line, allTokens);
|
ReattachMetadata(line, allTokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user