@@ -7,10 +7,10 @@ import { basename, dirname } from 'node:path'
77import { debounce , slash } from '@antfu/utils'
88import { load } from '@slidev/parser/fs'
99import { isMatch } from 'picomatch'
10- import { computed , effectScope , extensionContext , markRaw , onScopeDispose , ref , shallowReactive , shallowRef , useDisposable , useFsWatcher , useVscodeContext , watch , watchEffect } from 'reactive-vscode'
10+ import { computed , effectScope , extensionContext , markRaw , onScopeDispose , ref , shallowReactive , shallowRef , useDisposable , useFileSystemWatcher , useVscodeContext , watch , watchEffect } from 'reactive-vscode'
1111import { FileSystemError , Uri , window , workspace } from 'vscode'
1212import { useServerDetector } from './composables/useServerDetector'
13- import { exclude , forceEnabled , include } from './configs'
13+ import { config } from './configs'
1414import { findShallowestPath } from './utils/findShallowestPath'
1515import { logger } from './views/logger'
1616
@@ -31,18 +31,20 @@ export const activeProject = computed(() => activeEntry.value ? projects.get(act
3131export const activeData = computed ( ( ) => activeProject . value ?. data )
3232
3333export function useProjects ( ) {
34- const watcher = useFsWatcher ( include , false , true , false )
35- watcher . onDidCreate ( async ( uri ) => {
36- const path = slash ( uri . fsPath )
37- if ( ! isMatch ( path , exclude . value ) )
38- await addProject ( path )
39- } )
40- watcher . onDidDelete ( async ( uri ) => {
41- removeProject ( slash ( uri . fsPath ) )
34+ useFileSystemWatcher ( ( ) => config . include , {
35+ async onDidCreate ( uri ) {
36+ const path = slash ( uri . fsPath )
37+ if ( ! isMatch ( path , config . exclude ) )
38+ await addProject ( path )
39+ } ,
40+ onDidChange : false ,
41+ async onDidDelete ( uri ) {
42+ removeProject ( slash ( uri . fsPath ) )
43+ } ,
4244 } )
4345
4446 rescanProjects ( )
45- watch ( [ include , exclude ] , debounce ( 200 , rescanProjects ) )
47+ watch ( ( ) => [ config . include , config . exclude ] , debounce ( 200 , rescanProjects ) )
4648
4749 // In case all the projects are removed manually, and the user may not want to disable the extension.
4850 const everHadProjects = ref ( false )
@@ -80,7 +82,8 @@ export function useProjects() {
8082 } , { immediate : true } )
8183
8284 useVscodeContext ( 'slidev:enabled' , ( ) => {
83- const enabled = forceEnabled . value == null ? everHadProjects . value : forceEnabled . value
85+ const forceEnabled = config [ 'force-enabled' ]
86+ const enabled = forceEnabled == null ? everHadProjects . value : forceEnabled
8487 logger . info ( `Slidev ${ enabled ? 'enabled' : 'disabled' } .` )
8588 return enabled
8689 } )
@@ -102,8 +105,8 @@ export async function rescanProjects() {
102105 scanningProjects = true
103106 try {
104107 const entries = new Set < string > ( )
105- for ( const glob of include . value ) {
106- ( await workspace . findFiles ( glob , exclude . value ) )
108+ for ( const glob of config . include ) {
109+ ( await workspace . findFiles ( glob , config . exclude ) )
107110 . forEach ( file => entries . add ( file . fsPath ) )
108111 }
109112 for ( const entry of entries ) {
0 commit comments