File tree Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Expand file tree Collapse file tree 3 files changed +55
-2
lines changed Original file line number Diff line number Diff line change 17
17
" onStartupFinished"
18
18
],
19
19
"contributes" : {
20
+ "configuration" : {
21
+ "title" : " antd-design-token" ,
22
+ "properties" : {
23
+ "antdDesignToken.themePath" : {
24
+ "type" : " string" ,
25
+ "default" : " " ,
26
+ "description" : " json theme path ,relative to workspace root"
27
+ }
28
+ }
29
+ },
20
30
"commands" : [
21
31
{
22
32
"command" : " antd-design-token.toggle" ,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import setupEventListenerAndDecorations, {
4
4
DisposableAndClear ,
5
5
} from "./listener" ;
6
6
import setupAntdTokenCompletion from "./typing" ;
7
- import { checkAntdProject } from "./utils" ;
7
+ import { checkAntdProject , getThemeConfig } from "./utils" ;
8
8
9
9
export function activate ( context : vscode . ExtensionContext ) {
10
10
let isActive = true ;
@@ -38,7 +38,16 @@ export function activate(context: vscode.ExtensionContext) {
38
38
context . subscriptions . push ( disposable ) ;
39
39
40
40
function setup ( ) {
41
- const fullToken = getDesignToken ( ) ;
41
+ let fullToken : any ;
42
+
43
+ const themeConfig = getThemeConfig ( ) ;
44
+ console . log ( { themeConfig } ) ;
45
+
46
+ if ( themeConfig ) {
47
+ fullToken = getDesignToken ( themeConfig ) ;
48
+ } else {
49
+ fullToken = getDesignToken ( ) ;
50
+ }
42
51
43
52
if ( ! fullToken ) {
44
53
vscode . window . showErrorMessage ( "Failed to get antd fullToken." ) ;
@@ -53,6 +62,13 @@ export function activate(context: vscode.ExtensionContext) {
53
62
}
54
63
}
55
64
65
+ vscode . workspace . onDidChangeConfiguration ( ( event ) => {
66
+ if ( event . affectsConfiguration ( "antdDesignToken.themePath" ) ) {
67
+ if ( isActive ) {
68
+ setup ( ) ;
69
+ }
70
+ }
71
+ } ) ;
56
72
function setupDecorationsAndCompletion (
57
73
context : vscode . ExtensionContext ,
58
74
fullToken : any
Original file line number Diff line number Diff line change @@ -59,3 +59,30 @@ export function getProjectPath(): string | undefined {
59
59
?. map ( ( folder ) => folder . uri . fsPath )
60
60
. filter ( ( fsPath ) => fileName ?. startsWith ( fsPath ) ) [ 0 ] ;
61
61
}
62
+
63
+ export function getThemeConfig ( ) {
64
+ try {
65
+ const config = vscode . workspace . getConfiguration ( "antdDesignToken" ) ;
66
+ const themePath = config . get < string > ( "themePath" ) ?? "" ;
67
+ const extname = path . extname ( themePath ) ;
68
+ if ( extname !== ".json" ) {
69
+ console . warn ( `invalid theme path ${ themePath } ` ) ;
70
+ return null ;
71
+ }
72
+
73
+ let workspaceFolder =
74
+ vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri ?. fsPath ?? "" ;
75
+ let themeFullPath ;
76
+ if ( path . isAbsolute ( themePath ) ) {
77
+ themeFullPath = themePath ;
78
+ } else {
79
+ themeFullPath = path . join ( workspaceFolder , themePath ) ;
80
+ }
81
+ const jsonStr = fs . readFileSync ( themeFullPath , "utf-8" ) ;
82
+ const json = JSON . parse ( jsonStr ) ;
83
+ return json ;
84
+ } catch ( err ) {
85
+ vscode . window . showInformationMessage ( "failed to get theme json " ) ;
86
+ return null ;
87
+ }
88
+ }
You can’t perform that action at this time.
0 commit comments