This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
308b532
commit bf428f5
Showing
13 changed files
with
345 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
|
||
namespace OneWare.Essentials.EditorExtensions; | ||
|
||
public struct SemanticToken | ||
{ | ||
public int Line { get; init; } | ||
public int StartCharacter { get; init; } | ||
public int Length { get; init; } | ||
public SemanticTokenType TokenType { get; init; } | ||
public SemanticTokenModifier[] TokenModifiers { get; init; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System.Collections.Immutable; | ||
using OmniSharp.Extensions.LanguageServer.Protocol.Models; | ||
using OneWare.Essentials.EditorExtensions; | ||
|
||
namespace OneWare.Essentials.Helpers; | ||
|
||
public static class SemanticTokenHelper | ||
{ | ||
public static List<SemanticToken> ParseSemanticTokens(ImmutableArray<int> data, SemanticTokensLegend legend) | ||
{ | ||
var tokens = new List<SemanticToken>(); | ||
var line = 0; | ||
var character = 0; | ||
|
||
var types = legend.TokenTypes.ToArray(); | ||
var modifiers = legend.TokenModifiers.ToArray(); | ||
|
||
for (var i = 0; i < data.Length; i += 5) | ||
{ | ||
var deltaLine = data[i]; | ||
var deltaStartCharacter = data[i + 1]; | ||
var length = data[i + 2]; | ||
var tokenType = data[i + 3]; | ||
var tokenModifiersBitset = data[i + 4]; | ||
|
||
line += deltaLine; | ||
if (deltaLine == 0) | ||
{ | ||
character += deltaStartCharacter; | ||
} | ||
else | ||
{ | ||
character = deltaStartCharacter; | ||
} | ||
|
||
if(tokenType < 0 || tokenType >= types!.Length) | ||
throw new InvalidOperationException("Invalid token type"); | ||
|
||
var tokenModifiers = new List<SemanticTokenModifier>(); | ||
for (var bit = 0; bit < modifiers.Length; bit++) | ||
{ | ||
if ((tokenModifiersBitset & (1 << bit)) != 0) | ||
{ | ||
tokenModifiers.Add(modifiers[bit]); | ||
} | ||
} | ||
|
||
tokens.Add(new SemanticToken | ||
{ | ||
Line = line, | ||
StartCharacter = character, | ||
Length = length, | ||
TokenType = types![tokenType], | ||
TokenModifiers = tokenModifiers.ToArray() | ||
}); | ||
} | ||
|
||
return tokens; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.