add explorer extension
- Commit
00c536421c998c12164f1a01f1166afef83b0559- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-20 16:17 UTC (4 months ago)
- Parents
444c6b3
Diff
gradle-module-explorer/.gitignore
diff --git a/gradle-module-explorer/.gitignore b/gradle-module-explorer/.gitignorenew file mode 100644index 0000000000..d3e15b1e69--- /dev/null+++ b/gradle-module-explorer/.gitignore@@ -0,0 +1,3 @@+node_modules/+out/+*.vsix
gradle-module-explorer/.vscode/launch.json
diff --git a/gradle-module-explorer/.vscode/launch.json b/gradle-module-explorer/.vscode/launch.jsonnew file mode 100644index 0000000000..0163a56d26--- /dev/null+++ b/gradle-module-explorer/.vscode/launch.json@@ -0,0 +1,14 @@+{+ "version": "0.2.0",+ "configurations": [+ {+ "name": "Run Gradle Module Explorer",+ "type": "extensionHost",+ "request": "launch",+ "args": [+ "--extensionDevelopmentPath=${workspaceFolder}",+ "${workspaceFolder}/.."+ ]+ }+ ]+}
gradle-module-explorer/.vscodeignore
diff --git a/gradle-module-explorer/.vscodeignore b/gradle-module-explorer/.vscodeignorenew file mode 100644index 0000000000..feaceea766--- /dev/null+++ b/gradle-module-explorer/.vscodeignore@@ -0,0 +1,3 @@+.vscode/**+node_modules/**+.gitignore
gradle-module-explorer/README.md
diff --git a/gradle-module-explorer/README.md b/gradle-module-explorer/README.mdnew file mode 100644index 0000000000..588c5bbf2c--- /dev/null+++ b/gradle-module-explorer/README.md@@ -0,0 +1,56 @@+# Gradle Module Explorer++A VS Code extension that adds a custom **Modules** view to the activity bar for this+Gradle multi-module project. Written in plain JavaScript — no build step, no `npm install`+required to run it.++## What it shows++- A flat list of every Gradle module from `settings.gradle.kts`, using the Gradle+ colon path as the label (e.g. `games:chess`, `sdk:openassistant`).+- Top-level modules are sorted **alphabetically**, with the `library:*` group and then+ the `sdk:*` group pinned to the **bottom**.+- Expanding a module shows its **real filesystem**, with two things filtered out:+ - **Nested-module folders** (they appear as their own top-level entries instead).+ - **Build/IDE clutter**: `build/`, `.gradle/`, `.idea/`, `.cxx/`, `.kotlin/`, `out/`,+ `.git/`, `.DS_Store`.+- Clicking a file opens it. A **refresh** button (top-right of the view) re-reads+ `settings.gradle.kts`; it also auto-refreshes when that file changes.++The extension only activates in a workspace that contains a Gradle settings file+(`workspaceContains:settings.gradle.kts`), so it stays dormant in other projects.++## Run it (F5, no toolchain needed)++1. Open the `gradle-module-explorer` folder in VS Code.+2. Press **F5** ("Run Gradle Module Explorer").++This launches an Extension Development Host with the parent repo (`..`) already open, and+the **Modules** icon appears in the activity bar. Because it's plain JS, there is nothing+to compile.++## Install it permanently (optional)++Packaging a `.vsix` requires Node/npm (not currently on this machine). Once Node is+available:++```bash+cd gradle-module-explorer+npx @vscode/vsce package+code --install-extension gradle-module-explorer-0.0.1.vsix+```++Because it is gated on `settings.gradle.kts`, it only shows up when you open a Gradle+workspace.++## How modules are discovered++Modules come from parsing `include(":...")` statements in `settings.gradle.kts`. The+Gradle path maps to disk by replacing `:` with the path separator (e.g. `:games:chess`+→ `games/chess`), which matches this repo's default layout.++## Files++- `extension.js` — all the logic (module parsing, sorting, tree data provider).+- `package.json` — view container, view, command, and activation declarations.+- `resources/modules.svg` — activity-bar icon.
gradle-module-explorer/extension.js
diff --git a/gradle-module-explorer/extension.js b/gradle-module-explorer/extension.jsnew file mode 100644index 0000000000..d35a44604a--- /dev/null+++ b/gradle-module-explorer/extension.js@@ -0,0 +1,212 @@+const vscode = require('vscode');+const fs = require('fs');+const path = require('path');++/** Directory/file names hidden from every filesystem view (Gradle/IDE clutter). */+const IGNORED_NAMES = new Set([+ 'build',+ '.gradle',+ '.idea',+ '.cxx',+ '.kotlin',+ 'out',+ '.git',+ '.DS_Store',+]);++/** First workspace folder that contains a Gradle settings file, else the first folder. */+function findGradleRoot() {+ const folders = vscode.workspace.workspaceFolders;+ if (!folders || folders.length === 0) {+ return undefined;+ }+ for (const folder of folders) {+ const root = folder.uri.fsPath;+ if (+ fs.existsSync(path.join(root, 'settings.gradle.kts')) ||+ fs.existsSync(path.join(root, 'settings.gradle'))+ ) {+ return root;+ }+ }+ return folders[0].uri.fsPath;+}++/** Read the settings file and extract every included module via `include(":a:b")`. */+function parseModules(root) {+ let content = '';+ for (const name of ['settings.gradle.kts', 'settings.gradle']) {+ const file = path.join(root, name);+ if (fs.existsSync(file)) {+ content = fs.readFileSync(file, 'utf8');+ break;+ }+ }++ const modules = [];+ const seen = new Set();+ const re = /include\s*\(?\s*(["'])\s*:([^"']+)\1/g;+ let match;+ while ((match = re.exec(content)) !== null) {+ const gradlePath = match[2].trim();+ if (!gradlePath || seen.has(gradlePath)) {+ continue;+ }+ seen.add(gradlePath);+ modules.push({+ gradlePath,+ dir: path.join(root, ...gradlePath.split(':')),+ });+ }+ return modules;+}++/** 0 = normal (top, alphabetical), 1 = library group, 2 = sdk group (both at bottom). */+function groupRank(gradlePath) {+ const first = gradlePath.split(':')[0];+ if (first === 'library') {+ return 1;+ }+ if (first === 'sdk') {+ return 2;+ }+ return 0;+}++function sortModules(modules) {+ return [...modules].sort((a, b) => {+ const ra = groupRank(a.gradlePath);+ const rb = groupRank(b.gradlePath);+ if (ra !== rb) {+ return ra - rb;+ }+ return a.gradlePath.localeCompare(b.gradlePath);+ });+}++class ModuleTreeProvider {+ constructor() {+ this._onDidChangeTreeData = new vscode.EventEmitter();+ this.onDidChangeTreeData = this._onDidChangeTreeData.event;+ this.modules = [];+ this.moduleDirs = [];+ this.reload();+ }++ refresh() {+ this.reload();+ this._onDidChangeTreeData.fire();+ }++ reload() {+ this.root = findGradleRoot();+ this.modules = this.root ? sortModules(parseModules(this.root)) : [];+ this.moduleDirs = this.modules.map((m) => m.dir);+ }++ getTreeItem(node) {+ if (node.kind === 'module') {+ const item = new vscode.TreeItem(+ node.module.gradlePath,+ vscode.TreeItemCollapsibleState.Collapsed,+ );+ item.resourceUri = vscode.Uri.file(node.module.dir);+ item.iconPath = new vscode.ThemeIcon('package');+ item.tooltip = node.module.dir;+ item.contextValue = 'gradleModule';+ return item;+ }++ if (node.kind === 'dir') {+ // Passing a Uri gives us the themed folder icon and the basename label.+ return new vscode.TreeItem(+ vscode.Uri.file(node.path),+ vscode.TreeItemCollapsibleState.Collapsed,+ );+ }++ const item = new vscode.TreeItem(+ vscode.Uri.file(node.path),+ vscode.TreeItemCollapsibleState.None,+ );+ item.command = {+ command: 'vscode.open',+ title: 'Open',+ arguments: [vscode.Uri.file(node.path)],+ };+ return item;+ }++ getChildren(node) {+ if (!node) {+ return this.modules.map((module) => ({ kind: 'module', module }));+ }+ if (node.kind === 'file') {+ return [];+ }+ const dir = node.kind === 'module' ? node.module.dir : node.path;+ return this.readDir(dir);+ }++ /** True if `dir` is a module directory or an ancestor of one (a nested-module subtree). */+ isModuleSubtree(dir) {+ return this.moduleDirs.some(+ (md) => md === dir || md.startsWith(dir + path.sep),+ );+ }++ readDir(dir) {+ let entries;+ try {+ entries = fs.readdirSync(dir, { withFileTypes: true });+ } catch (e) {+ return [];+ }++ const dirs = [];+ const files = [];+ for (const entry of entries) {+ if (IGNORED_NAMES.has(entry.name)) {+ continue;+ }+ const full = path.join(dir, entry.name);+ if (entry.isDirectory()) {+ if (this.isModuleSubtree(full)) {+ continue; // Shown as its own top-level module entry instead.+ }+ dirs.push({ kind: 'dir', path: full });+ } else if (entry.isFile()) {+ files.push({ kind: 'file', path: full });+ }+ }++ const byBasename = (a, b) =>+ path.basename(a.path).localeCompare(path.basename(b.path));+ dirs.sort(byBasename);+ files.sort(byBasename);+ return [...dirs, ...files];+ }+}++function activate(context) {+ const provider = new ModuleTreeProvider();++ context.subscriptions.push(+ vscode.window.registerTreeDataProvider('gradleModuleExplorer.view', provider),+ vscode.commands.registerCommand('gradleModuleExplorer.refresh', () =>+ provider.refresh(),+ ),+ );++ const watcher = vscode.workspace.createFileSystemWatcher(+ '**/settings.gradle{.kts,}',+ );+ watcher.onDidChange(() => provider.refresh());+ watcher.onDidCreate(() => provider.refresh());+ watcher.onDidDelete(() => provider.refresh());+ context.subscriptions.push(watcher);+}++function deactivate() {}++module.exports = { activate, deactivate };
gradle-module-explorer/package.json
diff --git a/gradle-module-explorer/package.json b/gradle-module-explorer/package.jsonnew file mode 100644index 0000000000..7e56630824--- /dev/null+++ b/gradle-module-explorer/package.json@@ -0,0 +1,55 @@+{+ "name": "gradle-module-explorer",+ "displayName": "Gradle Module Explorer",+ "description": "Custom source tree that lists Gradle modules (flattened with colon paths) with library/sdk grouped at the bottom.",+ "version": "0.0.1",+ "publisher": "modern-apps",+ "private": true,+ "engines": {+ "vscode": "^1.75.0"+ },+ "categories": [+ "Other"+ ],+ "activationEvents": [+ "workspaceContains:settings.gradle.kts",+ "workspaceContains:settings.gradle"+ ],+ "main": "./extension.js",+ "contributes": {+ "viewsContainers": {+ "activitybar": [+ {+ "id": "gradleModuleExplorer",+ "title": "Modules",+ "icon": "resources/modules.svg"+ }+ ]+ },+ "views": {+ "gradleModuleExplorer": [+ {+ "id": "gradleModuleExplorer.view",+ "name": "Gradle Modules"+ }+ ]+ },+ "commands": [+ {+ "command": "gradleModuleExplorer.refresh",+ "title": "Refresh Modules",+ "category": "Gradle Modules",+ "icon": "$(refresh)"+ }+ ],+ "menus": {+ "view/title": [+ {+ "command": "gradleModuleExplorer.refresh",+ "when": "view == gradleModuleExplorer.view",+ "group": "navigation"+ }+ ]+ }+ }+}
gradle-module-explorer/resources/modules.svg
diff --git a/gradle-module-explorer/resources/modules.svg b/gradle-module-explorer/resources/modules.svgnew file mode 100644index 0000000000..1c01adc4c5--- /dev/null+++ b/gradle-module-explorer/resources/modules.svg@@ -0,0 +1,5 @@+<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round">+ <path d="M12 2.5l8.5 4.25L12 11 3.5 6.75 12 2.5z"/>+ <path d="M3.5 12L12 16.25 20.5 12"/>+ <path d="M3.5 17.25L12 21.5 20.5 17.25"/>+</svg>