22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5+ import * as Host from '../../core/host/host.js' ;
56import * as SDK from '../../core/sdk/sdk.js' ;
67import * as Protocol from '../../generated/protocol.js' ;
78import * as ComputedStyle from '../../models/computed_style/computed_style.js' ;
@@ -35,6 +36,11 @@ describe('StylesSidebarPane', () => {
3536 const target = createTarget ( ) ;
3637 const cssModel = target . model ( SDK . CSSModel . CSSModel ) ;
3738 sinon . stub ( ComputedStyle . ComputedStyleModel . ComputedStyleModel . prototype , 'cssModel' ) . returns ( cssModel ) ;
39+ sinon . stub ( Host . AidaClient . HostConfigTracker , 'instance' ) . returns ( {
40+ addEventListener : ( ) => { } ,
41+ removeEventListener : ( ) => { } ,
42+ dispose : ( ) => { } ,
43+ } as unknown as Host . AidaClient . HostConfigTracker ) ;
3844 } ) ;
3945
4046 it ( 'unescapes CSS strings' , ( ) => {
@@ -1241,6 +1247,8 @@ describe('StylesSidebarPane', () => {
12411247 '--wide-gamut-color' : 'lch(0 0 0)' ,
12421248 } ;
12431249
1250+ let aiCodeCompletionProvider :
1251+ sinon . SinonStubbedInstance < Elements . StylesAiCodeCompletionProvider . StylesAiCodeCompletionProvider > ;
12441252 let section : sinon . SinonStubbedInstance < Elements . StylePropertiesSection . StylePropertiesSection > ;
12451253 let mockTreeItem : Elements . StylePropertyTreeElement . StylePropertyTreeElement ;
12461254
@@ -1298,6 +1306,9 @@ describe('StylesSidebarPane', () => {
12981306 const pane = sinon . createStubInstance ( Elements . StylesSidebarPane . StylesSidebarPane ) ;
12991307 const cssModel = sinon . createStubInstance ( SDK . CSSModel . CSSModel ) ;
13001308 pane . cssModel . returns ( cssModel ) ;
1309+ aiCodeCompletionProvider =
1310+ sinon . createStubInstance ( Elements . StylesAiCodeCompletionProvider . StylesAiCodeCompletionProvider ) ;
1311+ pane . aiCodeCompletionProvider = aiCodeCompletionProvider ;
13011312 return pane ;
13021313 }
13031314 } as unknown as Elements . StylePropertyTreeElement . StylePropertyTreeElement ;
@@ -1382,8 +1393,6 @@ describe('StylesSidebarPane', () => {
13821393 } ) ;
13831394
13841395 describe ( 'AI code completion' , ( ) => {
1385- let aiCodeCompletionProvider :
1386- sinon . SinonStubbedInstance < Elements . StylesAiCodeCompletionProvider . StylesAiCodeCompletionProvider > ;
13871396 let attachedElement : HTMLDivElement ;
13881397 let cssPropertyPrompt : Elements . StylesSidebarPane . CSSPropertyPrompt ;
13891398
@@ -1399,11 +1408,6 @@ describe('StylesSidebarPane', () => {
13991408 }
14001409 } ) ;
14011410
1402- aiCodeCompletionProvider =
1403- sinon . createStubInstance ( Elements . StylesAiCodeCompletionProvider . StylesAiCodeCompletionProvider ) ;
1404- sinon . stub ( Elements . StylesAiCodeCompletionProvider . StylesAiCodeCompletionProvider , 'createInstance' )
1405- . returns ( aiCodeCompletionProvider ) ;
1406-
14071411 attachedElement = document . createElement ( 'div' ) ;
14081412 renderElementIntoDOM ( attachedElement ) ;
14091413 cssPropertyPrompt = new Elements . StylesSidebarPane . CSSPropertyPrompt ( mockTreeItem , false ) ;
@@ -1412,21 +1416,21 @@ describe('StylesSidebarPane', () => {
14121416 it ( 'getCompletionHint returns null if suggestBox is not visible' , ( ) => {
14131417 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
14141418
1415- assert . exists ( cssPropertyPrompt . aiCodeCompletionConfig ) ;
1416- assert . exists ( cssPropertyPrompt . aiCodeCompletionConfig . getCompletionHint ) ;
1417- assert . isNull ( cssPropertyPrompt . aiCodeCompletionConfig . getCompletionHint ( ) ) ;
1419+ assert . exists ( cssPropertyPrompt . aiCodeCompletionProvider ?. getCompletionHint ) ;
1420+ assert . isNull ( cssPropertyPrompt . aiCodeCompletionProvider . getCompletionHint ( ) ) ;
14181421 } ) ;
14191422
14201423 it ( 'getCompletionHint returns the correct completion hint' , async ( ) => {
14211424 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
14221425 cssPropertyPrompt . setText ( 'var(--rgb' ) ;
14231426 await cssPropertyPrompt . complete ( true ) ;
14241427
1425- assert . strictEqual ( cssPropertyPrompt . aiCodeCompletionConfig ?. getCompletionHint ?.( ) , '-color)' ) ;
1428+ assert . strictEqual ( cssPropertyPrompt . aiCodeCompletionProvider ?. getCompletionHint ?.( ) , '-color)' ) ;
14261429 } ) ;
14271430
14281431 it ( 'debounces triggerAiCodeCompletion' , async ( ) => {
14291432 const clock = sinon . useFakeTimers ( ) ;
1433+ const triggerAiCodeCompletionStub = aiCodeCompletionProvider . triggerAiCodeCompletion . resolves ( ) ;
14301434 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
14311435
14321436 cssPropertyPrompt . setText ( 'backgr' ) ;
@@ -1437,30 +1441,31 @@ describe('StylesSidebarPane', () => {
14371441 cssPropertyPrompt . onInput ( new Event ( 'input' ) ) ;
14381442 await clock . tickAsync ( TextEditor . AiCodeCompletionProvider . AIDA_REQUEST_DEBOUNCE_TIMEOUT_MS + 1 ) ;
14391443
1440- sinon . assert . calledOnce ( aiCodeCompletionProvider . triggerAiCodeCompletion ) ;
1441- assert . strictEqual ( aiCodeCompletionProvider . triggerAiCodeCompletion . firstCall . args [ 0 ] , 'backgrou' ) ;
1442- assert . strictEqual ( aiCodeCompletionProvider . triggerAiCodeCompletion . firstCall . args [ 1 ] , 8 ) ;
1444+ sinon . assert . calledOnce ( triggerAiCodeCompletionStub ) ;
1445+ assert . strictEqual ( triggerAiCodeCompletionStub . firstCall . args [ 0 ] , 'backgrou' ) ;
1446+ assert . strictEqual ( triggerAiCodeCompletionStub . firstCall . args [ 1 ] , 8 ) ;
14431447 clock . restore ( ) ;
14441448 } ) ;
14451449
14461450 it ( 'triggerAiCodeCompletion calls the provider with correct arguments' , ( ) => {
14471451 const clock = sinon . useFakeTimers ( ) ;
1452+ const triggerAiCodeCompletionStub = aiCodeCompletionProvider . triggerAiCodeCompletion . resolves ( ) ;
14481453 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
14491454
14501455 cssPropertyPrompt . setText ( 'backgrou' ) ;
14511456 cssPropertyPrompt . onInput ( new Event ( 'input' ) ) ;
14521457 clock . tick ( TextEditor . AiCodeCompletionProvider . AIDA_REQUEST_DEBOUNCE_TIMEOUT_MS + 1 ) ;
14531458
1454- sinon . assert . calledOnce ( aiCodeCompletionProvider . triggerAiCodeCompletion ) ;
1455- assert . strictEqual ( aiCodeCompletionProvider . triggerAiCodeCompletion . firstCall . args [ 0 ] , 'backgrou' ) ;
1456- assert . strictEqual ( aiCodeCompletionProvider . triggerAiCodeCompletion . firstCall . args [ 1 ] , 8 ) ;
1459+ sinon . assert . calledOnce ( triggerAiCodeCompletionStub ) ;
1460+ assert . strictEqual ( triggerAiCodeCompletionStub . firstCall . args [ 0 ] , 'backgrou' ) ;
1461+ assert . strictEqual ( triggerAiCodeCompletionStub . firstCall . args [ 1 ] , 8 ) ;
14571462 clock . restore ( ) ;
14581463 } ) ;
14591464
14601465 it ( 'setAiAutoCompletion sets activeAiSuggestion on the section' , async ( ) => {
14611466 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
14621467
1463- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1468+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
14641469 text : 'color: pink;' ,
14651470 from : 0 ,
14661471 startTime : 0 ,
@@ -1481,7 +1486,7 @@ content: "This is a semicolon; and this is a colon: inside a string";
14811486width: calc(100% - 20px);
14821487color: pink !important;` ;
14831488
1484- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1489+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
14851490 text : complexCss ,
14861491 from : 0 ,
14871492 startTime : 0 ,
@@ -1503,7 +1508,7 @@ color: pink !important;`;
15031508 cssPropertyPrompt . setText ( 'var(--rgb' ) ;
15041509 await cssPropertyPrompt . complete ( true ) ;
15051510
1506- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1511+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
15071512 text : 'color: var(--rgb-color);' ,
15081513 from : 0 ,
15091514 startTime : 0 ,
@@ -1524,7 +1529,7 @@ color: pink !important;`;
15241529 cssPropertyPrompt . setText ( 'var(--rgb' ) ;
15251530 await cssPropertyPrompt . complete ( true ) ;
15261531
1527- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1532+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
15281533 text : 'color: var(--rgb-color);' ,
15291534 from : 0 ,
15301535 startTime : 0 ,
@@ -1546,7 +1551,7 @@ color: pink !important;`;
15461551 cssPropertyPrompt = new Elements . StylesSidebarPane . CSSPropertyPrompt ( mockTreeItem , true ) ;
15471552 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
15481553
1549- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1554+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
15501555 text : 'color: pink;' ,
15511556 from : 0 ,
15521557 startTime : 0 ,
@@ -1566,7 +1571,7 @@ color: pink !important;`;
15661571
15671572 cssPropertyPrompt . setText ( 'gre' ) ;
15681573 await cssPropertyPrompt . complete ( true ) ;
1569- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1574+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
15701575 text : 'color: greenyellow;' ,
15711576 from : 0 ,
15721577 startTime : 0 ,
@@ -1590,7 +1595,7 @@ color: pink !important;`;
15901595
15911596 cssPropertyPrompt . setText ( 'var(--rgb' ) ;
15921597 await cssPropertyPrompt . complete ( true ) ;
1593- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1598+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
15941599 text : 'color: var(--rgb-color); background-color: white;' ,
15951600 from : 0 ,
15961601 startTime : 0 ,
@@ -1616,8 +1621,8 @@ color: pink !important;`;
16161621 it ( 'clears suggestion if user input does not match' , async ( ) => {
16171622 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
16181623
1619- assert . exists ( cssPropertyPrompt . aiCodeCompletionConfig ) ;
1620- cssPropertyPrompt . aiCodeCompletionConfig . setAiAutoCompletion ?.( {
1624+ assert . exists ( cssPropertyPrompt . aiCodeCompletionProvider ) ;
1625+ cssPropertyPrompt . aiCodeCompletionProvider . setAiAutoCompletion ?.( {
16211626 text : 'color: pink;' ,
16221627 from : 0 ,
16231628 startTime : 0 ,
@@ -1636,7 +1641,7 @@ color: pink !important;`;
16361641 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
16371642
16381643 cssPropertyPrompt . setText ( 'pin' ) ;
1639- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1644+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
16401645 text : 'color: pink;' ,
16411646 from : 3 ,
16421647 startTime : 0 ,
@@ -1662,7 +1667,7 @@ color: pink !important;`;
16621667
16631668 cssPropertyPrompt . setText ( 'var(--rgb' ) ;
16641669 await cssPropertyPrompt . complete ( true ) ;
1665- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1670+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
16661671 text : 'color: var(--rgb-background-color);' ,
16671672 from : 0 ,
16681673 startTime : 0 ,
@@ -1681,7 +1686,7 @@ color: pink !important;`;
16811686 cssPropertyPrompt . attachAndStartEditing ( attachedElement , noop ) ;
16821687
16831688 cssPropertyPrompt . setText ( 'p' ) ;
1684- cssPropertyPrompt . aiCodeCompletionConfig ?. setAiAutoCompletion ?.( {
1689+ cssPropertyPrompt . aiCodeCompletionProvider ?. setAiAutoCompletion ?.( {
16851690 text : 'color: pink;' ,
16861691 from : 1 ,
16871692 startTime : 0 ,
0 commit comments