Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@
"command": "swift.generateSourcekitConfiguration",
"title": "Generate SourceKit-LSP Configuration",
"category": "Swift"
},
{
"command": "swift.createDocumentationCatalog",
"title": "Create Documentation Catalog",
"category": "Swift"
}
],
"configuration": [
Expand Down
5 changes: 5 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { WorkspaceContext } from "./WorkspaceContext";
import { attachDebugger } from "./commands/attachDebugger";
import { cleanBuild, debugBuild, runBuild } from "./commands/build";
import { captureDiagnostics } from "./commands/captureDiagnostics";
import { createDocumentationCatalog } from "./commands/createDocumentationCatalog";
import { createNewProject } from "./commands/createNewProject";
import { editDependency } from "./commands/dependencies/edit";
import { resolveDependencies } from "./commands/dependencies/resolve";
Expand Down Expand Up @@ -350,6 +351,10 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(packagePath));
}),
vscode.commands.registerCommand("swift.openDocumentation", () => openDocumentation()),
vscode.commands.registerCommand(
"swift.createDocumentationCatalog",
async () => await createDocumentationCatalog()
),
vscode.commands.registerCommand(
Commands.GENERATE_SOURCEKIT_CONFIG,
async () => await generateSourcekitConfiguration(ctx)
Expand Down
40 changes: 40 additions & 0 deletions src/commands/createDocumentationCatalog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";

export async function createDocumentationCatalog(): Promise<void> {
const folders = vscode.workspace.workspaceFolders;
if (!folders || folders.length === 0) {
await vscode.window.showErrorMessage("Open a workspace first.");
return;
}

const moduleName = await vscode.window.showInputBox({
prompt: "Enter Swift module name",
placeHolder: "MyModule",
validateInput: value =>
value.trim().length === 0 ? "Module name cannot be empty" : undefined,
});

if (!moduleName) {
return; // user cancelled
}

const rootPath = folders[0].uri.fsPath;
const doccDir = path.join(rootPath, `${moduleName}.docc`);
const markdownFile = path.join(doccDir, `${moduleName}.md`);

if (fs.existsSync(doccDir)) {
await vscode.window.showErrorMessage(
`Documentation catalog "${moduleName}.docc" already exists.`
);
return;
}

fs.mkdirSync(doccDir, { recursive: true });
fs.writeFileSync(markdownFile, `# ${moduleName}\n`, { encoding: "utf8" });

await vscode.window.showInformationMessage(
`Created DocC documentation catalog: ${moduleName}.docc`
);
}