File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ export namespace Workspace {
3636 if ( firstUri === undefined ) return
3737
3838 await WorkspaceCfg . setWorkspaceUri ( firstUri )
39+
3940 void Alert . info ( `工作空间成功修改为: "${ WorkspaceCfg . getWorkspaceUri ( ) . fsPath } "` )
4041 }
4142}
Original file line number Diff line number Diff line change 11import { PlatformCfg } from '@/ctx/cfg/platform'
22import getPlatformCfg = PlatformCfg . getPlatformCfg
33import os from 'os'
4- import fs from 'fs '
5- import { ConfigurationTarget , Uri } from 'vscode '
4+ import { ConfigurationTarget , Uri , workspace } from 'vscode '
5+ import { Alert } from '@/infra/alert '
66
77export namespace WorkspaceCfg {
88 export function getWorkspaceUri ( ) {
99 const path = getPlatformCfg ( ) . get < string > ( 'workspace' ) ?? '~/Documents/Cnblogs'
1010 const absPath = path . replace ( '~' , os . homedir ( ) )
11-
1211 return Uri . file ( absPath )
1312 }
1413
15- export function setWorkspaceUri ( uri : Uri ) {
14+ export async function setWorkspaceUri ( uri : Uri ) : Promise < void > {
1615 const fsPath = uri . fsPath
17- if ( fs . existsSync ( fsPath ) || uri . scheme !== 'file' ) throw Error ( 'Invalid Uri' )
16+
17+ if ( uri . scheme !== 'file' ) throw Error ( `Invalid Uri: ${ uri . path } ` )
18+
19+ try {
20+ await workspace . fs . stat ( uri )
21+ } catch ( e ) {
22+ void Alert . err ( `Invalid Uri: ${ uri . path } ` )
23+ throw e
24+ }
1825
1926 const cfgTarget = ConfigurationTarget . Global
20- return getPlatformCfg ( ) ?. update ( 'workspace' , fsPath , cfgTarget )
27+ await getPlatformCfg ( ) ?. update ( 'workspace' , fsPath , cfgTarget )
2128 }
2229}
You can’t perform that action at this time.
0 commit comments