diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58fa93d..3a6023a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest] #, macos-latest] #, windows-latest] # https://github.com/coactions/setup-xvfb/issues/18 + os: [ubuntu-latest, macos-latest] #, windows-latest] # https://github.com/coactions/setup-xvfb/issues/18 steps: - name: Checkout diff --git a/package.json b/package.json index 5de38ae..13523d0 100644 --- a/package.json +++ b/package.json @@ -124,7 +124,13 @@ "bazel.projectview.updateFileWatcherExclusion": { "type": "boolean", "default": true, - "description": "update the files.watcherExclude setting to only watch directories specified in the .bazelproject file. when enabled the window will automatically be reloaded after the change is applied", + "description": "update the files.watcherExclude setting to only watch directories specified in the .bazelproject file.", + "scope": "window" + }, + "bazel.projectview.notification": { + "type": "boolean", + "default": true, + "description": "Display 'sync project view' notification info window on .bazelproject edit", "scope": "window" } } diff --git a/src/extension.ts b/src/extension.ts index f9d94b4..eb8e44a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,9 +5,7 @@ import { ConfigurationTarget, ExtensionContext, FileType, - StatusBarAlignment, TextDocument, - ThemeColor, Uri, commands, extensions, @@ -32,14 +30,6 @@ import { isBazelWorkspaceRoot, } from './util'; -const classpathStatus = window.createStatusBarItem(StatusBarAlignment.Left, 1); -const projectViewStatus = window.createStatusBarItem( - StatusBarAlignment.Left, - 1 -); -const outOfDateClasspaths: Set = new Set(); -classpathStatus.command = Commands.UPDATE_CLASSPATHS_CMD; -projectViewStatus.command = Commands.SYNC_PROJECTS_CMD; const workspaceRoot = getWorkspaceRoot(); export async function activate(context: ExtensionContext) { @@ -61,14 +51,10 @@ export async function activate(context: ExtensionContext) { BazelLanguageServerTerminal.trace('extension activated'); - workspace.onDidChangeTextDocument((event) => { - const doc = event.document; - if (doc.uri.fsPath.includes('bazelproject') && !doc.isDirty) { + workspace.onDidSaveTextDocument((doc) => { + if (doc.fileName.includes('bazelproject')) { toggleBazelProjectSyncStatus(doc); } - if (doc.uri.fsPath.includes('BUILD') && !doc.isDirty) { - toggleBazelClasspathSyncStatus(doc); - } }); context.subscriptions.push( @@ -92,7 +78,7 @@ export async function activate(context: ExtensionContext) { openBazelProjectFile(); showBazelprojectConfig.update('open', false); // only open this file on the first activation of this extension } - syncBazelProjectView(); + syncProjectViewDirectories(); context.subscriptions.push( commands.registerCommand(Commands.OPEN_BAZEL_PROJECT_FILE, () => openBazelProjectFile() @@ -106,7 +92,7 @@ export async function activate(context: ExtensionContext) { context.subscriptions.push( commands.registerCommand( Commands.SYNC_DIRECTORIES_ONLY, - syncBazelProjectView + syncProjectViewDirectories ) ); context.subscriptions.push( @@ -152,9 +138,19 @@ function syncProjectView(): void { return; } - projectViewStatus.hide(); + const launchMode = workspace + .getConfiguration('java.server') + .get('launchMode'); + // if the launchMode is not Standard it should be changed and the window reloaded to apply that change + if (!launchMode || launchMode !== 'Standard') { + workspace + .getConfiguration('java.server') + .update('launchMode', 'Standard') + .then(() => commands.executeCommand('workbench.action.reloadWindow')); + } + executeJavaLanguageServerCommand(Commands.SYNC_PROJECTS).then( - syncBazelProjectView + syncProjectViewDirectories ); } @@ -165,19 +161,6 @@ function updateClasspaths() { ); return; } - outOfDateClasspaths.forEach((uri) => { - BazelLanguageServerTerminal.info(`Updating classpath for ${uri.fsPath}`); - executeJavaLanguageServerCommand( - Commands.UPDATE_CLASSPATHS, - uri.toString() - ).then( - () => outOfDateClasspaths.delete(uri), - (err: Error) => { - BazelLanguageServerTerminal.error(`${err.message}\n${err.stack}`); - } - ); - }); - classpathStatus.hide(); } function runLSCmd() { @@ -210,24 +193,28 @@ function isRedhatJavaReady(): boolean { return false; } -function toggleBazelClasspathSyncStatus(doc: TextDocument) { - classpathStatus.show(); - classpathStatus.text = 'Sync bazel classpath'; - classpathStatus.backgroundColor = new ThemeColor( - 'statusBarItem.warningBackground' - ); - outOfDateClasspaths.add(doc.uri); -} - function toggleBazelProjectSyncStatus(doc: TextDocument) { - projectViewStatus.show(); - projectViewStatus.text = 'Sync bazel project view'; - projectViewStatus.backgroundColor = new ThemeColor( - 'statusBarItem.warningBackground' - ); + if (workspace.getConfiguration('bazel.projectview').get('notification')) { + window + .showWarningMessage( + `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)`, + ...['Java Projects', 'Only Directories', 'Do Nothing'] + ) + .then((val) => { + if (val === 'Java Projects') { + syncProjectView(); + } else if (val === 'Only Directories') { + syncProjectViewDirectories(); + } else if (val === 'Do Nothing') { + workspace + .getConfiguration('bazel.projectview') + .update('notification', false); + } + }); + } } -async function syncBazelProjectView() { +async function syncProjectViewDirectories() { if (workspaceRoot) { BazelLanguageServerTerminal.debug('Syncing bazel project view'); const displayFolders = new Set(['.eclipse', '.vscode']); // TODO bubble this out to a setting @@ -318,7 +305,7 @@ async function syncBazelProjectView() { .update('watcherExclude', newFilesWatcherExclude) .then((x) => window - .showInformationMessage( + .showWarningMessage( 'File watcher exclusions are out of date. Please reload the window to apply the change', ...['Reload', 'Ignore'] ) @@ -326,6 +313,11 @@ async function syncBazelProjectView() { if (opt === 'Reload') { commands.executeCommand('workbench.action.reloadWindow'); } + if (opt === 'Ignore') { + workspace + .getConfiguration('bazel.projectview') + .update('updateFileWatcherExclusion', false); + } }) ); }