diff options
| author | Bradley Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-10-29 00:12:45 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-29 00:12:45 -0400 |
| commit | cce38ecb7d006b22bc0b8fb7c483561a477ebd22 (patch) | |
| tree | 66df59b63754265076ebffa9bc42547f2acfff62 | |
| parent | e8b2b18f24973c4bde9e235cb083043a896fb705 (diff) | |
| parent | 0f0d35c0b52ea666fc2adae7ecbcf0d013152ec7 (diff) | |
Merge pull request #1129 from BradLewis/fix/hover-complex-quaternion-literals
Display hover information for untyped complex numbers and quaternions correctly
| -rw-r--r-- | src/server/analysis.odin | 35 | ||||
| -rw-r--r-- | src/server/builtins.odin | 1 | ||||
| -rw-r--r-- | src/server/documentation.odin | 4 | ||||
| -rw-r--r-- | src/server/symbol.odin | 2 | ||||
| -rw-r--r-- | tests/hover_test.odin | 27 |
5 files changed, 57 insertions, 12 deletions
diff --git a/src/server/analysis.odin b/src/server/analysis.odin index 8cd75d6..83aef98 100644 --- a/src/server/analysis.odin +++ b/src/server/analysis.odin @@ -302,14 +302,16 @@ resolve_type_comp_literal :: proc( // odinfmt: disable untyped_map: [SymbolUntypedValueType][]string = { - .Integer = { + .Integer = { "int", "uint", "u8", "i8", "u16", "i16", "u32", "i32", "u64", "i64", "u128", "i128", "byte", "i16le", "i16be", "i32le", "i32be", "i64le", "i64be", "i128le", "i128be", "u16le", "u16be", "u32le", "u32be", "u64le", "u64be", "u128le", "u128be", }, - .Bool = {"bool", "b8", "b16", "b32", "b64"}, - .Float = {"f16", "f32", "f64", "f16le", "f16be", "f32le", "f32be", "f64le", "f64be"}, - .String = {"string", "cstring"}, + .Bool = {"bool", "b8", "b16", "b32", "b64"}, + .Float = {"f16", "f32", "f64", "f16le", "f16be", "f32le", "f32be", "f64le", "f64be"}, + .String = {"string", "cstring"}, + .Complex = {"complex32", "complex64", "complex128"}, + .Quaternion = {"quaternion64", "quaternion128", "quaternion256"}, } // odinfmt: enable @@ -953,14 +955,27 @@ resolve_basic_lit :: proc(ast_context: ^AstContext, basic_lit: ast.Basic_Lit) -> return {}, false } - if v, ok := strconv.parse_int(basic_lit.tok.text); ok { + #partial switch basic_lit.tok.kind { + case .Integer: value.type = .Integer - } else if v, ok := strconv.parse_bool(basic_lit.tok.text); ok { - value.type = .Bool - } else if v, ok := strconv.parse_f64(basic_lit.tok.text); ok { + case .Float: value.type = .Float - } else { - value.type = .String + case .Imag: + if v, ok := strconv.parse_complex64(basic_lit.tok.text); ok { + value.type = .Complex + } else { + value.type = .Quaternion + } + case: + if v, ok := strconv.parse_int(basic_lit.tok.text); ok { + value.type = .Integer + } else if v, ok := strconv.parse_bool(basic_lit.tok.text); ok { + value.type = .Bool + } else if v, ok := strconv.parse_f64(basic_lit.tok.text); ok { + value.type = .Float + } else { + value.type = .String + } } symbol.pkg = ast_context.current_package diff --git a/src/server/builtins.odin b/src/server/builtins.odin index 7c5ce8e..37b80c3 100644 --- a/src/server/builtins.odin +++ b/src/server/builtins.odin @@ -1,7 +1,6 @@ package server import "core:fmt" -import "core:log" import "core:odin/ast" import "core:strconv" diff --git a/src/server/documentation.odin b/src/server/documentation.odin index 42afe6e..c190837 100644 --- a/src/server/documentation.odin +++ b/src/server/documentation.odin @@ -445,6 +445,10 @@ write_short_signature :: proc(sb: ^strings.Builder, ast_context: ^AstContext, sy strings.write_string(sb, "bool") case .Integer: strings.write_string(sb, "int") + case .Complex: + strings.write_string(sb, "complex") + case .Quaternion: + strings.write_string(sb, "quaternion") } return } diff --git a/src/server/symbol.odin b/src/server/symbol.odin index d4be282..4f9539d 100644 --- a/src/server/symbol.odin +++ b/src/server/symbol.odin @@ -138,6 +138,8 @@ SymbolBitSetValue :: struct { SymbolUntypedValueType :: enum { Integer, Float, + Complex, + Quaternion, String, Bool, } diff --git a/tests/hover_test.odin b/tests/hover_test.odin index bd7abe6..c3d6729 100644 --- a/tests/hover_test.odin +++ b/tests/hover_test.odin @@ -1,6 +1,5 @@ package tests -import "core:fmt" import "core:testing" import test "src:testing" @@ -5322,6 +5321,32 @@ ast_hover_proc_arg_generic_bit_set :: proc(t: ^testing.T) { } test.expect_hover(t, &source, "test.foo :: proc($T: typeid/bit_set[$F; $E])") } + +@(test) +ast_hover_complex_number_literal :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + main :: proc() { + f{*}oo := 1 + 1i + } + + `, + } + test.expect_hover(t, &source, "test.foo: complex") +} + +@(test) +ast_hover_quaternion_literal :: proc(t: ^testing.T) { + source := test.Source { + main = `package test + main :: proc() { + f{*}oo := 1 + 2i + 3j + 4k + } + + `, + } + test.expect_hover(t, &source, "test.foo: quaternion") +} /* Waiting for odin fix |