Removed struct, enum, opaque, union token types, added them to token modifiers

This commit is contained in:
Alexandros Naskos 2020-11-06 11:03:21 +02:00
parent 42cbcdf751
commit d877019abe
No known key found for this signature in database
GPG Key ID: 02BF2E72B0EA32D2
2 changed files with 20 additions and 24 deletions

View File

@ -5,12 +5,7 @@ const analysis = @import("analysis.zig");
const ast = std.zig.ast; const ast = std.zig.ast;
pub const TokenType = enum(u32) { pub const TokenType = enum(u32) {
namespace,
type, type,
@"struct",
@"enum",
@"union",
@"opaque",
parameter, parameter,
variable, variable,
tagField, tagField,
@ -28,6 +23,11 @@ pub const TokenType = enum(u32) {
}; };
pub const TokenModifiers = packed struct { pub const TokenModifiers = packed struct {
namespace: bool = false,
@"struct": bool = false,
@"enum": bool = false,
@"union": bool = false,
@"opaque": bool = false,
definition: bool = false, definition: bool = false,
@"async": bool = false, @"async": bool = false,
documentation: bool = false, documentation: bool = false,
@ -35,14 +35,11 @@ pub const TokenModifiers = packed struct {
fn toInt(self: TokenModifiers) u32 { fn toInt(self: TokenModifiers) u32 {
var res: u32 = 0; var res: u32 = 0;
if (self.definition) inline for (std.meta.fields(TokenModifiers)) |field, i| {
res |= 1 << 0; if (@field(self, field.name)) {
if (self.@"async") res |= 1 << i;
res |= 1 << 1; }
if (self.documentation) }
res |= 1 << 2;
if (self.generic)
res |= 1 << 3;
return res; 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 { fn colorIdentifierBasedOnType(builder: *Builder, type_node: analysis.TypeWithHandle, target_tok: ast.TokenIndex, tok_mod: TokenModifiers) !void {
if (type_node.type.is_type_val) { if (type_node.type.is_type_val) {
const tok_type = if (type_node.isNamespace()) var new_tok_mod = tok_mod;
.namespace if (type_node.isNamespace())
new_tok_mod.set("namespace")
else if (type_node.isStructType()) else if (type_node.isStructType())
.@"struct" new_tok_mod.set("struct")
else if (type_node.isEnumType()) else if (type_node.isEnumType())
.@"enum" new_tok_mod.set("enum")
else if (type_node.isUnionType()) else if (type_node.isUnionType())
.@"union" new_tok_mod.set("union")
else if (type_node.isOpaqueType()) else if (type_node.isOpaqueType())
.@"opaque" new_tok_mod.set("opaque");
else
TokenType.type;
try writeTokenMod(builder, target_tok, tok_type, tok_mod); try writeTokenMod(builder, target_tok, .type, new_tok_mod);
} else if (type_node.isTypeFunc()) { } else if (type_node.isTypeFunc()) {
try writeTokenMod(builder, target_tok, .type, tok_mod); try writeTokenMod(builder, target_tok, .type, tok_mod);
} else if (type_node.isFunc()) { } else if (type_node.isFunc()) {

View File

@ -97,7 +97,7 @@ test "Open file, ask for semantic tokens" {
try sendRequest(sem_toks_req, process); try sendRequest(sem_toks_req, process);
try sendRequest(shutdown_message, process); try sendRequest(shutdown_message, process);
try consumeOutputAndWait(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 sendRequest(shutdown_message, process);
try consumeOutputAndWait(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"}}}
}); });
} }