Skip to content

Commit 5e22ac9

Browse files
committed
covert to multi-root workspace
1 parent b72ae4a commit 5e22ac9

File tree

8 files changed

+1081
-237
lines changed

8 files changed

+1081
-237
lines changed

package-lock.json

Lines changed: 808 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@
182182
"command": "bazel.projectview.open",
183183
"title": "Open the Bazel Project View file",
184184
"category": "Bazel"
185+
},
186+
{
187+
"command": "bazel.convert.workspace",
188+
"title": "Convert to Multi-Root workspace",
189+
"category": "Bazel"
185190
}
186191
],
187192
"views": {
@@ -285,7 +290,7 @@
285290
"@typescript-eslint/eslint-plugin": "^6.0.0",
286291
"@typescript-eslint/parser": "^6.0.0",
287292
"@vscode/test-electron": "^2.3.4",
288-
"@vscode/vsce": "^2.22.0",
293+
"@vscode/vsce": "^3.0.0",
289294
"esbuild": "0.19.8",
290295
"esbuild-plugin-eslint": "^0.3.7",
291296
"esbuild-visualizer": "^0.4.1",

src/bazelprojectparser.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,7 @@ export async function getBazelProjectFile(): Promise<BazelProjectView> {
176176

177177
export function readBazelProject(bazelProjectFile: string): BazelProjectView {
178178
return parseProjectFile({
179-
root: workspace.workspaceFolders
180-
? workspace.workspaceFolders[0].uri.fsPath
181-
: './',
179+
root: getWorkspaceRoot(),
182180
imports: [bazelProjectFile],
183181
projectView: {
184182
directories: [],

src/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export namespace Commands {
4444
export const BAZEL_TARGET_KILL = 'bazelTaskOutline.kill';
4545

4646
export const OPEN_BAZEL_PROJECT_FILE = 'bazel.projectview.open';
47+
48+
export const CONVERT_PROJECT_WORKSPACE = 'bazel.convert.workspace';
4749
}
4850

4951
export function executeJavaLanguageServerCommand<T = unknown>(

src/extension.ts

Lines changed: 13 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import { existsSync } from 'fs';
22
import { join } from 'path';
33
import { format } from 'util';
44
import {
5-
ConfigurationTarget,
65
ExtensionContext,
7-
FileType,
86
TextDocument,
9-
Uri,
107
commands,
118
extensions,
129
tasks,
@@ -18,19 +15,19 @@ import {
1815
getBazelTerminal,
1916
} from './bazelLangaugeServerTerminal';
2017
import { BazelTaskManager } from './bazelTaskManager';
21-
import { getBazelProjectFile } from './bazelprojectparser';
2218
import { Commands, executeJavaLanguageServerCommand } from './commands';
2319
import { registerLSClient } from './loggingTCPServer';
20+
import { ProjectViewManager } from './projectViewManager';
2421
import { BazelRunTargetProvider } from './provider/bazelRunTargetProvider';
2522
import { BazelTaskProvider } from './provider/bazelTaskProvider';
26-
import { ExcludeConfig, FileWatcherExcludeConfig } from './types';
2723
import {
2824
getWorkspaceRoot,
2925
initBazelProjectFile,
3026
isBazelWorkspaceRoot,
3127
} from './util';
3228

3329
const workspaceRoot = getWorkspaceRoot();
30+
const workspaceRootName = workspaceRoot.split('/').reverse()[0];
3431

3532
export async function activate(context: ExtensionContext) {
3633
// activates
@@ -39,8 +36,8 @@ export async function activate(context: ExtensionContext) {
3936
// register TCP port with LS
4037
// project view should reflect what's in the LS
4138
// show any directories listed in the .bazelproject file
42-
// fetch all projects loaded into LS and display those too
43-
// show both .vscode and .eclipse folders
39+
// fetch all projects loaded into LS and display those as well
40+
// show .eclipse folder
4441
//
4542

4643
window.registerTreeDataProvider(
@@ -120,6 +117,13 @@ export async function activate(context: ExtensionContext) {
120117
)
121118
);
122119

120+
context.subscriptions.push(
121+
commands.registerCommand(
122+
Commands.CONVERT_PROJECT_WORKSPACE,
123+
ProjectViewManager.covertToMultiRoot
124+
)
125+
);
126+
123127
// trigger a refresh of the tree view when any task get executed
124128
tasks.onDidStartTask((_) => BazelRunTargetProvider.instance.refresh());
125129
tasks.onDidEndTask((_) => BazelRunTargetProvider.instance.refresh());
@@ -214,117 +218,8 @@ function toggleBazelProjectSyncStatus(doc: TextDocument) {
214218
}
215219
}
216220

217-
async function syncProjectViewDirectories() {
218-
if (workspaceRoot) {
219-
BazelLanguageServerTerminal.debug('Syncing bazel project view');
220-
const displayFolders = new Set<string>(['.eclipse', '.vscode']); // TODO bubble this out to a setting
221-
try {
222-
const bazelProjectFile = await getBazelProjectFile();
223-
let viewAll = false;
224-
if (bazelProjectFile.directories.includes('.')) {
225-
viewAll = true;
226-
} else {
227-
bazelProjectFile.directories.forEach((d) => {
228-
const dirRoot = d.split('/').filter((x) => x)[0];
229-
displayFolders.add(dirRoot);
230-
});
231-
bazelProjectFile.targets.forEach((t) =>
232-
displayFolders.add(
233-
t.replace('//', '').replace(/:.*/, '').replace(/\/.*/, '')
234-
)
235-
);
236-
}
237-
238-
workspace.fs.readDirectory(Uri.parse(workspaceRoot)).then(async (val) => {
239-
const dirs = val.filter((x) => x[1] !== FileType.File).map((d) => d[0]);
240-
const workspaceFilesConfig = workspace.getConfiguration('files');
241-
const filesExclude = workspaceFilesConfig.get(
242-
'exclude'
243-
) as ExcludeConfig;
244-
dirs.forEach(
245-
(d) => (filesExclude[d] = viewAll ? false : !displayFolders.has(d))
246-
);
247-
await workspaceFilesConfig.update(
248-
'exclude',
249-
filesExclude,
250-
ConfigurationTarget.Workspace
251-
);
252-
253-
// if the updateFileWatcherExclusion setting is enabled
254-
if (
255-
workspace
256-
.getConfiguration('bazel.projectview')
257-
.get('updateFileWatcherExclusion')
258-
) {
259-
BazelLanguageServerTerminal.debug(
260-
'updating files.watcherExclude setting'
261-
);
262-
263-
const filesWatcherExclude =
264-
workspaceFilesConfig.get<FileWatcherExcludeConfig>(
265-
'watcherExclude',
266-
{}
267-
);
268-
269-
const fileWatcherKeys = Object.keys(filesWatcherExclude);
270-
const hasOldEntry = fileWatcherKeys.filter(
271-
(k) => k.includes('.vscode') && k.includes('.eclipse')
272-
).length;
273-
274-
const fileWatcherExcludePattern = viewAll
275-
? ''
276-
: `**/!(${Array.from(displayFolders).join('|')})/**`;
277-
278-
if (viewAll) {
279-
// if viewAll and existing config doesn't contain .vscode/.eclipse return
280-
if (!hasOldEntry) {
281-
return;
282-
}
283-
} else {
284-
// if !viewAll and existing config contains identical entry return
285-
if (fileWatcherKeys.includes(fileWatcherExcludePattern)) {
286-
return;
287-
}
288-
}
289-
290-
// copy the old config obj, but remove any previous exclude based on the .bazelproject file
291-
const newFilesWatcherExclude: FileWatcherExcludeConfig = {};
292-
for (const val in filesWatcherExclude) {
293-
if (!(val.includes('.eclipse') && val.includes('.vscode'))) {
294-
newFilesWatcherExclude[val] = filesWatcherExclude[val];
295-
}
296-
}
297-
298-
if (fileWatcherExcludePattern) {
299-
newFilesWatcherExclude[fileWatcherExcludePattern] = true;
300-
}
301-
302-
// reload the workspace to make the updated file watcher exclusions take effect
303-
workspaceFilesConfig
304-
.update('watcherExclude', newFilesWatcherExclude)
305-
.then((x) =>
306-
window
307-
.showWarningMessage(
308-
'File watcher exclusions are out of date. Please reload the window to apply the change',
309-
...['Reload', 'Ignore']
310-
)
311-
.then((opt) => {
312-
if (opt === 'Reload') {
313-
commands.executeCommand('workbench.action.reloadWindow');
314-
}
315-
if (opt === 'Ignore') {
316-
workspace
317-
.getConfiguration('bazel.projectview')
318-
.update('updateFileWatcherExclusion', false);
319-
}
320-
})
321-
);
322-
}
323-
});
324-
} catch (err) {
325-
throw new Error(`Could not read bazelproject file: ${err}`);
326-
}
327-
}
221+
function syncProjectViewDirectories() {
222+
ProjectViewManager.updateProjectView();
328223
}
329224

330225
function openBazelProjectFile() {

0 commit comments

Comments
 (0)