5
5
6
6
import { URI } from '../../../../../../base/common/uri.js' ;
7
7
import { IFileService , IFileStatWithMetadata , IResolveMetadataFileOptions } from '../../../../../../platform/files/common/files.js' ;
8
- import { TerminalCompletionService , TerminalResourceRequestConfig } from '../../browser/terminalCompletionService.js' ;
8
+ import { TerminalCompletionService , TerminalResourceRequestConfig , type ITerminalCompletionProvider } from '../../browser/terminalCompletionService.js' ;
9
9
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/test/common/utils.js' ;
10
10
import assert , { fail } from 'assert' ;
11
11
import { isWindows , type IProcessEnvironment } from '../../../../../../base/common/platform.js' ;
@@ -21,6 +21,7 @@ import { count } from '../../../../../../base/common/strings.js';
21
21
import { WindowsShellType } from '../../../../../../platform/terminal/common/terminal.js' ;
22
22
import { gitBashToWindowsPath , windowsToGitBashPath } from '../../browser/terminalGitBashHelpers.js' ;
23
23
import { ILogService , NullLogService } from '../../../../../../platform/log/common/log.js' ;
24
+ import { TerminalSuggestSettingId } from '../../common/terminalSuggestConfiguration.js' ;
24
25
25
26
const pathSeparator = isWindows ? '\\' : '/' ;
26
27
@@ -770,4 +771,106 @@ suite('TerminalCompletionService', () => {
770
771
} ) ;
771
772
772
773
} ) ;
774
+
775
+ suite ( 'Provider Configuration' , ( ) => {
776
+ // Test class that extends TerminalCompletionService to access protected methods
777
+ class TestTerminalCompletionService extends TerminalCompletionService {
778
+ public getEnabledProviders ( providers : ITerminalCompletionProvider [ ] ) : ITerminalCompletionProvider [ ] {
779
+ return super . _getEnabledProviders ( providers ) ;
780
+ }
781
+ }
782
+
783
+ let testTerminalCompletionService : TestTerminalCompletionService ;
784
+
785
+ setup ( ( ) => {
786
+ testTerminalCompletionService = store . add ( instantiationService . createInstance ( TestTerminalCompletionService ) ) ;
787
+ } ) ;
788
+
789
+ // Mock provider for testing
790
+ function createMockProvider ( id : string ) : ITerminalCompletionProvider {
791
+ return {
792
+ id,
793
+ provideCompletions : async ( ) => [ {
794
+ label : `completion-from-${ id } ` ,
795
+ kind : TerminalCompletionItemKind . Method ,
796
+ replacementIndex : 0 ,
797
+ replacementLength : 0 ,
798
+ provider : id
799
+ } ]
800
+ } ;
801
+ }
802
+
803
+ test ( 'should enable providers by default when no configuration exists' , ( ) => {
804
+ const defaultProvider = createMockProvider ( 'terminal-suggest' ) ;
805
+ const newProvider = createMockProvider ( 'new-extension-provider' ) ;
806
+ const providers = [ defaultProvider , newProvider ] ;
807
+
808
+ // Set empty configuration (no provider keys)
809
+ configurationService . setUserConfiguration ( TerminalSuggestSettingId . Providers , { } ) ;
810
+
811
+ const result = testTerminalCompletionService . getEnabledProviders ( providers ) ;
812
+
813
+ // Both providers should be enabled since they're not explicitly disabled
814
+ assert . strictEqual ( result . length , 2 , 'Should enable both providers by default' ) ;
815
+ assert . ok ( result . includes ( defaultProvider ) , 'Should include default provider' ) ;
816
+ assert . ok ( result . includes ( newProvider ) , 'Should include new provider' ) ;
817
+ } ) ;
818
+
819
+ test ( 'should disable providers when explicitly set to false' , ( ) => {
820
+ const provider1 = createMockProvider ( 'provider1' ) ;
821
+ const provider2 = createMockProvider ( 'provider2' ) ;
822
+ const providers = [ provider1 , provider2 ] ;
823
+
824
+ // Disable provider1, leave provider2 unconfigured
825
+ configurationService . setUserConfiguration ( TerminalSuggestSettingId . Providers , {
826
+ 'provider1' : false
827
+ } ) ;
828
+
829
+ const result = testTerminalCompletionService . getEnabledProviders ( providers ) ;
830
+
831
+ // Only provider2 should be enabled
832
+ assert . strictEqual ( result . length , 1 , 'Should enable only one provider' ) ;
833
+ assert . ok ( result . includes ( provider2 ) , 'Should include unconfigured provider' ) ;
834
+ assert . ok ( ! result . includes ( provider1 ) , 'Should not include disabled provider' ) ;
835
+ } ) ;
836
+
837
+ test ( 'should enable providers when explicitly set to true' , ( ) => {
838
+ const provider1 = createMockProvider ( 'provider1' ) ;
839
+ const provider2 = createMockProvider ( 'provider2' ) ;
840
+ const providers = [ provider1 , provider2 ] ;
841
+
842
+ // Explicitly enable provider1, leave provider2 unconfigured
843
+ configurationService . setUserConfiguration ( TerminalSuggestSettingId . Providers , {
844
+ 'provider1' : true
845
+ } ) ;
846
+
847
+ const result = testTerminalCompletionService . getEnabledProviders ( providers ) ;
848
+
849
+ // Both providers should be enabled
850
+ assert . strictEqual ( result . length , 2 , 'Should enable both providers' ) ;
851
+ assert . ok ( result . includes ( provider1 ) , 'Should include explicitly enabled provider' ) ;
852
+ assert . ok ( result . includes ( provider2 ) , 'Should include unconfigured provider' ) ;
853
+ } ) ;
854
+
855
+ test ( 'should handle mixed configuration correctly' , ( ) => {
856
+ const provider1 = createMockProvider ( 'provider1' ) ;
857
+ const provider2 = createMockProvider ( 'provider2' ) ;
858
+ const provider3 = createMockProvider ( 'provider3' ) ;
859
+ const providers = [ provider1 , provider2 , provider3 ] ;
860
+
861
+ // Mixed configuration: enable provider1, disable provider2, leave provider3 unconfigured
862
+ configurationService . setUserConfiguration ( TerminalSuggestSettingId . Providers , {
863
+ 'provider1' : true ,
864
+ 'provider2' : false
865
+ } ) ;
866
+
867
+ const result = testTerminalCompletionService . getEnabledProviders ( providers ) ;
868
+
869
+ // provider1 and provider3 should be enabled, provider2 should be disabled
870
+ assert . strictEqual ( result . length , 2 , 'Should enable two providers' ) ;
871
+ assert . ok ( result . includes ( provider1 ) , 'Should include explicitly enabled provider' ) ;
872
+ assert . ok ( result . includes ( provider3 ) , 'Should include unconfigured provider' ) ;
873
+ assert . ok ( ! result . includes ( provider2 ) , 'Should not include disabled provider' ) ;
874
+ } ) ;
875
+ } ) ;
773
876
} ) ;
0 commit comments