@@ -517,6 +517,40 @@ get_selector_completion :: proc(
517
517
append (&items, item)
518
518
}
519
519
520
+ case SymbolBitSetValue:
521
+ list.isIncomplete = false
522
+
523
+ enumv, ok := unwrap_bitset (ast_context, selector)
524
+ if !ok { break }
525
+
526
+ range, rok := get_range_from_selection_start_to_dot (position_context)
527
+ if !rok { break }
528
+
529
+ range.end.character -= 1
530
+
531
+ variable, vok := position_context.selector.derived_expr.(^ast.Ident)
532
+ if !vok { break }
533
+
534
+ remove_edit := TextEdit {
535
+ range = {
536
+ start = range.start,
537
+ end = range.end,
538
+ },
539
+ newText = " " ,
540
+ }
541
+
542
+ additionalTextEdits := make ([]TextEdit, 1 , context .temp_allocator)
543
+ additionalTextEdits[0 ] = remove_edit
544
+
545
+ for name in enumv.names {
546
+ append (&items, CompletionItem {
547
+ label = fmt.tprintf (" .%s" , name),
548
+ kind = .EnumMember,
549
+ detail = fmt.tprintf (" %s.%s" , selector.name, name),
550
+ additionalTextEdits = additionalTextEdits,
551
+ })
552
+ }
553
+
520
554
case SymbolStructValue:
521
555
list.isIncomplete = false
522
556
@@ -669,11 +703,31 @@ get_implicit_completion :: proc(
669
703
// value decl infer a : My_Enum = .*
670
704
if position_context.value_decl != nil &&
671
705
position_context.value_decl.type != nil {
672
- if enum_value, ok := unwrap_enum (
706
+ enum_value: Maybe (SymbolEnumValue)
707
+
708
+ if _enum_value, ok := unwrap_enum (
673
709
ast_context,
674
710
position_context.value_decl.type,
675
711
); ok {
676
- for name in enum_value.names {
712
+ enum_value = _enum_value
713
+ }
714
+
715
+ if position_context.comp_lit != nil {
716
+ if bitset_symbol, ok := resolve_type_expression (
717
+ ast_context,
718
+ position_context.value_decl.type,
719
+ ); ok {
720
+ if _enum_value, ok := unwrap_bitset (
721
+ ast_context,
722
+ bitset_symbol,
723
+ ); ok {
724
+ enum_value = _enum_value
725
+ }
726
+ }
727
+ }
728
+
729
+ if ev, ok := enum_value.?; ok {
730
+ for name in ev.names {
677
731
item := CompletionItem {
678
732
label = name,
679
733
kind = .EnumMember,
@@ -790,114 +844,112 @@ get_implicit_completion :: proc(
790
844
791
845
// infer bitset and enums based on the identifier comp_lit, i.e. a := My_Struct { my_ident = . }
792
846
if position_context.comp_lit != nil {
793
- if position_context.parent_comp_lit.type == nil {
794
- return
795
- }
796
-
797
- field_name: string
847
+ if position_context.parent_comp_lit.type != nil {
848
+ field_name: string
798
849
799
- if position_context.field_value != nil {
800
- if field, ok := position_context.field_value.field.derived.(^ast.Ident);
801
- ok {
802
- field_name = field.name
803
- } else {
804
- return
850
+ if position_context.field_value != nil {
851
+ if field, ok := position_context.field_value.field.derived.(^ast.Ident);
852
+ ok {
853
+ field_name = field.name
854
+ } else {
855
+ return
856
+ }
805
857
}
806
- }
807
858
808
- if symbol, ok := resolve_type_expression (
809
- ast_context,
810
- position_context.parent_comp_lit.type,
811
- ); ok {
812
- if comp_symbol, comp_lit, ok := resolve_type_comp_literal (
859
+ if symbol, ok := resolve_type_expression (
813
860
ast_context,
814
- position_context,
815
- symbol,
816
- position_context.parent_comp_lit,
861
+ position_context.parent_comp_lit.type,
817
862
); ok {
818
- if s, ok := comp_symbol.value.(SymbolStructValue); ok {
819
- ast_context.current_package = comp_symbol.pkg
820
-
821
- // We can either have the final
822
- elem_index := -1
823
-
824
- for elem, i in comp_lit.elems {
825
- if position_in_node (elem, position_context.position) {
826
- elem_index = i
827
- }
828
- }
863
+ if comp_symbol, comp_lit, ok := resolve_type_comp_literal (
864
+ ast_context,
865
+ position_context,
866
+ symbol,
867
+ position_context.parent_comp_lit,
868
+ ); ok {
869
+ if s, ok := comp_symbol.value.(SymbolStructValue); ok {
870
+ ast_context.current_package = comp_symbol.pkg
829
871
830
- type: ^ast.Expr
872
+ // We can either have the final
873
+ elem_index := -1
831
874
832
- for name, i in s.names {
833
- if name != field_name {
834
- continue
875
+ for elem, i in comp_lit.elems {
876
+ if position_in_node (elem, position_context.position) {
877
+ elem_index = i
878
+ }
835
879
}
836
880
837
- type = s.types[i]
838
- break
839
- }
840
-
841
- if type == nil && len (s.types) > elem_index {
842
- type = s.types[elem_index]
843
- }
881
+ type: ^ast.Expr
844
882
845
- if enum_value, ok := unwrap_enum (ast_context, type); ok {
846
- for enum_name in enum_value.names {
847
- item := CompletionItem {
848
- label = enum_name,
849
- kind = .EnumMember,
850
- detail = enum_name,
883
+ for name, i in s.names {
884
+ if name != field_name {
885
+ continue
851
886
}
852
887
853
- append (&items, item)
888
+ type = s.types[i]
889
+ break
854
890
}
855
891
856
- list.items = items[:]
857
- return
858
- } else if bitset_symbol, ok := resolve_type_expression (
859
- ast_context,
860
- type,
861
- ); ok {
862
- ast_context.current_package = bitset_symbol.pkg
863
-
864
- if value, ok := unwrap_bitset (
865
- ast_context,
866
- bitset_symbol,
867
- ); ok {
868
- for name in value.names {
892
+ if type == nil && len (s.types) > elem_index {
893
+ type = s.types[elem_index]
894
+ }
869
895
896
+ if enum_value, ok := unwrap_enum (ast_context, type); ok {
897
+ for enum_name in enum_value.names {
870
898
item := CompletionItem {
871
- label = name ,
899
+ label = enum_name ,
872
900
kind = .EnumMember,
873
- detail = name ,
901
+ detail = enum_name ,
874
902
}
875
903
876
904
append (&items, item)
877
905
}
906
+
878
907
list.items = items[:]
879
908
return
909
+ } else if bitset_symbol, ok := resolve_type_expression (
910
+ ast_context,
911
+ type,
912
+ ); ok {
913
+ ast_context.current_package = bitset_symbol.pkg
914
+
915
+ if value, ok := unwrap_bitset (
916
+ ast_context,
917
+ bitset_symbol,
918
+ ); ok {
919
+ for name in value.names {
920
+
921
+ item := CompletionItem {
922
+ label = name,
923
+ kind = .EnumMember,
924
+ detail = name,
925
+ }
926
+
927
+ append (&items, item)
928
+ }
929
+ list.items = items[:]
930
+ return
931
+ }
880
932
}
881
- }
882
- } else if s, ok := unwrap_bitset (ast_context, comp_symbol);
883
- ok {
884
- for enum_name in s.names {
885
- item := CompletionItem {
886
- label = enum_name,
887
- kind = .EnumMember,
888
- detail = enum_name,
933
+ } else if s, ok := unwrap_bitset (ast_context, comp_symbol);
934
+ ok {
935
+ for enum_name in s.names {
936
+ item := CompletionItem {
937
+ label = enum_name,
938
+ kind = .EnumMember,
939
+ detail = enum_name,
940
+ }
941
+
942
+ append (&items, item)
889
943
}
890
944
891
- append (&items, item)
945
+ list.items = items[:]
946
+ return
892
947
}
893
-
894
- list.items = items[:]
895
- return
896
948
}
897
949
}
898
- }
899
950
900
- reset_ast_context (ast_context)
951
+ reset_ast_context (ast_context)
952
+ }
901
953
}
902
954
903
955
if position_context.binary != nil &&
@@ -1066,6 +1118,33 @@ get_implicit_completion :: proc(
1066
1118
list.items = items[:]
1067
1119
return
1068
1120
}
1121
+
1122
+ // Bitset comp literal in parameter, eg: `hello({ . })`.
1123
+ if position_context.comp_lit != nil {
1124
+ if bitset_symbol, ok := resolve_type_expression (
1125
+ ast_context,
1126
+ proc_value.arg_types[parameter_index].type,
1127
+ ); ok {
1128
+ if enum_value, ok := unwrap_bitset (
1129
+ ast_context,
1130
+ bitset_symbol,
1131
+ ); ok {
1132
+ for name in enum_value.names {
1133
+ item := CompletionItem {
1134
+ label = name,
1135
+ kind = .EnumMember,
1136
+ detail = name,
1137
+ }
1138
+
1139
+ append (&items, item)
1140
+ }
1141
+
1142
+ list.items = items[:]
1143
+ return
1144
+ }
1145
+ }
1146
+ }
1147
+
1069
1148
} else if enum_value, ok := symbol.value.(SymbolEnumValue);
1070
1149
ok {
1071
1150
for name in enum_value.names {
0 commit comments