@@ -12,24 +12,55 @@ import { getMenuItems, getParallelBuildNumber } from './smart';
1212import { initDockView } from './dock' ;
1313import { setupVEnv } from './venv' ;
1414import { initAPI } from './api' ;
15+ import { openWorkspaceProjectsWebview } from './webviews/project' ;
16+ import { initProjectTree } from './project/tree' ;
1517
1618let _context : vscode . ExtensionContext ;
1719
20+ // 有两种模式
21+ // isRTThreadWorksapce - workspace模式,会定位.vscode/workspace.json文件是否存在,是否启用
22+ // isRTThread - 项目模式,rtconfig.h文件是否存在
23+
1824export async function activate ( context : vscode . ExtensionContext ) {
1925 let isRTThread : boolean = false ;
20- const workspaceFolders = vscode . workspace . workspaceFolders ;
26+ let isRTThreadWorksapce : boolean = false ;
2127
2228 _context = context ;
29+
30+ // init context for isRTThread, isRTThreadWorksapce
31+ vscode . commands . executeCommand ( 'setContext' , 'isRTThread' , isRTThread ) ;
32+ context . workspaceState . update ( 'isRTThread' , isRTThread ) ;
33+ vscode . commands . executeCommand ( 'setContext' , 'isRTThreadWorksapce' , isRTThreadWorksapce ) ;
34+ context . workspaceState . update ( 'isRTThreadWorksapce' , isRTThreadWorksapce ) ;
35+ initAPI ( context ) ;
36+
37+ const workspaceFolders = vscode . workspace . workspaceFolders ;
2338 if ( workspaceFolders ) {
2439 const workspacePath = workspaceFolders [ 0 ] . uri . fsPath ;
25- // check rtconfig.h exists
26- const rtconfigPath = path . join ( workspacePath , 'rtconfig.h' ) ;
27- if ( fs . existsSync ( rtconfigPath ) ) {
28- /* The workspace is a RT-Thread Project*/
29- isRTThread = true ;
30- initAPI ( context , isRTThread ) ;
31- vscode . commands . executeCommand ( 'setContext' , 'isRTThread' , true ) ;
3240
41+ const rtthreadWorkspace = path . join ( workspacePath , '.vscode' , 'workspace.json' ) ;
42+ if ( fs . existsSync ( rtthreadWorkspace ) ) {
43+ const json = fs . readFileSync ( rtthreadWorkspace , 'utf8' ) ;
44+ const jsonNode = JSON . parse ( json ) ;
45+
46+ if ( jsonNode . hasOwnProperty ( "bsps" ) ) {
47+ isRTThreadWorksapce = true ;
48+ vscode . commands . executeCommand ( 'setContext' , 'isRTThreadWorksapce' , true ) ;
49+ context . workspaceState . update ( 'isRTThreadWorksapce' , isRTThreadWorksapce ) ;
50+ }
51+ }
52+ else {
53+ // check rtconfig.h exists
54+ const rtconfigPath = path . join ( workspacePath , 'rtconfig.h' ) ;
55+ if ( fs . existsSync ( rtconfigPath ) ) {
56+ /* The workspace is a RT-Thread Project*/
57+ isRTThread = true ;
58+ vscode . commands . executeCommand ( 'setContext' , 'isRTThread' , true ) ;
59+ context . workspaceState . update ( 'isRTThread' , isRTThread ) ;
60+ }
61+ }
62+
63+ if ( isRTThread || isRTThreadWorksapce ) {
3364 // if it's Windows system
3465 if ( os . platform ( ) === 'win32' ) {
3566 await setupVEnv ( ) ;
@@ -42,7 +73,7 @@ export async function activate(context: vscode.ExtensionContext) {
4273 // register commands
4374 vscode . commands . registerCommand ( 'extension.showAbout' , ( ) => {
4475 openAboutWebview ( context ) ;
45- } ) ;
76+ } ) ;
4677 vscode . commands . registerCommand ( 'extension.executeCommand' , ( arg1 , arg2 ) => {
4778 if ( arg1 )
4879 {
@@ -60,21 +91,35 @@ export async function activate(context: vscode.ExtensionContext) {
6091 }
6192 } )
6293 }
63- else {
64- isRTThread = false ;
65- vscode . commands . executeCommand ( 'setContext' , 'isRTThread' , false ) ;
66- initAPI ( context , isRTThread ) ;
67- }
68- }
69- else {
70- initAPI ( context , isRTThread ) ;
7194 }
7295
7396 vscode . commands . registerCommand ( 'extension.showHome' , ( ) => {
7497 openHomeWebview ( context ) ;
7598 } ) ;
99+ if ( isRTThreadWorksapce ) {
100+ vscode . commands . registerCommand ( 'extension.showWorkspaceSettings' , ( ) => {
101+ openWorkspaceProjectsWebview ( context ) ;
102+ } ) ;
103+ initProjectTree ( context ) ;
104+ }
105+
76106 /* initialize dock view always */
77107 initDockView ( context ) ;
108+ initExperimentStatusBarItem ( context )
109+ }
110+
111+ function initExperimentStatusBarItem ( context : vscode . ExtensionContext ) {
112+ if ( false ) {
113+ const statusItem = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Left , 5 ) ;
114+ statusItem . text = '$(beaker) 实验性功能' ;
115+ statusItem . tooltip = 'Experimental features' ;
116+ statusItem . command = 'extension.Experimental' ;
117+ statusItem . show ( ) ;
118+
119+ vscode . commands . registerCommand ( 'extension.Experimental' , ( ) => {
120+ console . log ( 'Experimental features are not available yet.' ) ;
121+ } ) ;
122+ }
78123}
79124
80125function setupStatusBarItems ( context : vscode . ExtensionContext ) {
0 commit comments