@@ -24,15 +24,15 @@ export abstract class XmlSuggestionProvider<T> {
2424 attribute ?: XMLAttribute
2525 ) : T [ ] ;
2626
27- public getConfigKey ( ) : string | undefined {
27+ protected getConfigKey ( ) : string | undefined {
2828 return undefined ;
2929 }
3030
31- public getAttributeValueConditions ( ) : CombinedCondition [ ] {
31+ protected getAttributeValueConditions ( ) : CombinedCondition [ ] {
3232 return [ ] ;
3333 }
3434
35- public getElementContentMatches ( ) : CombinedCondition [ ] {
35+ protected getElementContentMatches ( ) : CombinedCondition [ ] {
3636 return [ ] ;
3737 }
3838
@@ -48,22 +48,18 @@ export abstract class XmlSuggestionProvider<T> {
4848 return this . processSuggestions ( document , position , tokenData ) ;
4949 }
5050
51- public getSuggestionProviders ( document : TextDocument ) : SuggestionProviders < T > {
51+ protected getSuggestionProviders ( document : TextDocument ) : SuggestionProviders < T > {
5252 return {
5353 attributeValue : [ options => this . getAttributeValueSuggestionProviders ( document , options ) ] ,
5454 elementContent : [ options => this . getElementContentSuggestionProviders ( document , options ) ] ,
5555 } ;
5656 }
5757
58- public getAttributeValueSuggestionProviders (
58+ protected getAttributeValueSuggestionProviders (
5959 document : TextDocument ,
6060 { element, attribute } : AttributeValueCompletionOptions < undefined >
6161 ) : T [ ] {
62- const match = this . getAttributeValueConditions ( ) . find ( matchElement => {
63- return this . matchesConditions ( matchElement , element , attribute ) ;
64- } ) ;
65-
66- if ( ! match ) {
62+ if ( ! this . hasMatchingCondition ( this . getAttributeValueConditions ( ) , element , attribute ) ) {
6763 return [ ] ;
6864 }
6965
@@ -81,15 +77,11 @@ export abstract class XmlSuggestionProvider<T> {
8177 return this . getSuggestionItems ( value , range , document , element , attribute ) ;
8278 }
8379
84- public getElementContentSuggestionProviders (
80+ protected getElementContentSuggestionProviders (
8581 document : TextDocument ,
8682 { element } : ElementContentCompletionOptions < undefined >
8783 ) : T [ ] {
88- const match = this . getElementContentMatches ( ) . find ( matchElement => {
89- return this . matchesConditions ( matchElement , element ) ;
90- } ) ;
91-
92- if ( ! match ) {
84+ if ( ! this . hasMatchingCondition ( this . getElementContentMatches ( ) , element ) ) {
9385 return [ ] ;
9486 }
9587
@@ -108,6 +100,16 @@ export abstract class XmlSuggestionProvider<T> {
108100 return this . getSuggestionItems ( elementValue , range , document , element ) ;
109101 }
110102
103+ protected hasMatchingCondition (
104+ conditions : CombinedCondition [ ] ,
105+ element : XMLElement ,
106+ attribute ?: XMLAttribute
107+ ) : boolean {
108+ return conditions . some ( condition => {
109+ return this . matchesConditions ( condition , element , attribute ) ;
110+ } ) ;
111+ }
112+
111113 protected matchesConditions (
112114 conditions : CombinedCondition ,
113115 element : XMLElement ,
@@ -139,8 +141,10 @@ export abstract class XmlSuggestionProvider<T> {
139141 }
140142 }
141143
142- return this . getFilePatterns ( ) . some ( pattern =>
143- minimatch ( document . uri . fsPath , pattern , { matchBase : true } )
144- ) ;
144+ return this . isMatchingFile ( document , this . getFilePatterns ( ) ) ;
145+ }
146+
147+ protected isMatchingFile ( document : TextDocument , patterns : string [ ] ) : boolean {
148+ return patterns . some ( pattern => minimatch ( document . uri . fsPath , pattern , { matchBase : true } ) ) ;
145149 }
146150}
0 commit comments