@@ -4,11 +4,12 @@ import type { API, Change, GitExtension, Repository, RepositoryState } from './g
44import type { ScmChange , ScmGroup , ScmGroupMeta , ScmRepo , ScmRepoMeta } from './types'
55import { basename } from 'pathe'
66import { effectScope , getCurrentScope , useDisposable } from 'reactive-vscode'
7- import { extensions } from 'vscode'
7+ import { extensions , Uri } from 'vscode'
88import * as Y from 'yjs'
99import { YTuple } from '../sync/y-tuple'
1010
1111export function useHostScm ( connection : Connection , doc : Y . Doc ) {
12+ const { toHostUri } = connection
1213 const scope = getCurrentScope ( ) !
1314 const _git = ( async ( ) => {
1415 const gitExtension = extensions . getExtension < GitExtension > ( 'vscode.git' )
@@ -18,6 +19,21 @@ export function useHostScm(connection: Connection, doc: Y.Doc) {
1819 const gitApi = gitExtension . exports . getAPI ( 1 )
1920 return scope . run ( ( ) => useHostGitScm ( gitApi , connection , doc ) )
2021 } ) ( )
22+
23+ return {
24+ async scmClean ( repoUri : string , groupId : string , resourceUris : string [ ] ) {
25+ const git = await _git
26+ if ( ! git )
27+ return
28+ const repo = git . repositories . get ( repoUri )
29+ if ( ! repo )
30+ return
31+ await repo . repo . clean ( resourceUris . map ( ( uri_ ) => {
32+ const uri = toHostUri ( Uri . parse ( uri_ ) )
33+ return uri . fsPath
34+ } ) )
35+ } ,
36+ }
2137}
2238
2339function useHostGitScm ( api : API , connection : Connection , doc : Y . Doc ) {
@@ -29,13 +45,19 @@ function useHostGitScm(api: API, connection: Connection, doc: Y.Doc) {
2945 // const changedInstances = new Set()
3046 // const resourceCache = new Map()
3147
32- const repoScopes = new Map < string , EffectScope > ( )
48+ const repositories = new Map < string , {
49+ scope : EffectScope
50+ repo : Repository
51+ } > ( )
3352 const openRepository = ( repo : Repository ) => {
3453 const uri = toTrackUri ( repo . rootUri ) ?. toString ( )
3554 if ( ! uri )
3655 return
3756 const scope = effectScope ( true )
38- repoScopes . set ( uri , scope )
57+ repositories . set ( uri , {
58+ scope,
59+ repo,
60+ } )
3961 map . set ( uri , scope . run ( ( ) => useScmRepo ( repo , {
4062 rootUri : uri ,
4163 label : 'Git' ,
@@ -50,26 +72,19 @@ function useHostGitScm(api: API, connection: Connection, doc: Y.Doc) {
5072 if ( ! uri )
5173 return
5274 map . delete ( uri )
53- const scope = repoScopes . get ( uri )
54- if ( scope ) {
55- scope . stop ( )
56- repoScopes . delete ( uri )
75+ const repository = repositories . get ( uri )
76+ if ( repository ) {
77+ repository . scope . stop ( )
78+ repositories . delete ( uri )
5779 }
5880 } ) )
5981
6082 // const documentUriCacheCleanupTimer = setInterval(cleanupDocumentUriCache, 300000)
6183 // onScopeDispose(() => clearInterval(documentUriCacheCleanupTimer))
6284
6385 return {
64- // getRecentVersions,
65- // getRecentVersionsTillMergeVersion,
66- // getCurrentVersionName,
67- // getRemoteVersionsNames,
68- // getMergeVersion,
69- // getDiffsForVersion,
70- // getDiffForResource,
71- // getResource,
72- // cleanResources,
86+ api,
87+ repositories,
7388 }
7489
7590 // function getInstanceId(repo: Repository) {
0 commit comments