Removed struct, enum, opaque, union token types, added them to token modifiers
This commit is contained in:
parent
42cbcdf751
commit
d877019abe
@ -5,12 +5,7 @@ const analysis = @import("analysis.zig");
|
||||
const ast = std.zig.ast;
|
||||
|
||||
pub const TokenType = enum(u32) {
|
||||
namespace,
|
||||
type,
|
||||
@"struct",
|
||||
@"enum",
|
||||
@"union",
|
||||
@"opaque",
|
||||
parameter,
|
||||
variable,
|
||||
tagField,
|
||||
@ -28,6 +23,11 @@ pub const TokenType = enum(u32) {
|
||||
};
|
||||
|
||||
pub const TokenModifiers = packed struct {
|
||||
namespace: bool = false,
|
||||
@"struct": bool = false,
|
||||
@"enum": bool = false,
|
||||
@"union": bool = false,
|
||||
@"opaque": bool = false,
|
||||
definition: bool = false,
|
||||
@"async": bool = false,
|
||||
documentation: bool = false,
|
||||
@ -35,14 +35,11 @@ pub const TokenModifiers = packed struct {
|
||||
|
||||
fn toInt(self: TokenModifiers) u32 {
|
||||
var res: u32 = 0;
|
||||
if (self.definition)
|
||||
res |= 1 << 0;
|
||||
if (self.@"async")
|
||||
res |= 1 << 1;
|
||||
if (self.documentation)
|
||||
res |= 1 << 2;
|
||||
if (self.generic)
|
||||
res |= 1 << 3;
|
||||
inline for (std.meta.fields(TokenModifiers)) |field, i| {
|
||||
if (@field(self, field.name)) {
|
||||
res |= 1 << i;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -188,20 +185,19 @@ const GapHighlighter = struct {
|
||||
|
||||
fn colorIdentifierBasedOnType(builder: *Builder, type_node: analysis.TypeWithHandle, target_tok: ast.TokenIndex, tok_mod: TokenModifiers) !void {
|
||||
if (type_node.type.is_type_val) {
|
||||
const tok_type = if (type_node.isNamespace())
|
||||
.namespace
|
||||
var new_tok_mod = tok_mod;
|
||||
if (type_node.isNamespace())
|
||||
new_tok_mod.set("namespace")
|
||||
else if (type_node.isStructType())
|
||||
.@"struct"
|
||||
new_tok_mod.set("struct")
|
||||
else if (type_node.isEnumType())
|
||||
.@"enum"
|
||||
new_tok_mod.set("enum")
|
||||
else if (type_node.isUnionType())
|
||||
.@"union"
|
||||
new_tok_mod.set("union")
|
||||
else if (type_node.isOpaqueType())
|
||||
.@"opaque"
|
||||
else
|
||||
TokenType.type;
|
||||
new_tok_mod.set("opaque");
|
||||
|
||||
try writeTokenMod(builder, target_tok, tok_type, tok_mod);
|
||||
try writeTokenMod(builder, target_tok, .type, new_tok_mod);
|
||||
} else if (type_node.isTypeFunc()) {
|
||||
try writeTokenMod(builder, target_tok, .type, tok_mod);
|
||||
} else if (type_node.isFunc()) {
|
||||
|
@ -97,7 +97,7 @@ test "Open file, ask for semantic tokens" {
|
||||
try sendRequest(sem_toks_req, process);
|
||||
try sendRequest(shutdown_message, process);
|
||||
try consumeOutputAndWait(process, .{
|
||||
\\{"jsonrpc":"2.0","id":2,"result":{"data":[0,0,5,12,0,0,6,3,0,1,0,4,1,16,0,0,2,7,17,0,0,8,5,14,0]}}
|
||||
\\{"jsonrpc":"2.0","id":0,"result":{"data":[0,0,5,7,0,0,6,3,0,33,0,4,1,11,0,0,2,7,12,0,0,8,5,9,0]}}
|
||||
});
|
||||
}
|
||||
|
||||
@ -143,6 +143,6 @@ test "Requesting utf-8 offset encoding" {
|
||||
|
||||
try sendRequest(shutdown_message, process);
|
||||
try consumeOutputAndWait(process, .{
|
||||
\\{"jsonrpc":"2.0","id":0,"result":{"offsetEncoding":"utf-8","capabilities":{"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":1,"renameProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",":","@"]},"documentHighlightProvider":false,"hoverProvider":true,"codeActionProvider":false,"declarationProvider":true,"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":false,"referencesProvider":true,"documentSymbolProvider":true,"colorProvider":false,"documentFormattingProvider":true,"documentRangeFormattingProvider":false,"foldingRangeProvider":false,"selectionRangeProvider":false,"workspaceSymbolProvider":false,"rangeProvider":false,"documentProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}},"semanticTokensProvider":{"documentProvider":true,"legend":{"tokenTypes":["namespace","type","struct","enum","union","opaque","parameter","variable","tagField","field","errorTag","function","keyword","comment","string","number","operator","builtin","label","keywordLiteral"],"tokenModifiers":["definition","async","documentation","generic"]}}},"serverInfo":{"name":"zls","version":"0.1.0"}}}
|
||||
\\{"jsonrpc":"2.0","id":0,"result":{"offsetEncoding":"utf-8","capabilities":{"signatureHelpProvider":{"triggerCharacters":["(",","]},"textDocumentSync":1,"renameProvider":true,"completionProvider":{"resolveProvider":false,"triggerCharacters":[".",":","@"]},"documentHighlightProvider":false,"hoverProvider":true,"codeActionProvider":false,"declarationProvider":true,"definitionProvider":true,"typeDefinitionProvider":true,"implementationProvider":false,"referencesProvider":true,"documentSymbolProvider":true,"colorProvider":false,"documentFormattingProvider":true,"documentRangeFormattingProvider":false,"foldingRangeProvider":false,"selectionRangeProvider":false,"workspaceSymbolProvider":false,"rangeProvider":false,"documentProvider":true,"workspace":{"workspaceFolders":{"supported":true,"changeNotifications":true}},"semanticTokensProvider":{"documentProvider":true,"legend":{"tokenTypes":["type","parameter","variable","tagField","field","errorTag","function","keyword","comment","string","number","operator","builtin","label","keywordLiteral"],"tokenModifiers":["namespace","struct","enum","union","opaque","definition","async","documentation","generic"]}}},"serverInfo":{"name":"zls","version":"0.1.0"}}}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user