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 1717 " onStartupFinished"
1818 ],
1919 "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+ },
2030 "commands" : [
2131 {
2232 "command" : " antd-design-token.toggle" ,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import setupEventListenerAndDecorations, {
44 DisposableAndClear ,
55} from "./listener" ;
66import setupAntdTokenCompletion from "./typing" ;
7- import { checkAntdProject } from "./utils" ;
7+ import { checkAntdProject , getThemeConfig } from "./utils" ;
88
99export function activate ( context : vscode . ExtensionContext ) {
1010 let isActive = true ;
@@ -38,7 +38,16 @@ export function activate(context: vscode.ExtensionContext) {
3838 context . subscriptions . push ( disposable ) ;
3939
4040 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+ }
4251
4352 if ( ! fullToken ) {
4453 vscode . window . showErrorMessage ( "Failed to get antd fullToken." ) ;
@@ -53,6 +62,13 @@ export function activate(context: vscode.ExtensionContext) {
5362 }
5463 }
5564
65+ vscode . workspace . onDidChangeConfiguration ( ( event ) => {
66+ if ( event . affectsConfiguration ( "antdDesignToken.themePath" ) ) {
67+ if ( isActive ) {
68+ setup ( ) ;
69+ }
70+ }
71+ } ) ;
5672 function setupDecorationsAndCompletion (
5773 context : vscode . ExtensionContext ,
5874 fullToken : any
Original file line number Diff line number Diff line change @@ -59,3 +59,30 @@ export function getProjectPath(): string | undefined {
5959 ?. map ( ( folder ) => folder . uri . fsPath )
6060 . filter ( ( fsPath ) => fileName ?. startsWith ( fsPath ) ) [ 0 ] ;
6161}
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+ vscode . window . showInformationMessage ( "invalid theme path" ) ;
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