1111
1212namespace TypeScriptDefinitionGenerator
1313{
14- public static class IntellisenseParser
14+ internal static class IntellisenseParser
1515 {
16- private static string DefaultModuleName = Options . DefaultModuleName ;
1716 private const string ModuleNameAttributeName = "TypeScriptModule" ;
1817 private static readonly Regex IsNumber = new Regex ( "^[0-9a-fx]+[ul]{0,2}$" , RegexOptions . IgnoreCase | RegexOptions . Compiled ) ;
1918 private static Project _project ;
2019
21- //internal static class Ext
22- //{
23- // public const string TypeScript = ".d.ts";
24- //}
25-
2620 internal static IEnumerable < IntellisenseObject > ProcessFile ( ProjectItem item , HashSet < CodeClass > underProcess = null )
2721 {
2822 if ( item . FileCodeModel == null || item . ContainingProject == null )
@@ -239,7 +233,7 @@ private static string GetDataContractName(CodeClass cc, string attrName)
239233
240234 private static string GetNamespace ( CodeElements attrs )
241235 {
242- if ( attrs == null ) return DefaultModuleName ;
236+ if ( attrs == null ) return Options . DefaultModuleName ;
243237
244238 var namespaceFromAttr = from a in attrs . Cast < CodeAttribute2 > ( )
245239 where a . Name . EndsWith ( ModuleNameAttributeName , StringComparison . OrdinalIgnoreCase )
@@ -248,7 +242,7 @@ from arg in a.Arguments.Cast<CodeAttributeArgument>()
248242 where ! string . IsNullOrWhiteSpace ( v )
249243 select v ;
250244
251- return namespaceFromAttr . FirstOrDefault ( ) ?? DefaultModuleName ;
245+ return namespaceFromAttr . FirstOrDefault ( ) ?? Options . DefaultModuleName ;
252246 }
253247
254248 private static IntellisenseType GetType ( CodeClass rootElement , CodeTypeRef codeTypeRef , HashSet < string > traversedTypes , HashSet < string > references )
@@ -270,25 +264,37 @@ private static IntellisenseType GetType(CodeClass rootElement, CodeTypeRef codeT
270264
271265 try
272266 {
273-
274267 var codeClass = effectiveTypeRef . CodeType as CodeClass2 ;
275268 var codeEnum = effectiveTypeRef . CodeType as CodeEnum ;
276269 var isPrimitive = IsPrimitive ( effectiveTypeRef ) ;
270+ //VSHelpers.WriteOnBuildDebugWindow($"###{effectiveTypeRef.CodeType.GetType().FullName}");
277271
278272 var result = new IntellisenseType
279273 {
280274 IsArray = ! isDictionary && ( isArray || isCollection ) ,
281275 IsDictionary = isDictionary ,
282276 CodeName = effectiveTypeRef . AsString
283277 } ;
284- if ( effectiveTypeRef . TypeKind == vsCMTypeRef . vsCMTypeRefCodeType && effectiveTypeRef . CodeType . InfoLocation == vsCMInfoLocation . vsCMInfoLocationProject )
278+
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}");
281+ if ( effectiveTypeRef . TypeKind == vsCMTypeRef . vsCMTypeRefCodeType )
285282 {
286- result . ClientSideReferenceName = ( codeClass != null && HasIntellisense ( codeClass . ProjectItem , references ) ? ( GetNamespace ( codeClass ) + "." + Utility . CamelCaseClassName ( GetClassName ( codeClass ) ) ) : null ) ??
287- ( codeEnum != null && HasIntellisense ( codeEnum . ProjectItem , references ) ? ( GetNamespace ( codeEnum ) + "." + Utility . CamelCaseClassName ( codeEnum . Name ) ) : null ) ;
283+ var hasIntellisense = Options . IgnoreIntellisense ;
284+ if ( effectiveTypeRef . CodeType . InfoLocation == vsCMInfoLocation . vsCMInfoLocationProject )
285+ {
286+ if ( codeClass != null )
287+ hasIntellisense = HasIntellisense ( codeClass . ProjectItem , references ) ;
288+ if ( codeEnum != null )
289+ hasIntellisense = HasIntellisense ( codeEnum . ProjectItem , references ) ;
290+ }
291+
292+ result . ClientSideReferenceName = ( codeClass != null && hasIntellisense ? ( GetNamespace ( codeClass ) + "." + Utility . CamelCaseClassName ( GetClassName ( codeClass ) ) ) : null ) ??
293+ ( codeEnum != null && hasIntellisense ? ( GetNamespace ( codeEnum ) + "." + Utility . CamelCaseClassName ( codeEnum . Name ) ) : null ) ;
288294 }
289295 else result . ClientSideReferenceName = null ;
290296
291- if ( ! isPrimitive && codeClass != null && ! traversedTypes . Contains ( effectiveTypeRef . CodeType . FullName ) && ! isCollection )
297+ if ( ! isPrimitive && ( codeClass != null || codeEnum != null ) && ! traversedTypes . Contains ( effectiveTypeRef . CodeType . FullName ) && ! isCollection )
292298 {
293299 traversedTypes . Add ( effectiveTypeRef . CodeType . FullName ) ;
294300 result . Shape = GetProperties ( effectiveTypeRef . CodeType . Members , traversedTypes , references ) . ToList ( ) ;
@@ -373,7 +379,7 @@ private static bool HasIntellisense(ProjectItem projectItem, HashSet<string> ref
373379 {
374380 for ( short i = 0 ; i < projectItem . FileCount ; i ++ )
375381 {
376- var fileName = GenerationService . GenerateFileName ( projectItem . FileNames [ i ] ) ;
382+ var fileName = Utility . GenerateFileName ( projectItem . FileNames [ i ] ) ;
377383
378384 references . Add ( fileName ) ;
379385 return true ;
0 commit comments