image.vision\aoci\aoci_symbol.mbt

94.1% · 16 / 17 points · 90 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

  1. 1///|
  2. 2/// # AOCI 符号坐标类型 AOCI Symbol Coordinate Types
  3. 3///
  4. 4/// 符号在代码库中的位置和元信息
  5. 5/// 符号位置与元数据 Symbol position
  6. 6// AOCI 符号语义索引 — 符号坐标类型
  7. 7// SymbolCoord: 符号在代码库中的位置和元信息
  8. 8
  9. 9///|
  10. 10/// `#non_exhaustive` 表示未来可能添加新构造器
  11. 11#derive(Eq, @debug.Debug)
  12. 12#non_exhaustive
  13. 13pub(all) enum SymbolKind {
  14. 14 Function
  15. 15 Method
  16. 16 Type
  17. 17 TypeAlias
  18. 18 Enum
  19. 19 Struct
  20. 20}
  21. 21
  22. 22///|
  23. 23pub extend SymbolKind with Eq::{not_equal, equal}
  24. 24
  25. 25///|
  26. 26pub extend SymbolKind with @debug.Debug::{to_repr}
  27. 27
  28. 28///|
  29. 29pub fn SymbolKind::to_string(self : SymbolKind) -> String {
  30. 30● match self {
  31. 31● Function => "Function"
  32. 32● Method => "Method"
  33. 33● Type => "Type"
  34. 34○ TypeAlias => "TypeAlias"
  35. 35● Enum => "Enum"
  36. 36● Struct => "Struct"
  37. 37 }
  38. 38}
  39. 39
  40. 40///|
  41. 41#derive(Eq, @debug.Debug)
  42. 42pub(all) struct SymbolCoord {
  43. 43 pkg : String
  44. 44 name : String
  45. 45 kind : SymbolKind
  46. 46 signature : String
  47. 47 doc : String
  48. 48 keywords : Array[String]
  49. 49}
  50. 50
  51. 51///|
  52. 52pub extend SymbolCoord with Eq::{not_equal, equal}
  53. 53
  54. 54///|
  55. 55pub extend SymbolCoord with @debug.Debug::{to_repr}
  56. 56
  57. 57///|
  58. 58pub fn SymbolCoord::make(
  59. 59 pkg~ : String,
  60. 60 name~ : String,
  61. 61 kind~ : SymbolKind,
  62. 62 signature~ : String = "",
  63. 63 doc~ : String = "",
  64. 64 keywords~ : Array[String] = [],
  65. 65) -> SymbolCoord {
  66. 66● { pkg, name, kind, signature, doc, keywords, }
  67. 67}
  68. 68
  69. 69///|
  70. 70pub fn SymbolCoord::full_name(self : SymbolCoord) -> String {
  71. 71● self.pkg + "::" + self.name
  72. 72}
  73. 73
  74. 74///|
  75. 75pub fn SymbolCoord::has_keyword(self : SymbolCoord, keyword : String) -> Bool {
  76. 76● for kw in self.keywords {
  77. 77● if kw == keyword {
  78. 78● return true
  79. 79 }
  80. 80 }
  81. 81 false
  82. 82}
  83. 83
  84. 84///|
  85. 85pub fn SymbolCoord::estimated_tokens(self : SymbolCoord) -> Int32 {
  86. 86● let name_tokens = self.name.length() / 4 + 1
  87. 87● let sig_tokens = self.signature.length() / 4 + 1
  88. 88● let doc_tokens = self.doc.length() / 4 + 1
  89. 89 name_tokens + sig_tokens + doc_tokens + 10
  90. 90}