@@ -130,6 +130,9 @@ void RegisterTypeScript(IncrementalGeneratorInitializationContext context)
130130 var typeScriptEnabled = context . AnalyzerConfigOptionsProvider
131131 . Select ( ( configOptions , token ) =>
132132 {
133+ // https://github.com/dotnet/project-system/blob/main/docs/design-time-builds.md
134+ var isDesignTimeBuild = configOptions . GlobalOptions . TryGetValue ( "build_property.DesignTimeBuild" , out var designTimeBuild ) && designTimeBuild == "true" ;
135+
133136 string ? path ;
134137 if ( ! configOptions . GlobalOptions . TryGetValue ( "build_property.MemoryPackGenerator_TypeScriptOutputDirectory" , out path ) )
135138 {
@@ -161,7 +164,8 @@ void RegisterTypeScript(IncrementalGeneratorInitializationContext context)
161164 OutputDirectory = path ,
162165 ImportExtension = ext ,
163166 ConvertPropertyName = convert ,
164- EnableNullableTypes = bool . TryParse ( enableNullableTypes , out var enabledNullableTypesParsed ) && enabledNullableTypesParsed
167+ EnableNullableTypes = bool . TryParse ( enableNullableTypes , out var enabledNullableTypesParsed ) && enabledNullableTypesParsed ,
168+ IsDesignTimeBuild = isDesignTimeBuild
165169 } ;
166170 } ) ;
167171
@@ -193,6 +197,10 @@ or RecordDeclarationSyntax
193197 var unionMap = new Dictionary < ITypeSymbol , ITypeSymbol > ( SymbolEqualityComparer . Default ) ; // <impl, base>
194198 foreach ( var item in source )
195199 {
200+ var tsOptions = item . Right ;
201+ if ( tsOptions == null ) continue ;
202+ if ( tsOptions . IsDesignTimeBuild ) continue ; // designtime build(in IDE), do nothing.
203+
196204 var syntax = item . Left . Item1 ;
197205 var compilation = item . Left . Item2 ;
198206 var semanticModel = compilation . GetSemanticModel ( syntax . SyntaxTree ) ;
@@ -203,7 +211,7 @@ or RecordDeclarationSyntax
203211 reference = new ReferenceSymbols ( compilation ) ;
204212 }
205213
206- if ( generatePath is null && item . Right is { } options )
214+ if ( generatePath is null && item . Right is { } options )
207215 {
208216 generatePath = options . OutputDirectory ;
209217 }
@@ -223,26 +231,26 @@ or RecordDeclarationSyntax
223231 }
224232 }
225233
226- var collector = new TypeCollector ( ) ;
227- foreach ( var item in source )
234+ if ( generatePath != null )
228235 {
229- var typeDeclaration = item . Left . Item1 ;
230- var compilation = item . Left . Item2 ;
231-
232- if ( reference == null )
236+ var collector = new TypeCollector ( ) ;
237+ foreach ( var item in source )
233238 {
234- reference = new ReferenceSymbols ( compilation ) ;
235- }
239+ var typeDeclaration = item . Left . Item1 ;
240+ var compilation = item . Left . Item2 ;
236241
237- var meta = GenerateTypeScript ( typeDeclaration , compilation , item . Right ! , context , reference , unionMap ) ;
238- if ( meta != null )
239- {
240- collector . Visit ( meta , false ) ;
242+ if ( reference == null )
243+ {
244+ reference = new ReferenceSymbols ( compilation ) ;
245+ }
246+
247+ var meta = GenerateTypeScript ( typeDeclaration , compilation , item . Right ! , context , reference , unionMap ) ;
248+ if ( meta != null )
249+ {
250+ collector . Visit ( meta , false ) ;
251+ }
241252 }
242- }
243253
244- if ( generatePath != null )
245- {
246254 GenerateEnums ( collector . GetEnums ( ) , generatePath ) ;
247255
248256 // generate runtime
0 commit comments