@alloy-js/csharp 0.20.0-dev.2 → 0.20.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/dist/src/components/Declaration.d.ts +2 -2
  2. package/dist/src/components/Declaration.d.ts.map +1 -1
  3. package/dist/src/components/Declaration.js +3 -13
  4. package/dist/src/components/Reference.d.ts.map +1 -1
  5. package/dist/src/components/Reference.js +5 -1
  6. package/dist/src/components/SourceFile.d.ts +8 -9
  7. package/dist/src/components/SourceFile.d.ts.map +1 -1
  8. package/dist/src/components/SourceFile.js +69 -45
  9. package/dist/src/components/UsingDirective.d.ts +5 -1
  10. package/dist/src/components/UsingDirective.d.ts.map +1 -1
  11. package/dist/src/components/UsingDirective.js +3 -1
  12. package/dist/src/components/class/declaration.d.ts +2 -2
  13. package/dist/src/components/class/declaration.d.ts.map +1 -1
  14. package/dist/src/components/class/declaration.js +19 -33
  15. package/dist/src/components/class/declaration.test.js +192 -193
  16. package/dist/src/components/constructor/constructor.d.ts.map +1 -1
  17. package/dist/src/components/constructor/constructor.js +11 -19
  18. package/dist/src/components/constructor/constructor.test.js +10 -19
  19. package/dist/src/components/{EnumDeclaration.d.ts → enum/declaration.d.ts} +6 -11
  20. package/dist/src/components/enum/declaration.d.ts.map +1 -0
  21. package/dist/src/components/enum/declaration.js +54 -0
  22. package/dist/src/components/enum/declaration.ref.test.d.ts +2 -0
  23. package/dist/src/components/enum/declaration.ref.test.d.ts.map +1 -0
  24. package/dist/src/components/enum/declaration.ref.test.js +120 -0
  25. package/dist/src/components/enum/declaration.test.d.ts +2 -0
  26. package/dist/src/components/enum/declaration.test.d.ts.map +1 -0
  27. package/dist/src/components/enum/declaration.test.js +39 -0
  28. package/dist/src/components/enum/member.d.ts +7 -0
  29. package/dist/src/components/enum/member.d.ts.map +1 -0
  30. package/dist/src/components/enum/member.js +29 -0
  31. package/dist/src/components/enum/member.test.d.ts +2 -0
  32. package/dist/src/components/enum/member.test.d.ts.map +1 -0
  33. package/dist/src/components/enum/member.test.js +28 -0
  34. package/dist/src/components/field/field.d.ts.map +1 -1
  35. package/dist/src/components/field/field.js +9 -17
  36. package/dist/src/components/field/field.test.js +7 -7
  37. package/dist/src/components/index.d.ts +5 -2
  38. package/dist/src/components/index.d.ts.map +1 -1
  39. package/dist/src/components/index.js +5 -2
  40. package/dist/src/components/interface/declaration.d.ts.map +1 -1
  41. package/dist/src/components/interface/declaration.js +19 -21
  42. package/dist/src/components/interface/declaration.test.js +26 -35
  43. package/dist/src/components/interface/method.d.ts.map +1 -1
  44. package/dist/src/components/interface/method.js +7 -18
  45. package/dist/src/components/interface/method.test.js +38 -47
  46. package/dist/src/components/interface/property.d.ts.map +1 -1
  47. package/dist/src/components/interface/property.js +21 -39
  48. package/dist/src/components/interface/property.test.js +11 -11
  49. package/dist/src/components/lexical-scope.d.ts +8 -0
  50. package/dist/src/components/lexical-scope.d.ts.map +1 -0
  51. package/dist/src/components/lexical-scope.js +24 -0
  52. package/dist/src/components/method/method.d.ts +5 -2
  53. package/dist/src/components/method/method.d.ts.map +1 -1
  54. package/dist/src/components/method/method.js +7 -16
  55. package/dist/src/components/method/method.test.js +11 -11
  56. package/dist/src/components/method-scope.d.ts +8 -0
  57. package/dist/src/components/method-scope.d.ts.map +1 -0
  58. package/dist/src/components/method-scope.js +24 -0
  59. package/dist/src/components/namespace-scopes.d.ts +13 -0
  60. package/dist/src/components/namespace-scopes.d.ts.map +1 -0
  61. package/dist/src/components/namespace-scopes.js +44 -0
  62. package/dist/src/components/namespace.d.ts +7 -0
  63. package/dist/src/components/namespace.d.ts.map +1 -0
  64. package/dist/src/components/namespace.js +46 -0
  65. package/dist/src/components/namespace.ref.test.d.ts +2 -0
  66. package/dist/src/components/namespace.ref.test.d.ts.map +1 -0
  67. package/dist/src/components/namespace.ref.test.js +181 -0
  68. package/dist/src/components/namespace.test.d.ts.map +1 -0
  69. package/dist/src/components/namespace.test.js +78 -0
  70. package/dist/src/components/parameters/parameters.d.ts +2 -2
  71. package/dist/src/components/parameters/parameters.d.ts.map +1 -1
  72. package/dist/src/components/parameters/parameters.js +12 -14
  73. package/dist/src/components/parameters/parameters.test.d.ts +2 -0
  74. package/dist/src/components/parameters/parameters.test.d.ts.map +1 -0
  75. package/dist/src/components/parameters/parameters.test.js +87 -0
  76. package/dist/src/components/property/property.d.ts.map +1 -1
  77. package/dist/src/components/property/property.js +21 -39
  78. package/dist/src/components/property/property.test.js +14 -14
  79. package/dist/src/components/record/declaration.d.ts +18 -0
  80. package/dist/src/components/record/declaration.d.ts.map +1 -1
  81. package/dist/src/components/record/declaration.js +19 -13
  82. package/dist/src/components/record/declaration.test.js +50 -3
  83. package/dist/src/components/struct/declaration.d.ts.map +1 -1
  84. package/dist/src/components/struct/declaration.js +4 -6
  85. package/dist/src/components/struct/declaration.test.js +30 -39
  86. package/dist/src/components/type-parameters/type-parameter.d.ts.map +1 -1
  87. package/dist/src/components/type-parameters/type-parameter.js +7 -10
  88. package/dist/src/components/type-parameters/type-parameters.test.js +3 -3
  89. package/dist/src/components/var/declaration.d.ts.map +1 -1
  90. package/dist/src/components/var/declaration.js +6 -8
  91. package/dist/src/components/var/declaration.test.js +11 -20
  92. package/dist/src/contexts/global-namespace.d.ts +5 -0
  93. package/dist/src/contexts/global-namespace.d.ts.map +1 -0
  94. package/dist/src/contexts/global-namespace.js +24 -0
  95. package/dist/src/contexts/namespace.d.ts +8 -0
  96. package/dist/src/contexts/namespace.d.ts.map +1 -0
  97. package/dist/src/contexts/namespace.js +5 -0
  98. package/dist/src/index.d.ts +1 -0
  99. package/dist/src/index.d.ts.map +1 -1
  100. package/dist/src/index.js +1 -0
  101. package/dist/src/modifiers.d.ts +11 -0
  102. package/dist/src/modifiers.d.ts.map +1 -1
  103. package/dist/src/scopes/class.d.ts +10 -0
  104. package/dist/src/scopes/class.d.ts.map +1 -0
  105. package/dist/src/scopes/class.js +10 -0
  106. package/dist/src/scopes/contexts.d.ts +9 -0
  107. package/dist/src/scopes/contexts.d.ts.map +1 -0
  108. package/dist/src/scopes/contexts.js +33 -0
  109. package/dist/src/scopes/csharp.d.ts +8 -0
  110. package/dist/src/scopes/csharp.d.ts.map +1 -0
  111. package/dist/src/scopes/csharp.js +11 -0
  112. package/dist/src/scopes/factories.d.ts +9 -0
  113. package/dist/src/scopes/factories.d.ts.map +1 -0
  114. package/dist/src/scopes/factories.js +23 -0
  115. package/dist/src/scopes/index.d.ts +10 -0
  116. package/dist/src/scopes/index.d.ts.map +1 -0
  117. package/dist/src/scopes/index.js +9 -0
  118. package/dist/src/scopes/lexical.d.ts +7 -0
  119. package/dist/src/scopes/lexical.d.ts.map +1 -0
  120. package/dist/src/scopes/lexical.js +7 -0
  121. package/dist/src/scopes/method.d.ts +9 -0
  122. package/dist/src/scopes/method.d.ts.map +1 -0
  123. package/dist/src/scopes/method.js +13 -0
  124. package/dist/src/scopes/named-type.d.ts +22 -0
  125. package/dist/src/scopes/named-type.d.ts.map +1 -0
  126. package/dist/src/scopes/named-type.js +32 -0
  127. package/dist/src/scopes/namespace.d.ts +11 -0
  128. package/dist/src/scopes/namespace.d.ts.map +1 -0
  129. package/dist/src/scopes/namespace.js +38 -0
  130. package/dist/src/scopes/source-file.d.ts +16 -0
  131. package/dist/src/scopes/source-file.d.ts.map +1 -0
  132. package/dist/src/scopes/source-file.js +43 -0
  133. package/dist/src/symbols/csharp.d.ts +76 -0
  134. package/dist/src/symbols/csharp.d.ts.map +1 -0
  135. package/dist/src/symbols/csharp.js +222 -0
  136. package/dist/src/symbols/factories.d.ts +25 -0
  137. package/dist/src/symbols/factories.d.ts.map +1 -0
  138. package/dist/src/symbols/factories.js +86 -0
  139. package/dist/src/symbols/index.d.ts +5 -2
  140. package/dist/src/symbols/index.d.ts.map +1 -1
  141. package/dist/src/symbols/index.js +6 -3
  142. package/dist/src/symbols/method.d.ts +13 -0
  143. package/dist/src/symbols/method.d.ts.map +1 -0
  144. package/dist/src/symbols/method.js +15 -0
  145. package/dist/src/symbols/named-type.d.ts +19 -0
  146. package/dist/src/symbols/named-type.d.ts.map +1 -0
  147. package/dist/src/symbols/named-type.js +30 -0
  148. package/dist/src/symbols/namespace.d.ts +22 -0
  149. package/dist/src/symbols/namespace.d.ts.map +1 -0
  150. package/dist/src/symbols/namespace.js +44 -0
  151. package/dist/src/symbols/reference.d.ts +2 -2
  152. package/dist/src/symbols/reference.d.ts.map +1 -1
  153. package/dist/src/symbols/reference.js +36 -43
  154. package/dist/test/project-directory.test.js +12 -16
  155. package/dist/test/sourcefile.test.js +7 -19
  156. package/dist/test/using.test.js +18 -16
  157. package/dist/test/utils.js +2 -2
  158. package/dist/tsconfig.tsbuildinfo +1 -1
  159. package/package.json +8 -4
  160. package/src/components/Declaration.tsx +3 -6
  161. package/src/components/Reference.tsx +3 -1
  162. package/src/components/SourceFile.tsx +68 -55
  163. package/src/components/UsingDirective.tsx +12 -2
  164. package/src/components/class/declaration.test.tsx +138 -143
  165. package/src/components/class/declaration.tsx +20 -33
  166. package/src/components/constructor/constructor.test.tsx +10 -16
  167. package/src/components/constructor/constructor.tsx +13 -32
  168. package/src/components/enum/declaration.ref.test.tsx +93 -0
  169. package/src/components/enum/declaration.test.tsx +34 -0
  170. package/src/components/enum/declaration.tsx +65 -0
  171. package/src/components/enum/member.test.tsx +24 -0
  172. package/src/components/enum/member.tsx +36 -0
  173. package/src/components/field/field.test.tsx +7 -7
  174. package/src/components/field/field.tsx +12 -22
  175. package/src/components/index.ts +5 -2
  176. package/src/components/interface/declaration.test.tsx +26 -32
  177. package/src/components/interface/declaration.tsx +16 -18
  178. package/src/components/interface/method.test.tsx +38 -44
  179. package/src/components/interface/method.tsx +7 -20
  180. package/src/components/interface/property.test.tsx +11 -11
  181. package/src/components/interface/property.tsx +15 -34
  182. package/src/components/lexical-scope.tsx +29 -0
  183. package/src/components/method/method.test.tsx +11 -11
  184. package/src/components/method/method.tsx +12 -23
  185. package/src/components/method-scope.tsx +27 -0
  186. package/src/components/namespace-scopes.tsx +44 -0
  187. package/src/components/namespace.ref.test.tsx +139 -0
  188. package/src/components/namespace.test.tsx +52 -0
  189. package/src/components/namespace.tsx +45 -0
  190. package/src/components/parameters/parameters.test.tsx +71 -0
  191. package/src/components/parameters/parameters.tsx +9 -21
  192. package/src/components/property/property.test.tsx +14 -14
  193. package/src/components/property/property.tsx +17 -41
  194. package/src/components/record/declaration.test.tsx +47 -3
  195. package/src/components/record/declaration.tsx +34 -11
  196. package/src/components/struct/declaration.test.tsx +16 -22
  197. package/src/components/struct/declaration.tsx +4 -6
  198. package/src/components/type-parameters/type-parameter.tsx +14 -11
  199. package/src/components/type-parameters/type-parameters.test.tsx +4 -4
  200. package/src/components/var/declaration.test.tsx +8 -14
  201. package/src/components/var/declaration.tsx +12 -6
  202. package/src/contexts/global-namespace.ts +29 -0
  203. package/src/contexts/namespace.ts +13 -0
  204. package/src/index.ts +1 -0
  205. package/src/modifiers.ts +14 -0
  206. package/src/scopes/class.ts +12 -0
  207. package/src/scopes/contexts.ts +45 -0
  208. package/src/scopes/csharp.ts +18 -0
  209. package/src/scopes/factories.ts +45 -0
  210. package/src/scopes/index.ts +9 -0
  211. package/src/scopes/lexical.ts +10 -0
  212. package/src/scopes/method.ts +22 -0
  213. package/src/scopes/named-type.ts +44 -0
  214. package/src/scopes/namespace.ts +59 -0
  215. package/src/scopes/source-file.ts +67 -0
  216. package/src/symbols/csharp.ts +307 -0
  217. package/src/symbols/factories.ts +199 -0
  218. package/src/symbols/index.ts +5 -2
  219. package/src/symbols/method.ts +26 -0
  220. package/src/symbols/named-type.ts +54 -0
  221. package/src/symbols/namespace.ts +62 -0
  222. package/src/symbols/reference.ts +47 -50
  223. package/temp/api.json +6152 -2151
  224. package/test/project-directory.test.tsx +12 -16
  225. package/test/sourcefile.test.tsx +7 -21
  226. package/test/using.test.tsx +18 -16
  227. package/test/utils.tsx +1 -1
  228. package/tsdoc-metadata.json +1 -1
  229. package/dist/src/components/EnumDeclaration.d.ts.map +0 -1
  230. package/dist/src/components/EnumDeclaration.js +0 -85
  231. package/dist/src/components/Namespace.d.ts +0 -11
  232. package/dist/src/components/Namespace.d.ts.map +0 -1
  233. package/dist/src/components/Namespace.js +0 -33
  234. package/dist/src/symbols/csharp-output-symbol.d.ts +0 -8
  235. package/dist/src/symbols/csharp-output-symbol.d.ts.map +0 -1
  236. package/dist/src/symbols/csharp-output-symbol.js +0 -19
  237. package/dist/src/symbols/scopes.d.ts +0 -14
  238. package/dist/src/symbols/scopes.d.ts.map +0 -1
  239. package/dist/src/symbols/scopes.js +0 -31
  240. package/dist/test/enum.test.d.ts +0 -2
  241. package/dist/test/enum.test.d.ts.map +0 -1
  242. package/dist/test/enum.test.js +0 -178
  243. package/dist/test/namespace.test.d.ts.map +0 -1
  244. package/dist/test/namespace.test.js +0 -81
  245. package/src/components/EnumDeclaration.tsx +0 -99
  246. package/src/components/Namespace.tsx +0 -35
  247. package/src/symbols/csharp-output-symbol.ts +0 -22
  248. package/src/symbols/scopes.ts +0 -41
  249. package/test/enum.test.tsx +0 -149
  250. package/test/namespace.test.tsx +0 -55
  251. /package/dist/{test → src/components}/namespace.test.d.ts +0 -0
@@ -0,0 +1,222 @@
1
+ import { OutputDeclarationSpace, OutputMemberSpace, OutputSymbol, track, TrackOpTypes, trigger, TriggerOpTypes, watch } from "@alloy-js/core";
2
+ /**
3
+ * This is the base type for all symbols in C#.
4
+ *
5
+ * Many subtypes of this symbol exist for specific purposes. However, this symbol
6
+ * may be used in cases where a more specific symbol is not required.
7
+ *
8
+ * @remarks
9
+ *
10
+ * This is roughly equivalent to the Roslyn ISymbol interface:
11
+ * https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.isymbol?view=roslyn-dotnet-4.13.0
12
+ */
13
+ export class CSharpSymbol extends OutputSymbol {
14
+ symbolKind = "symbol";
15
+ constructor(name, spaces, options = {}) {
16
+ super(name, spaces, options);
17
+ this.#accessibility = options.accessibility;
18
+ this.#isAbstract = options.isAbstract ?? false;
19
+ this.#isVirtual = options.isVirtual ?? false;
20
+ this.#isStatic = options.isStatic ?? false;
21
+ this.#isOverride = options.isOverride ?? false;
22
+ this.#isSealed = options.isSealed ?? false;
23
+ this.#isExtern = options.isExtern ?? false;
24
+ this.#isReadOnly = options.isReadOnly ?? false;
25
+ }
26
+ get enclosingNamespace() {
27
+ if (this.spaces.length === 0) {
28
+ return undefined;
29
+ }
30
+
31
+ // todo: probably need to validate that a symbol can't belong to spaces in
32
+ // multiple namespaces.
33
+ const firstSpace = this.spaces[0];
34
+ if (firstSpace instanceof OutputMemberSpace) {
35
+ // this symbol is a member of something, so get the enclosing namespace from
36
+ // the symbol.
37
+
38
+ if (firstSpace.symbol.constructor.name === "NamespaceSymbol") {
39
+ // this is a namespace symbol, so return the namespace symbol itself.
40
+ // can't use instanceof here due to circular reference issues.
41
+ return firstSpace.symbol;
42
+ }
43
+ return firstSpace.symbol.enclosingNamespace;
44
+ } else if (firstSpace instanceof OutputDeclarationSpace) {
45
+ // this symbol is in a lexical scope, so get the namespace symbol from the
46
+ // scope.
47
+ return firstSpace.scope.enclosingNamespace;
48
+ }
49
+ throw new Error("No place to get namespace symbol from");
50
+ return undefined;
51
+ }
52
+ #accessibility;
53
+ get accessibility() {
54
+ track(this, TrackOpTypes.GET, "accessibility");
55
+ return this.#accessibility;
56
+ }
57
+ set accessibility(value) {
58
+ const old = this.#accessibility;
59
+ if (old === value) {
60
+ return;
61
+ }
62
+ this.#accessibility = value;
63
+ trigger(this, TriggerOpTypes.SET, "accessibility", value, old);
64
+ }
65
+ copy() {
66
+ const options = this.getCopyOptions();
67
+ const copy = new CSharpSymbol(this.name, undefined, {
68
+ ...options,
69
+ accessibility: this.#accessibility,
70
+ isStatic: this.#isStatic,
71
+ isVirtual: this.#isVirtual,
72
+ isAbstract: this.#isAbstract,
73
+ isOverride: this.#isOverride,
74
+ isSealed: this.#isSealed,
75
+ isExtern: this.#isExtern,
76
+ isReadOnly: this.#isReadOnly
77
+ });
78
+ this.initializeCopy(copy);
79
+ watch(() => this.accessibility, newAccessibility => {
80
+ copy.accessibility = newAccessibility;
81
+ });
82
+ return copy;
83
+ }
84
+
85
+ /**
86
+ * Whether this symbol is static.
87
+ */
88
+ get isStatic() {
89
+ track(this, TrackOpTypes.GET, "isStatic");
90
+ return this.#isStatic;
91
+ }
92
+ set isStatic(value) {
93
+ const old = this.#isStatic;
94
+ if (old === value) {
95
+ return;
96
+ }
97
+ this.#isStatic = value;
98
+ trigger(this, TriggerOpTypes.SET, "isStatic", value, old);
99
+ }
100
+ #isStatic = false;
101
+
102
+ /**
103
+ * Whether this symbol is virtual.
104
+ */
105
+ get isVirtual() {
106
+ track(this, TrackOpTypes.GET, "isVirtual");
107
+ return this.#isVirtual;
108
+ }
109
+ set isVirtual(value) {
110
+ const old = this.#isVirtual;
111
+ if (old === value) {
112
+ return;
113
+ }
114
+ this.#isVirtual = value;
115
+ trigger(this, TriggerOpTypes.SET, "isVirtual", value, old);
116
+ }
117
+ #isVirtual = false;
118
+
119
+ /**
120
+ * Whether this symbol is abstract.
121
+ */
122
+ get isAbstract() {
123
+ track(this, TrackOpTypes.GET, "isAbstract");
124
+ return this.#isAbstract;
125
+ }
126
+ set isAbstract(value) {
127
+ const old = this.#isAbstract;
128
+ if (old === value) {
129
+ return;
130
+ }
131
+ this.#isAbstract = value;
132
+ trigger(this, TriggerOpTypes.SET, "isAbstract", value, old);
133
+ }
134
+ #isAbstract = false;
135
+
136
+ /**
137
+ * Whether this symbol is override.
138
+ */
139
+ get isOverride() {
140
+ track(this, TrackOpTypes.GET, "isOverride");
141
+ return this.#isOverride;
142
+ }
143
+ set isOverride(value) {
144
+ const old = this.#isOverride;
145
+ if (old === value) {
146
+ return;
147
+ }
148
+ this.#isOverride = value;
149
+ trigger(this, TriggerOpTypes.SET, "isOverride", value, old);
150
+ }
151
+ #isOverride = false;
152
+
153
+ /**
154
+ * Whether this symbol is sealed.
155
+ */
156
+ get isSealed() {
157
+ track(this, TrackOpTypes.GET, "isSealed");
158
+ return this.#isSealed;
159
+ }
160
+ set isSealed(value) {
161
+ const old = this.#isSealed;
162
+ if (old === value) {
163
+ return;
164
+ }
165
+ this.#isSealed = value;
166
+ trigger(this, TriggerOpTypes.SET, "isSealed", value, old);
167
+ }
168
+ #isSealed = false;
169
+
170
+ /**
171
+ * Whether this symbol is extern.
172
+ */
173
+ get isExtern() {
174
+ track(this, TrackOpTypes.GET, "isExtern");
175
+ return this.#isExtern;
176
+ }
177
+ set isExtern(value) {
178
+ const old = this.#isExtern;
179
+ if (old === value) {
180
+ return;
181
+ }
182
+ this.#isExtern = value;
183
+ trigger(this, TriggerOpTypes.SET, "isExtern", value, old);
184
+ }
185
+ #isExtern = false;
186
+
187
+ /**
188
+ * Whether this symbol is readonly.
189
+ */
190
+ get isReadOnly() {
191
+ track(this, TrackOpTypes.GET, "isReadOnly");
192
+ return this.#isReadOnly;
193
+ }
194
+ set isReadOnly(value) {
195
+ const old = this.#isReadOnly;
196
+ if (old === value) {
197
+ return;
198
+ }
199
+ this.#isReadOnly = value;
200
+ trigger(this, TriggerOpTypes.SET, "isReadOnly", value, old);
201
+ }
202
+ #isReadOnly = false;
203
+ }
204
+ export function accessibilityFromProps(props) {
205
+ for (const key of ["public", "internal", "protected", "private"]) {
206
+ if (props[key]) {
207
+ return key;
208
+ }
209
+ }
210
+ return "private";
211
+ }
212
+ export function nonAccessibilityFromProps(props) {
213
+ return {
214
+ isOverride: props.override ?? false,
215
+ isAbstract: props.abstract ?? false,
216
+ isVirtual: props.virtual ?? false,
217
+ isStatic: props.static ?? false,
218
+ isSealed: props.sealed ?? false,
219
+ isExtern: props.extern ?? false,
220
+ isReadOnly: props.readOnly ?? false
221
+ };
222
+ }
@@ -0,0 +1,25 @@
1
+ import { Namekey, OutputSymbolOptions } from "@alloy-js/core";
2
+ import { CSharpMethodScope } from "../scopes/method.js";
3
+ import { CSharpNamedTypeScope } from "../scopes/named-type.js";
4
+ import { CSharpSymbol, CSharpSymbolOptions } from "./csharp.js";
5
+ import { MethodKinds, MethodSymbol } from "./method.js";
6
+ import { NamedTypeSymbol, NamedTypeTypeKind } from "./named-type.js";
7
+ import { NamespaceSymbol } from "./namespace.js";
8
+ /**
9
+ * Create a symbol for a parameter in the current method scope.
10
+ */
11
+ export declare function createParameterSymbol(originalName: string | Namekey, options?: CSharpSymbolOptions): CSharpSymbol;
12
+ export interface CreateTypeParameterSymbolOptions extends CSharpSymbolOptions {
13
+ scope?: CSharpMethodScope | CSharpNamedTypeScope;
14
+ }
15
+ export declare function createTypeParameterSymbol(originalName: string | Namekey, options?: CreateTypeParameterSymbolOptions): CSharpSymbol;
16
+ export declare function createFieldSymbol(originalName: string | Namekey, options?: CSharpSymbolOptions): CSharpSymbol;
17
+ export declare function createNamedTypeSymbol(name: string | Namekey, kind: NamedTypeTypeKind, options?: OutputSymbolOptions): NamedTypeSymbol;
18
+ export declare function createNamespaceSymbol(name: string): NamespaceSymbol;
19
+ export interface CreateMethodSymbolOptions extends CSharpSymbolOptions {
20
+ methodKind?: MethodKinds;
21
+ }
22
+ export declare function createMethodSymbol(originalName: string | Namekey, options?: CreateMethodSymbolOptions): MethodSymbol;
23
+ export declare function createPropertySymbol(name: string | Namekey, options: CSharpSymbolOptions): CSharpSymbol;
24
+ export declare function createVariableSymbol(originalName: string | Namekey, options?: CSharpSymbolOptions): CSharpSymbol;
25
+ //# sourceMappingURL=factories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories.d.ts","sourceRoot":"","sources":["../../../src/symbols/factories.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,mBAAmB,EAEpB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAM/D,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,mBAAwB,gBAgBlC;AAED,MAAM,WAAW,gCAAiC,SAAQ,mBAAmB;IAC3E,KAAK,CAAC,EAAE,iBAAiB,GAAG,oBAAoB,CAAC;CAClD;AACD,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,gCAAqC,gBAiB/C;AAED,wBAAgB,iBAAiB,CAC/B,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,mBAAwB,gBA0BlC;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,mBAAmB,mBAI9B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,mBAOjD;AAED,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACpE,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,yBAA8B,gBAoBxC;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,OAAO,EAAE,mBAAmB,gBAQ7B;AAED,wBAAgB,oBAAoB,CAClC,YAAY,EAAE,MAAM,GAAG,OAAO,EAC9B,OAAO,GAAE,mBAAwB,gBA2BlC"}
@@ -0,0 +1,86 @@
1
+ import { useBinder } from "@alloy-js/core";
2
+ import { getGlobalNamespace } from "../contexts/global-namespace.js";
3
+ import { useCSharpNamePolicy } from "../name-policy.js";
4
+ import { CSharpClassScope } from "../scopes/class.js";
5
+ import { useCSharpScope, useNamedTypeScope } from "../scopes/contexts.js";
6
+ import { CSharpLexicalScope } from "../scopes/lexical.js";
7
+ import { CSharpMethodScope } from "../scopes/method.js";
8
+ import { CSharpNamedTypeScope } from "../scopes/named-type.js";
9
+ import { CSharpNamespaceScope, useEnclosingNamespaceScope } from "../scopes/namespace.js";
10
+ import { CSharpSourceFileScope } from "../scopes/source-file.js";
11
+ import { CSharpSymbol } from "./csharp.js";
12
+ import { MethodSymbol } from "./method.js";
13
+ import { NamedTypeSymbol } from "./named-type.js";
14
+ import { NamespaceSymbol } from "./namespace.js";
15
+
16
+ /**
17
+ * Create a symbol for a parameter in the current method scope.
18
+ */
19
+ export function createParameterSymbol(originalName, options = {}) {
20
+ const scope = useCSharpScope();
21
+ if (!(scope instanceof CSharpMethodScope) && !(scope instanceof CSharpClassScope)) {
22
+ throw new Error(`Can't create parameter symbol outside of a method or class scope.`);
23
+ }
24
+ return new CSharpSymbol(originalName, scope.parameters, withNamePolicy(options, "parameter"));
25
+ }
26
+ export function createTypeParameterSymbol(originalName, options = {}) {
27
+ const scope = options.scope ?? useCSharpScope();
28
+ if (!(scope instanceof CSharpMethodScope) && !(scope instanceof CSharpNamedTypeScope)) {
29
+ throw new Error("Can't create a type parameter symbol outside of a method or named type scope.");
30
+ }
31
+ return new CSharpSymbol(originalName, scope.typeParameters, withNamePolicy(options, "type-parameter"));
32
+ }
33
+ export function createFieldSymbol(originalName, options = {}) {
34
+ let nameElement = "class-member-private";
35
+ if (options.accessibility === "public" || options.accessibility === "internal" || options.accessibility === "protected") {
36
+ nameElement = "class-member-public";
37
+ }
38
+ const scope = useNamedTypeScope();
39
+ if (scope.ownerSymbol.typeKind !== "class" && scope.ownerSymbol.typeKind !== "struct") {
40
+ throw new Error(`Can't define a field outside of a class or struct.`);
41
+ }
42
+ return new CSharpSymbol(originalName, scope.members, withNamePolicy(options, nameElement));
43
+ }
44
+ export function createNamedTypeSymbol(name, kind, options) {
45
+ const scope = useNamedTypeScope();
46
+ return new NamedTypeSymbol(name, scope.ownerSymbol.members, kind, options);
47
+ }
48
+ export function createNamespaceSymbol(name) {
49
+ const scope = useEnclosingNamespaceScope();
50
+ const nsSymbol = scope?.ownerSymbol ?? getGlobalNamespace(useBinder());
51
+ if (nsSymbol.members.symbolNames.has(name)) {
52
+ return nsSymbol.members.symbolNames.get(name);
53
+ }
54
+ return new NamespaceSymbol(name, nsSymbol);
55
+ }
56
+ export function createMethodSymbol(originalName, options = {}) {
57
+ const scope = useNamedTypeScope();
58
+ if (scope.ownerSymbol.typeKind !== "class" && scope.ownerSymbol.typeKind !== "interface" && scope.ownerSymbol.typeKind !== "struct") {
59
+ throw new Error(`Can't define a method outside of a class, interface, or struct.`);
60
+ }
61
+ return new MethodSymbol(originalName, scope.members, options.methodKind ?? "ordinary", withNamePolicy(options, "class-method"));
62
+ }
63
+ export function createPropertySymbol(name, options) {
64
+ const scope = useNamedTypeScope();
65
+ return new CSharpSymbol(name, scope.members, withNamePolicy(options, "class-property"));
66
+ }
67
+ export function createVariableSymbol(originalName, options = {}) {
68
+ let scope = useCSharpScope();
69
+ if (scope instanceof CSharpNamespaceScope && scope.ownerSymbol === getGlobalNamespace(scope.ownerSymbol.binder)) {
70
+ // allow top-level variables in the global namespace, which are local to the source file.
71
+ scope = scope.parent;
72
+ if (!(scope instanceof CSharpSourceFileScope)) {
73
+ throw new Error("Variable declarations must be in the global namespace or within a lexical scope.");
74
+ }
75
+ }
76
+ if (!(scope instanceof CSharpLexicalScope)) {
77
+ throw new Error(`Can't create variable symbol outside of a lexical scope, got a ${scope.constructor.name}.`);
78
+ }
79
+ return new CSharpSymbol(originalName, scope.localVariables, withNamePolicy(options, "variable"));
80
+ }
81
+ function withNamePolicy(options, elementType) {
82
+ return {
83
+ ...options,
84
+ namePolicy: options.namePolicy ?? useCSharpNamePolicy().for(elementType)
85
+ };
86
+ }
@@ -1,4 +1,7 @@
1
- export * from "./csharp-output-symbol.js";
1
+ export * from "./csharp.js";
2
+ export * from "./factories.js";
3
+ export * from "./method.js";
4
+ export * from "./named-type.js";
5
+ export * from "./namespace.js";
2
6
  export * from "./reference.js";
3
- export * from "./scopes.js";
4
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/symbols/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
@@ -1,3 +1,6 @@
1
- export * from "./csharp-output-symbol.js";
2
- export * from "./reference.js";
3
- export * from "./scopes.js";
1
+ export * from "./csharp.js";
2
+ export * from "./factories.js";
3
+ export * from "./method.js";
4
+ export * from "./named-type.js";
5
+ export * from "./namespace.js";
6
+ export * from "./reference.js";
@@ -0,0 +1,13 @@
1
+ import { Namekey, OutputSpace } from "@alloy-js/core";
2
+ import { CSharpSymbol, CSharpSymbolOptions } from "./csharp.js";
3
+ export type MethodKinds = "ordinary" | "constructor";
4
+ /**
5
+ * A symbol for a method or constructor of a class, interface, or struct.
6
+ */
7
+ export declare class MethodSymbol extends CSharpSymbol {
8
+ #private;
9
+ readonly symbolKind = "method";
10
+ get methodKind(): MethodKinds;
11
+ constructor(name: string | Namekey, spaces: OutputSpace | undefined, kind: MethodKinds, options?: CSharpSymbolOptions);
12
+ }
13
+ //# sourceMappingURL=method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../src/symbols/method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEhE,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,aAAa,CAAC;AAErD;;GAEG;AACH,qBAAa,YAAa,SAAQ,YAAY;;IAC5C,SAAgB,UAAU,YAAY;IAGtC,IAAI,UAAU,gBAEb;gBAGC,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,MAAM,EAAE,WAAW,GAAG,SAAS,EAC/B,IAAI,EAAE,WAAW,EACjB,OAAO,GAAE,mBAAwB;CAKpC"}
@@ -0,0 +1,15 @@
1
+ import { CSharpSymbol } from "./csharp.js";
2
+ /**
3
+ * A symbol for a method or constructor of a class, interface, or struct.
4
+ */
5
+ export class MethodSymbol extends CSharpSymbol {
6
+ symbolKind = "method";
7
+ #methodKind;
8
+ get methodKind() {
9
+ return this.#methodKind;
10
+ }
11
+ constructor(name, spaces, kind, options = {}) {
12
+ super(name, spaces, options);
13
+ this.#methodKind = kind;
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ import { Namekey, OutputSpace, OutputSymbolOptions } from "@alloy-js/core";
2
+ import { CSharpSymbol } from "./csharp.js";
3
+ export type NamedTypeTypeKind = "class" | "interface" | "enum" | "namespace" | "struct" | "record";
4
+ export type NamedTypeSymbolKind = "named-type" | "namespace";
5
+ /**
6
+ * A symbol for a named type in C# such as a class, interface, enum, and so
7
+ * forth. Named types are generally defined in a namespace, and can have members
8
+ * of their own.
9
+ */
10
+ export declare class NamedTypeSymbol extends CSharpSymbol {
11
+ #private;
12
+ readonly symbolKind: NamedTypeSymbolKind;
13
+ static readonly memberSpaces: string[];
14
+ constructor(name: string | Namekey, spaces: OutputSpace[] | OutputSpace | undefined, kind: NamedTypeTypeKind, options?: OutputSymbolOptions);
15
+ get typeKind(): NamedTypeTypeKind;
16
+ copy(): NamedTypeSymbol;
17
+ get members(): import("@alloy-js/core").OutputMemberSpace;
18
+ }
19
+ //# sourceMappingURL=named-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"named-type.d.ts","sourceRoot":"","sources":["../../../src/symbols/named-type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP,WAAW,GACX,MAAM,GACN,WAAW,GACX,QAAQ,GACR,QAAQ,CAAC;AACb,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,WAAW,CAAC;AAE7D;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,YAAY;;IAC/C,SAAgB,UAAU,EAAE,mBAAmB,CAAgB;IAC/D,gBAAuB,YAAY,WAAe;gBAGhD,IAAI,EAAE,MAAM,GAAG,OAAO,EACtB,MAAM,EAAE,WAAW,EAAE,GAAG,WAAW,GAAG,SAAS,EAC/C,IAAI,EAAE,iBAAiB,EACvB,OAAO,CAAC,EAAE,mBAAmB;IAO/B,IAAI,QAAQ,sBAEX;IAED,IAAI;IAYJ,IAAI,OAAO,+CAEV;CACF"}
@@ -0,0 +1,30 @@
1
+ import { CSharpSymbol } from "./csharp.js";
2
+
3
+ // represents a symbol from a .cs file. Class, enum, interface etc.
4
+
5
+ /**
6
+ * A symbol for a named type in C# such as a class, interface, enum, and so
7
+ * forth. Named types are generally defined in a namespace, and can have members
8
+ * of their own.
9
+ */
10
+ export class NamedTypeSymbol extends CSharpSymbol {
11
+ symbolKind = "named-type";
12
+ static memberSpaces = ["members"];
13
+ constructor(name, spaces, kind, options) {
14
+ super(name, spaces, options);
15
+ this.#typeKind = kind;
16
+ }
17
+ #typeKind;
18
+ get typeKind() {
19
+ return this.#typeKind;
20
+ }
21
+ copy() {
22
+ const options = this.getCopyOptions();
23
+ const copy = new NamedTypeSymbol(this.name, undefined, this.#typeKind, options);
24
+ this.initializeCopy(copy);
25
+ return copy;
26
+ }
27
+ get members() {
28
+ return this.memberSpaceFor("members");
29
+ }
30
+ }
@@ -0,0 +1,22 @@
1
+ import { OutputSymbolOptions } from "@alloy-js/core";
2
+ import { NamedTypeSymbol } from "./named-type.js";
3
+ export interface NamespaceSymbolOptions extends OutputSymbolOptions {
4
+ isGlobal?: boolean;
5
+ }
6
+ /**
7
+ * A symbol for a namespace in C#.
8
+ */
9
+ export declare class NamespaceSymbol extends NamedTypeSymbol {
10
+ #private;
11
+ readonly symbolKind = "namespace";
12
+ constructor(name: string, parentNamespace?: NamespaceSymbol, options?: NamespaceSymbolOptions);
13
+ /**
14
+ * Whether this symbol is the global namespace symbol.
15
+ */
16
+ get isGlobal(): boolean;
17
+ getFullyQualifiedName(options?: {
18
+ omitGlobal?: boolean;
19
+ }): string;
20
+ copy(): NamespaceSymbol;
21
+ }
22
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../src/symbols/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,sBAAuB,SAAQ,mBAAmB;IACjE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,eAAe;;IAClD,SAAgB,UAAU,eAAe;gBAEvC,IAAI,EAAE,MAAM,EACZ,eAAe,CAAC,EAAE,eAAe,EACjC,OAAO,CAAC,EAAE,sBAAsB;IAUlC;;OAEG;IACH,IAAI,QAAQ,YAEX;IAED,qBAAqB,CAAC,OAAO,GAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAO,GAAG,MAAM;IAoBrE,IAAI;CASL"}
@@ -0,0 +1,44 @@
1
+ import { NamedTypeSymbol } from "./named-type.js";
2
+ /**
3
+ * A symbol for a namespace in C#.
4
+ */
5
+ export class NamespaceSymbol extends NamedTypeSymbol {
6
+ symbolKind = "namespace";
7
+ constructor(name, parentNamespace, options) {
8
+ const space = parentNamespace?.members;
9
+ super(name, space, "namespace", options);
10
+ this.#isGlobal = !!options?.isGlobal;
11
+ }
12
+ #isGlobal;
13
+ /**
14
+ * Whether this symbol is the global namespace symbol.
15
+ */
16
+ get isGlobal() {
17
+ return this.#isGlobal;
18
+ }
19
+ getFullyQualifiedName(options = {}) {
20
+ const parts = [];
21
+
22
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
23
+ let current = this;
24
+ while (current && !current.isGlobal) {
25
+ parts.unshift(current.name);
26
+ current = current.ownerSymbol;
27
+ }
28
+ const idPart = parts.join(".");
29
+ if (options.omitGlobal) {
30
+ return idPart;
31
+ } else {
32
+ return `global::${idPart}`;
33
+ }
34
+ }
35
+ copy() {
36
+ const options = this.getCopyOptions();
37
+ const copy = new NamespaceSymbol(this.name, undefined, {
38
+ ...options,
39
+ isGlobal: this.#isGlobal
40
+ });
41
+ this.initializeCopy(copy);
42
+ return copy;
43
+ }
44
+ }
@@ -1,3 +1,3 @@
1
- import * as core from "@alloy-js/core";
2
- export declare function ref(refkey: core.Refkey): () => string;
1
+ import { OutputSymbol, Refkey } from "@alloy-js/core";
2
+ export declare function ref(refkey: Refkey): () => [string, OutputSymbol | undefined];
3
3
  //# sourceMappingURL=reference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAoBvC,wBAAgB,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,GAAG,MAAM,MAAM,CA4CrD"}
1
+ {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../../../src/symbols/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,YAAY,EAAE,MAAM,EAAW,MAAM,gBAAgB,CAAC;AAWrE,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC,CAkD5E"}
@@ -1,54 +1,47 @@
1
- import * as core from "@alloy-js/core";
2
- import { useNamespace } from "../components/Namespace.js";
3
- import { useSourceFile } from "../components/SourceFile.js";
4
-
5
- // when resolving references across source files, the last element
6
- // in pathDown will be the containing source file. we only need this
7
- // here so we can find and remove this scope as it's not useful
8
- // when building the reference
9
-
1
+ import { memo, resolve } from "@alloy-js/core";
2
+ import { CSharpNamespaceScope } from "../scopes/namespace.js";
3
+ import { useSourceFileScope } from "../scopes/source-file.js";
10
4
  // converts a refkey to its fully qualified name
11
5
  // e.g. if refkey is for bar in enum type foo, and
12
6
  // foo is in the same namespace as the refkey, then
13
7
  // the result would be foo.bar.
14
8
  export function ref(refkey) {
15
- const targetNamespaceCtx = useNamespace();
16
- const resolveResult = core.resolve(refkey);
17
- return core.memo(() => {
9
+ const refSfScope = useSourceFileScope();
10
+ const resolveResult = resolve(refkey);
11
+ return memo(() => {
18
12
  if (resolveResult.value === undefined) {
19
- return "<Unresolved Symbol>";
13
+ return ["<Unresolved Symbol>", undefined];
20
14
  }
21
-
22
- // targetDeclaration is the symbol with the refkey
23
- // pathDown is an array of scopes to that symbol and can be empty.
24
- // the entries are top-down, so namespace, source-file, member
25
- // - referencing a type within the same namespace will have an empty path
26
- // - referencing a member (e.g. enum value) within the same namespace will
27
- // have a single path entry that contains the owning type
28
- // - referencing a type within the same namespace but in a different source
29
- // file will have at least a source-file entry
30
- // - referencing a symbol outside the current namespace will have at least
31
- // two entries, namespace, source-file
15
+ const result = resolveResult.value;
32
16
  const {
33
- targetDeclaration,
34
- pathDown
35
- } = resolveResult.value;
36
- const sourceNamespace = pathDown.find(v => {
37
- return v.kind === "namespace";
38
- });
39
- if (sourceNamespace && sourceNamespace.name !== targetNamespaceCtx.name) {
40
- // the source symbol is in a different namespace that the target refkey.
41
- // add the applicable using statement to the target's source file.
42
- const targetSrc = useSourceFile();
43
- targetSrc.addUsing(sourceNamespace.name);
17
+ commonScope,
18
+ pathDown,
19
+ memberPath
20
+ } = result;
21
+ let {
22
+ lexicalDeclaration
23
+ } = result;
24
+ const parts = [];
25
+ if (!commonScope) {
26
+ // this shouldn't be possible in csharp.
27
+ return ["<Unresolved Symbol>", undefined];
44
28
  }
45
-
46
- // we only need to build the fully-qualified name for members
47
- // TODO: possibly a subset of members
48
- const syms = pathDown.filter(v => {
49
- return v.kind === "member";
50
- }).map(s => s.owner);
51
- syms.push(targetDeclaration);
52
- return syms.map(sym => sym.name).join(".");
29
+ if (commonScope instanceof CSharpNamespaceScope && commonScope.ownerSymbol.isGlobal && lexicalDeclaration.symbolKind === "namespace" && memberPath.length > 0) {
30
+ // we need to using the namespace
31
+ let nsToUse;
32
+ while (lexicalDeclaration.symbolKind === "namespace" && memberPath.length > 0) {
33
+ nsToUse = lexicalDeclaration;
34
+ lexicalDeclaration = memberPath.shift();
35
+ }
36
+ refSfScope.addUsing(nsToUse);
37
+ }
38
+ for (const nsScope of pathDown) {
39
+ parts.push(nsScope.ownerSymbol.name);
40
+ }
41
+ parts.push(lexicalDeclaration.name);
42
+ for (const member of memberPath) {
43
+ parts.push(member.name);
44
+ }
45
+ return [parts.join("."), result.symbol];
53
46
  });
54
47
  }