Skip to content

Commit

Permalink
Add .Nil member to SymbolUntypedValue.type for nil
Browse files Browse the repository at this point in the history
Change symbol for `nil` from SymbolBasicValue to SymbolUntypedValue

Enable semantic tokens for identifiers with SymbolBasicValue symbol value.
Previously I disabled it (in #263) because `nil` was included there,
which made it be highlighted as a type.
  • Loading branch information
thetarnav committed May 4, 2024
1 parent 3fc35ca commit 044477b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
29 changes: 15 additions & 14 deletions src/server/analysis.odin
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ is_symbol_same_typed :: proc(
case:
return false
}
case .Nil:
return false
}
}
}
Expand Down Expand Up @@ -1292,24 +1294,21 @@ internal_resolve_type_identifier :: proc(
ident := new_type(Ident, node.pos, node.end, ast_context.allocator)
ident.name = node.name

symbol: Symbol
symbol: Symbol = {
type = .Keyword,
signature = node.name,
name = ident.name,
pkg = ast_context.current_package,
}

switch ident.name {
case "true", "false":
symbol = Symbol {
type = .Keyword,
signature = node.name,
pkg = ast_context.current_package,
value = SymbolUntypedValue{type = .Bool},
}
symbol.value = SymbolUntypedValue{type = .Bool}
case "nil":
// TODO get the type of nil from the context and remove .Nil from SymbolUntypedValue
symbol.value = SymbolUntypedValue{type = .Nil}
case:
symbol = Symbol {
type = .Keyword,
signature = node.name,
name = ident.name,
pkg = ast_context.current_package,
value = SymbolBasicValue{ident = ident},
}
symbol.value = SymbolBasicValue{ident = ident}
}

return symbol, true
Expand Down Expand Up @@ -4375,6 +4374,8 @@ get_signature :: proc(
return "bool"
case .Integer:
return "int"
case .Nil:
return "" // no obvious type for nil
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/server/hover.odin
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ write_hover_content :: proc(
symbol.signature = "float"
case .Integer:
symbol.signature = "int"
case .Nil:
// no obvious signature for nil
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/server/semantic_tokens.odin
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,11 @@ visit_ident :: proc(
SymbolFixedArrayValue,
SymbolSliceValue,
SymbolMapValue,
SymbolMultiPointer:
SymbolMultiPointer,
SymbolBasicValue:
write_semantic_node(builder, ident, .Type, modifiers)
case SymbolBasicValue, SymbolUntypedValue:
// handled by static syntax analysis
case SymbolUntypedValue:
// handled by static syntax highlighting
case SymbolGenericValue:
// unused
case:
Expand Down
1 change: 1 addition & 0 deletions src/server/symbol.odin
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ SymbolUntypedValue :: struct {
Float,
String,
Bool,
Nil,
},
tok: tokenizer.Token,
}
Expand Down

0 comments on commit 044477b

Please sign in to comment.