55 ConfigurationTarget ,
66 ExtensionContext ,
77 FileType ,
8- StatusBarAlignment ,
98 TextDocument ,
10- ThemeColor ,
119 Uri ,
1210 commands ,
1311 extensions ,
@@ -32,14 +30,6 @@ import {
3230 isBazelWorkspaceRoot ,
3331} from './util' ;
3432
35- const classpathStatus = window . createStatusBarItem ( StatusBarAlignment . Left , 1 ) ;
36- const projectViewStatus = window . createStatusBarItem (
37- StatusBarAlignment . Left ,
38- 1
39- ) ;
40- const outOfDateClasspaths : Set < Uri > = new Set < Uri > ( ) ;
41- classpathStatus . command = Commands . UPDATE_CLASSPATHS_CMD ;
42- projectViewStatus . command = Commands . SYNC_PROJECTS_CMD ;
4333const workspaceRoot = getWorkspaceRoot ( ) ;
4434
4535export async function activate ( context : ExtensionContext ) {
@@ -61,14 +51,10 @@ export async function activate(context: ExtensionContext) {
6151
6252 BazelLanguageServerTerminal . trace ( 'extension activated' ) ;
6353
64- workspace . onDidChangeTextDocument ( ( event ) => {
65- const doc = event . document ;
66- if ( doc . uri . fsPath . includes ( 'bazelproject' ) && ! doc . isDirty ) {
54+ workspace . onDidSaveTextDocument ( ( doc ) => {
55+ if ( doc . fileName . includes ( 'bazelproject' ) ) {
6756 toggleBazelProjectSyncStatus ( doc ) ;
6857 }
69- if ( doc . uri . fsPath . includes ( 'BUILD' ) && ! doc . isDirty ) {
70- toggleBazelClasspathSyncStatus ( doc ) ;
71- }
7258 } ) ;
7359
7460 context . subscriptions . push (
@@ -92,7 +78,7 @@ export async function activate(context: ExtensionContext) {
9278 openBazelProjectFile ( ) ;
9379 showBazelprojectConfig . update ( 'open' , false ) ; // only open this file on the first activation of this extension
9480 }
95- syncBazelProjectView ( ) ;
81+ syncProjectViewDirectories ( ) ;
9682 context . subscriptions . push (
9783 commands . registerCommand ( Commands . OPEN_BAZEL_PROJECT_FILE , ( ) =>
9884 openBazelProjectFile ( )
@@ -106,7 +92,7 @@ export async function activate(context: ExtensionContext) {
10692 context . subscriptions . push (
10793 commands . registerCommand (
10894 Commands . SYNC_DIRECTORIES_ONLY ,
109- syncBazelProjectView
95+ syncProjectViewDirectories
11096 )
11197 ) ;
11298 context . subscriptions . push (
@@ -152,9 +138,19 @@ function syncProjectView(): void {
152138 return ;
153139 }
154140
155- projectViewStatus . hide ( ) ;
141+ const launchMode = workspace
142+ . getConfiguration ( 'java.server' )
143+ . get ( 'launchMode' ) ;
144+ // if the launchMode is not Standard it should be changed and the window reloaded to apply that change
145+ if ( ! launchMode || launchMode !== 'Standard' ) {
146+ workspace
147+ . getConfiguration ( 'java.server' )
148+ . update ( 'launchMode' , 'Standard' )
149+ . then ( ( ) => commands . executeCommand ( 'workbench.action.reloadWindow' ) ) ;
150+ }
151+
156152 executeJavaLanguageServerCommand ( Commands . SYNC_PROJECTS ) . then (
157- syncBazelProjectView
153+ syncProjectViewDirectories
158154 ) ;
159155}
160156
@@ -165,19 +161,6 @@ function updateClasspaths() {
165161 ) ;
166162 return ;
167163 }
168- outOfDateClasspaths . forEach ( ( uri ) => {
169- BazelLanguageServerTerminal . info ( `Updating classpath for ${ uri . fsPath } ` ) ;
170- executeJavaLanguageServerCommand (
171- Commands . UPDATE_CLASSPATHS ,
172- uri . toString ( )
173- ) . then (
174- ( ) => outOfDateClasspaths . delete ( uri ) ,
175- ( err : Error ) => {
176- BazelLanguageServerTerminal . error ( `${ err . message } \n${ err . stack } ` ) ;
177- }
178- ) ;
179- } ) ;
180- classpathStatus . hide ( ) ;
181164}
182165
183166function runLSCmd ( ) {
@@ -210,24 +193,28 @@ function isRedhatJavaReady(): boolean {
210193 return false ;
211194}
212195
213- function toggleBazelClasspathSyncStatus ( doc : TextDocument ) {
214- classpathStatus . show ( ) ;
215- classpathStatus . text = 'Sync bazel classpath' ;
216- classpathStatus . backgroundColor = new ThemeColor (
217- 'statusBarItem.warningBackground'
218- ) ;
219- outOfDateClasspaths . add ( doc . uri ) ;
220- }
221-
222196function toggleBazelProjectSyncStatus ( doc : TextDocument ) {
223- projectViewStatus . show ( ) ;
224- projectViewStatus . text = 'Sync bazel project view' ;
225- projectViewStatus . backgroundColor = new ThemeColor (
226- 'statusBarItem.warningBackground'
227- ) ;
197+ if ( workspace . getConfiguration ( 'bazel.projectview' ) . get ( 'notification' ) ) {
198+ window
199+ . showWarningMessage (
200+ `The Bazel Project View changed. Do you want to synchronize? [details](https://github.com/salesforce/bazel-eclipse/blob/main/docs/common/projectviews.md#project-views)` ,
201+ ...[ 'Java Projects' , 'Only Directories' , 'Do Nothing' ]
202+ )
203+ . then ( ( val ) => {
204+ if ( val === 'Java Projects' ) {
205+ syncProjectView ( ) ;
206+ } else if ( val === 'Only Directories' ) {
207+ syncProjectViewDirectories ( ) ;
208+ } else if ( val === 'Do Nothing' ) {
209+ workspace
210+ . getConfiguration ( 'bazel.projectview' )
211+ . update ( 'notification' , false ) ;
212+ }
213+ } ) ;
214+ }
228215}
229216
230- async function syncBazelProjectView ( ) {
217+ async function syncProjectViewDirectories ( ) {
231218 if ( workspaceRoot ) {
232219 BazelLanguageServerTerminal . debug ( 'Syncing bazel project view' ) ;
233220 const displayFolders = new Set < string > ( [ '.eclipse' , '.vscode' ] ) ; // TODO bubble this out to a setting
@@ -318,14 +305,19 @@ async function syncBazelProjectView() {
318305 . update ( 'watcherExclude' , newFilesWatcherExclude )
319306 . then ( ( x ) =>
320307 window
321- . showInformationMessage (
308+ . showWarningMessage (
322309 'File watcher exclusions are out of date. Please reload the window to apply the change' ,
323310 ...[ 'Reload' , 'Ignore' ]
324311 )
325312 . then ( ( opt ) => {
326313 if ( opt === 'Reload' ) {
327314 commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
328315 }
316+ if ( opt === 'Ignore' ) {
317+ workspace
318+ . getConfiguration ( 'bazel.projectview' )
319+ . update ( 'updateFileWatcherExclusion' , false ) ;
320+ }
329321 } )
330322 ) ;
331323 }
0 commit comments