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 {
36
36
if ( firstUri === undefined ) return
37
37
38
38
await WorkspaceCfg . setWorkspaceUri ( firstUri )
39
+
39
40
void Alert . info ( `工作空间成功修改为: "${ WorkspaceCfg . getWorkspaceUri ( ) . fsPath } "` )
40
41
}
41
42
}
Original file line number Diff line number Diff line change 1
1
import { PlatformCfg } from '@/ctx/cfg/platform'
2
2
import getPlatformCfg = PlatformCfg . getPlatformCfg
3
3
import 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 '
6
6
7
7
export namespace WorkspaceCfg {
8
8
export function getWorkspaceUri ( ) {
9
9
const path = getPlatformCfg ( ) . get < string > ( 'workspace' ) ?? '~/Documents/Cnblogs'
10
10
const absPath = path . replace ( '~' , os . homedir ( ) )
11
-
12
11
return Uri . file ( absPath )
13
12
}
14
13
15
- export function setWorkspaceUri ( uri : Uri ) {
14
+ export async function setWorkspaceUri ( uri : Uri ) : Promise < void > {
16
15
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
+ }
18
25
19
26
const cfgTarget = ConfigurationTarget . Global
20
- return getPlatformCfg ( ) ?. update ( 'workspace' , fsPath , cfgTarget )
27
+ await getPlatformCfg ( ) ?. update ( 'workspace' , fsPath , cfgTarget )
21
28
}
22
29
}
You can’t perform that action at this time.
0 commit comments