Skip to content

Commit 1f685d6

Browse files
author
Denis Peshkov
committed
Merge remote-tracking branch 'origin/master' into bugfix/problem_with_types_defined_in_external_libs
2 parents 494a898 + 3d17581 commit 1f685d6

3 files changed

Lines changed: 44 additions & 38 deletions

File tree

src/TypeScriptDefinitionGenerator/Generator/IntellisenseParser.cs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal static class IntellisenseParser
1717
private static readonly Regex IsNumber = new Regex("^[0-9a-fx]+[ul]{0,2}$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
1818
private static Project _project;
1919

20-
public static IEnumerable<IntellisenseObject> ProcessFile(ProjectItem item, HashSet<CodeClass> underProcess = null)
20+
internal static IEnumerable<IntellisenseObject> ProcessFile(ProjectItem item, HashSet<CodeClass> underProcess = null)
2121
{
2222
if (item.FileCodeModel == null || item.ContainingProject == null)
2323
return null;
@@ -267,7 +267,7 @@ private static IntellisenseType GetType(CodeClass rootElement, CodeTypeRef codeT
267267
var codeClass = effectiveTypeRef.CodeType as CodeClass2;
268268
var codeEnum = effectiveTypeRef.CodeType as CodeEnum;
269269
var isPrimitive = IsPrimitive(effectiveTypeRef);
270-
VSHelpers.WriteOnBuildDebugWindow($"###{effectiveTypeRef.CodeType.GetType().FullName}");
270+
//VSHelpers.WriteOnBuildDebugWindow($"###{effectiveTypeRef.CodeType.GetType().FullName}");
271271

272272
var result = new IntellisenseType
273273
{
@@ -276,31 +276,21 @@ private static IntellisenseType GetType(CodeClass rootElement, CodeTypeRef codeT
276276
CodeName = effectiveTypeRef.AsString
277277
};
278278

279-
VSHelpers.WriteOnBuildDebugWindow($"#{result.CodeName}#{result.TypeScriptName}#{effectiveTypeRef.AsString}#{effectiveTypeRef.AsFullName}#{effectiveTypeRef.CodeType}");
280-
VSHelpers.WriteOnBuildDebugWindow($"##{effectiveTypeRef.TypeKind}##{vsCMTypeRef.vsCMTypeRefCodeType}##{effectiveTypeRef.CodeType.InfoLocation}##{vsCMInfoLocation.vsCMInfoLocationProject}");
279+
//VSHelpers.WriteOnBuildDebugWindow($"#{result.CodeName}#{result.TypeScriptName}#{effectiveTypeRef.AsString}#{effectiveTypeRef.AsFullName}#{effectiveTypeRef.CodeType}");
280+
//VSHelpers.WriteOnBuildDebugWindow($"##{effectiveTypeRef.TypeKind}##{vsCMTypeRef.vsCMTypeRefCodeType}##{effectiveTypeRef.CodeType.InfoLocation}##{vsCMInfoLocation.vsCMInfoLocationProject}");
281281
if (effectiveTypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefCodeType)
282282
{
283+
var hasIntellisense = Options.IgnoreIntellisense;
283284
if (effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject)
284285
{
285286
if (codeClass != null)
286-
HasIntellisense(codeClass.ProjectItem, references);
287+
hasIntellisense = HasIntellisense(codeClass.ProjectItem, references);
287288
if (codeEnum != null)
288-
HasIntellisense(codeEnum.ProjectItem, references);
289+
hasIntellisense = HasIntellisense(codeEnum.ProjectItem, references);
289290
}
290291

291-
result.ClientSideReferenceName = (codeClass != null ? (GetNamespace(codeClass) + "." + Utility.CamelCaseClassName(GetClassName(codeClass))) : null) ??
292-
(codeEnum != null ? (GetNamespace(codeEnum) + "." + Utility.CamelCaseClassName(codeEnum.Name)) : null);
293-
//if (effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationProject)
294-
//{
295-
// result.ClientSideReferenceName = (codeClass != null && HasIntellisense(codeClass.ProjectItem, references) ? (GetNamespace(codeClass) + "." + Utility.CamelCaseClassName(GetClassName(codeClass))) : null) ??
296-
// (codeEnum != null && HasIntellisense(codeEnum.ProjectItem, references) ? (GetNamespace(codeEnum) + "." + Utility.CamelCaseClassName(codeEnum.Name)) : null);
297-
//}
298-
//if (effectiveTypeRef.CodeType.InfoLocation == vsCMInfoLocation.vsCMInfoLocationExternal)
299-
//{
300-
// result.ClientSideReferenceName = (codeClass != null ? (GetNamespace(codeClass) + "." + Utility.CamelCaseClassName(GetClassName(codeClass))) : null) ??
301-
// (codeEnum != null ? (GetNamespace(codeEnum) + "." + Utility.CamelCaseClassName(codeEnum.Name)) : null);
302-
//}
303-
// VSHelpers.WriteOnOutputWindow($"@@{GetNamespace(codeEnum)}@{Utility.CamelCaseClassName(codeEnum.Name)}");
292+
result.ClientSideReferenceName = (codeClass != null && hasIntellisense ? (GetNamespace(codeClass) + "." + Utility.CamelCaseClassName(GetClassName(codeClass))) : null) ??
293+
(codeEnum != null && hasIntellisense ? (GetNamespace(codeEnum) + "." + Utility.CamelCaseClassName(codeEnum.Name)) : null);
304294
}
305295
else result.ClientSideReferenceName = null;
306296

src/TypeScriptDefinitionGenerator/Options.cs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ public class OptionsDialogPage : DialogPage
1212
internal const bool _defCamelCaseEnumerationValues = false;
1313
internal const bool _defCamelCasePropertyNames = true;
1414
internal const bool _defCamelCaseTypeNames = false;
15+
16+
internal const bool _defWebEssentials2015 = false;
17+
1518
internal const bool _defClassInsteadOfInterface = false;
16-
internal const bool _defGlobalScope = false;
17-
internal const bool _defExport = false;
18-
internal const bool _defWebEssentials2015 = true;
1919
internal const string _defModuleName = "Server.Dtos";
20+
internal const bool _defExport = false;
21+
internal const bool _defGlobalScope = false;
22+
internal const bool _defIgnoreIntellisense = true;
2023

2124
[Category("Casing")]
2225
[DisplayName("Camel case enum values")]
@@ -56,7 +59,12 @@ public class OptionsDialogPage : DialogPage
5659
[DefaultValue(_defExport)]
5760
public bool Export { get; set; } = _defExport;
5861

59-
62+
[Category("Settings")]
63+
[DisplayName("Ignore intellisense")]
64+
[Description("Ignore intellisense for client side reference names")]
65+
[DefaultValue(_defIgnoreIntellisense)]
66+
public bool IgnoreIntellisense { get; set; } = _defIgnoreIntellisense;
67+
6068
[Category("Compatibilty")]
6169
[DisplayName("Web Esentials 2015 file names")]
6270
[Description("Web Essentials 2015 format is <filename>.cs.d.ts instead of <filename>.d.ts")]
@@ -68,63 +76,71 @@ public class Options
6876
{
6977
const string OVERRIDE_FILE_NAME = "tsdefgen.json";
7078
static OptionsOverride overrides { get; set; } = null;
71-
static public bool CamelCaseEnumerationValues
79+
public static bool CamelCaseEnumerationValues
7280
{
7381
get
7482
{
7583
return overrides != null ? overrides.CamelCaseEnumerationValues : DtsPackage.Options.CamelCaseEnumerationValues;
7684
}
7785
}
7886

79-
static public bool CamelCasePropertyNames
87+
public static bool CamelCasePropertyNames
8088
{
8189
get
8290
{
8391
return overrides != null ? overrides.CamelCasePropertyNames : DtsPackage.Options.CamelCasePropertyNames;
8492
}
8593
}
8694

87-
static public bool CamelCaseTypeNames
95+
public static bool CamelCaseTypeNames
8896
{
8997
get
9098
{
9199
return overrides != null ? overrides.CamelCaseTypeNames : DtsPackage.Options.CamelCaseTypeNames;
92100
}
93101
}
94-
//todo:设置为服务器命名空间
95-
static public string DefaultModuleName
102+
//todo: set to server namespace
103+
public static string DefaultModuleName
96104
{
97105
get
98106
{
99107
return overrides != null ? overrides.DefaultModuleName : DtsPackage.Options.DefaultModuleName;
100108
}
101109
}
102110

103-
static public bool ClassInsteadOfInterface
111+
public static bool ClassInsteadOfInterface
104112
{
105113
get
106114
{
107115
return overrides != null ? overrides.ClassInsteadOfInterface : DtsPackage.Options.ClassInsteadOfInterface;
108116
}
109117
}
110118

111-
static public bool GlobalScope
119+
public static bool GlobalScope
112120
{
113121
get
114122
{
115123
return overrides != null ? overrides.GlobalScope : DtsPackage.Options.GlobalScope;
116124
}
117125
}
118126

119-
static public bool Export
127+
public static bool Export
120128
{
121129
get
122130
{
123131
return overrides != null ? overrides.Export : DtsPackage.Options.Export;
124132
}
125133
}
126134

127-
static public bool WebEssentials2015
135+
public static bool IgnoreIntellisense
136+
{
137+
get
138+
{
139+
return overrides != null ? overrides.IgnoreIntellisense : DtsPackage.Options.IgnoreIntellisense;
140+
}
141+
}
142+
143+
public static bool WebEssentials2015
128144
{
129145
get
130146
{
@@ -184,13 +200,13 @@ public static void ReadOptionOverrides(ProjectItem sourceItem, bool display = tr
184200
}
185201
}
186202

187-
public static void SetOptionsOverrides(OptionsOverride optionsOverride)
203+
internal static void SetOptionsOverrides(OptionsOverride optionsOverride)
188204
{
189205
overrides = optionsOverride;
190206
}
191207
}
192208

193-
public class OptionsOverride
209+
internal class OptionsOverride
194210
{
195211
// [JsonRequired]
196212
public bool CamelCaseEnumerationValues { get; set; } = OptionsDialogPage._defCamelCaseEnumerationValues;
@@ -213,6 +229,9 @@ public class OptionsOverride
213229
// [JsonRequired]
214230
public bool Export { get; set; } = OptionsDialogPage._defExport;
215231

232+
// [JsonRequired]
233+
public bool IgnoreIntellisense { get; set; } = OptionsDialogPage._defIgnoreIntellisense;
234+
216235
// [JsonRequired]
217236
public bool WebEssentials2015 { get; set; } = OptionsDialogPage._defWebEssentials2015;
218237

tests/TypeScriptDefinitionGenerator.Tests/IntellisenseParserTest.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public void _ShouldWorkProperly()
4848
ProjectItem item = worker.GetProjectItem(dte2.Solution, "Class1.cs");
4949

5050
//Act
51-
//string dts = GenerationService.ConvertToTypeScript(item);
52-
//var res = Encoding.UTF8.GetBytes(dts);
53-
54-
//string dts = GenerationService.ConvertToTypeScript(item);
5551
Options.SetOptionsOverrides(new OptionsOverride()
5652
{
5753
CamelCaseEnumerationValues = false,
@@ -64,6 +60,7 @@ public void _ShouldWorkProperly()
6460
DefaultModuleName = "Server.Dtos",
6561
Export = false,
6662
GlobalScope = false,
63+
IgnoreIntellisense = true,
6764
});
6865
var list = IntellisenseParser.ProcessFile(item).ToList();
6966

0 commit comments

Comments
 (0)