11import type { TreeViewNode } from 'reactive-vscode'
22import type { ApiDetail , MockApiData } from '../types'
33import { parse , stringify } from 'comment-json'
4- import { createSingletonComposable , executeCommand , ref , useCommand , useTreeView } from 'reactive-vscode'
4+ import { createSingletonComposable , executeCommand , ref , useCommand , useTreeView , watchEffect } from 'reactive-vscode'
55import { TreeItemCollapsibleState , Uri , window , workspace } from 'vscode'
66import { config } from '../config'
77import { crabuDiffNewScheme , crabuDiffOldScheme } from '../constants'
@@ -48,6 +48,13 @@ function handleData(data: MockApiData[]) {
4848
4949export const useMockTreeView = createSingletonComposable ( async ( ) => {
5050 const roots = ref < TreeViewNode [ ] > ( [ ] )
51+ const treeView = useTreeView (
52+ 'mockTreeView' ,
53+ roots ,
54+ {
55+ showCollapseAll : true ,
56+ } ,
57+ )
5158
5259 async function getRootNode ( ) {
5360 try {
@@ -65,6 +72,7 @@ export const useMockTreeView = createSingletonComposable(async () => {
6572 }
6673
6774 async function refreshMockTreeView ( ) {
75+ logger . info ( 'refreshMockTreeView' )
6876 window . withProgress ( {
6977 location : { viewId : 'mockTreeView' } ,
7078 } , async ( progress ) => {
@@ -73,7 +81,7 @@ export const useMockTreeView = createSingletonComposable(async () => {
7381 } )
7482 }
7583
76- await refreshMockTreeView ( )
84+ watchEffect ( refreshMockTreeView )
7785
7886 useCommand ( commands . refreshMockTreeView , refreshMockTreeView )
7987 useCommand ( commands . showCrabuWebviewWithMock , ( event ) => {
@@ -199,11 +207,8 @@ export const useMockTreeView = createSingletonComposable(async () => {
199207 executeCommand ( 'vscode.diff' , oldUri , newUri , `检查变更:${ mockItem . label } ` )
200208 } )
201209
202- return useTreeView (
203- 'mockTreeView' ,
204- roots ,
205- {
206- showCollapseAll : true ,
207- } ,
208- )
210+ useCommand ( commands . findInMock , async ( ) => {
211+ await treeView . reveal ( roots . value ?. [ 0 ] , { focus : true } )
212+ executeCommand ( 'list.find' )
213+ } )
209214} )
0 commit comments