diff --git a/src/Lepiter-Snippet-Example/LeExampleSnippet.class.st b/src/Lepiter-Snippet-Example/LeExampleSnippet.class.st index 795f3e8d0..a2c397d38 100644 --- a/src/Lepiter-Snippet-Example/LeExampleSnippet.class.st +++ b/src/Lepiter-Snippet-Example/LeExampleSnippet.class.st @@ -128,6 +128,17 @@ LeExampleSnippet >> contentAsString [ ^ '{{gtExample:', self asAnnotationString, '}}' ] +{ #category : #'api - accessing' } +LeExampleSnippet >> copyFrom: aLeExampleSnippet [ + self codeExpanded: aLeExampleSnippet codeExpanded. + self exampleBehaviorName: aLeExampleSnippet exampleBehaviorName. + self exampleSelector: aLeExampleSnippet exampleSelector. + self noCode: aLeExampleSnippet noCode. + self previewExpanded: aLeExampleSnippet previewExpanded. + self previewHeight: aLeExampleSnippet previewHeight. + self previewShowSelector: aLeExampleSnippet previewShowSelector. +] + { #category : #initialization } LeExampleSnippet >> defaultCodeExpanded [ ^ true diff --git a/src/Lepiter-Snippet-Example/LeExampleSnippetAnnotationValidator.class.st b/src/Lepiter-Snippet-Example/LeExampleSnippetAnnotationValidator.class.st new file mode 100644 index 000000000..ec574f9e1 --- /dev/null +++ b/src/Lepiter-Snippet-Example/LeExampleSnippetAnnotationValidator.class.st @@ -0,0 +1,44 @@ +Class { + #name : #LeExampleSnippetAnnotationValidator, + #superclass : #Object, + #traits : 'TLeAnnotationParseNodeVisitor', + #classTraits : 'TLeAnnotationParseNodeVisitor classTrait', + #instVars : [ + 'isValid' + ], + #category : #'Lepiter-Snippet-Example-Snippet' +} + +{ #category : #initialization } +LeExampleSnippetAnnotationValidator >> initialize [ + super initialize. + + isValid := true +] + +{ #category : #accessing } +LeExampleSnippetAnnotationValidator >> isValid [ + ^ isValid +] + +{ #category : #accessing } +LeExampleSnippetAnnotationValidator >> validate: anAst [ + isValid := true. + self accept: anAst. + ^ self isValid +] + +{ #category : #visiting } +LeExampleSnippetAnnotationValidator >> visitCodeExpandedArgument: aCodeExpandedArgument [ + isValid := isValid and: [ aCodeExpandedArgument hasValidBooleanValue ] +] + +{ #category : #generated } +LeExampleSnippetAnnotationValidator >> visitNoCodeArgument: aNoCodeArgument [ + isValid := isValid and: [ aNoCodeArgument hasValidBooleanValue ] +] + +{ #category : #generated } +LeExampleSnippetAnnotationValidator >> visitPreviewExpandedArgument: aPreviewExpandedArgument [ + isValid := isValid and: [ aPreviewExpandedArgument hasValidBooleanValue ] +] diff --git a/src/Lepiter-Snippet-Example/LeExampleSnippetAnnotationVisitor.class.st b/src/Lepiter-Snippet-Example/LeExampleSnippetAnnotationVisitor.class.st index acfe37715..45bab58c5 100644 --- a/src/Lepiter-Snippet-Example/LeExampleSnippetAnnotationVisitor.class.st +++ b/src/Lepiter-Snippet-Example/LeExampleSnippetAnnotationVisitor.class.st @@ -51,7 +51,7 @@ LeExampleSnippetAnnotationVisitor >> visitNoCodeArgument: aNoCodeArgument [ LeExampleSnippetAnnotationVisitor >> visitPreviewExpandedArgument: aPreviewExpandedArgument [ aPreviewExpandedArgument hasValidBooleanValue ifFalse: [ ^ self ]. - + self exampleSnippet previewExpanded: aPreviewExpandedArgument booleanValue ] diff --git a/src/Lepiter-Snippet-Example/LeExampleSnippetViewModel.class.st b/src/Lepiter-Snippet-Example/LeExampleSnippetViewModel.class.st index cdfe5ca78..f6702725e 100644 --- a/src/Lepiter-Snippet-Example/LeExampleSnippetViewModel.class.st +++ b/src/Lepiter-Snippet-Example/LeExampleSnippetViewModel.class.st @@ -200,7 +200,7 @@ LeExampleSnippetViewModel >> notifyAnnotationCoderViewModelChanged [ { #category : #'private - event handling' } LeExampleSnippetViewModel >> onAnnotationAstChanged: anAstChangedAnnouncement [ - | anAst | + | anAst aNewSnippet | anAst := anAstChangedAnnouncement ast. anAst @@ -208,15 +208,27 @@ LeExampleSnippetViewModel >> onAnnotationAstChanged: anAstChangedAnnouncement [ andTokensDo: [ :eachToken | ] includeErrors: true. + aNewSnippet := LeExampleSnippet new. + + "this will modify the properties of a default snippet while making sure that removing properties falls back to default" + LeExampleSnippetAnnotationVisitor new + exampleSnippet: aNewSnippet; + accept: anAst. + + "if properties did not change, do nothing" + (self snippetModel similarTo: aNewSnippet) + ifTrue: [ ^ self ]. + "it is possible that multiple parameters were changes as part of the ast update. we should queue them up and request annotation update only once at the very end" self optionAt: #doNotUpdateText put: true. [ - LeExampleSnippetAnnotationVisitor new - exampleSnippet: self; - accept: anAst. + self snippetModel copyFrom: aNewSnippet ] ensure: [ self optionAt: #doNotUpdateText put: false ]. - + + (LeExampleSnippetAnnotationValidator new validate: anAst) + ifFalse: [ ^ self ]. + self requestUpdateAnnotationText ]