-
Notifications
You must be signed in to change notification settings - Fork 88
Add command to create a Swift DocC documentation catalog #2006
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import * as fs from "fs"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably use |
||
| 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."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: This error message is a bit vague. Can we change it to something like suggestion: We can also make it less likely for this situation to occur by only showing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also you don't want to |
||
| 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: We can't assume there will only be a single workspace folder. The command should guide the user through creating a catalog in any workspace folder they wish to use. |
||
| const doccDir = path.join(rootPath, `${moduleName}.docc`); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: We can't assume that the user will only place a catalog at the root of the workspace. Documentation catalogs can be located anywhere in the project structure. However, they are most commonly placed within targets from the |
||
| const markdownFile = path.join(doccDir, `${moduleName}.md`); | ||
|
|
||
| if (fs.existsSync(doccDir)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: We can show this error in the input and not allow continuing instead of forcing the user to restart the whole command. See the create new project command for an example of this. |
||
| 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( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| `Created DocC documentation catalog: ${moduleName}.docc` | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Missing copyright header.