docs: document the sample code with TSDoc comments (#195)

* docs: document the sample code with TSDoc comments

Add TSDoc comments to the sample plugin's classes, methods and settings,
and a README section on writing them, so plugins built from the template
start with documented code that editors show on hover.

Closes #100

* docs: make TSDoc comments an optional suggestion
This commit is contained in:
Michael Naumov authored and GitHub committed 2026-12-02 00:27:51 -06:00
1 parent 8f2aea6455
commit 9bb372bc7f
3 files changed
+31

No files matched your search

+6
View File
@@ -63,6 +63,12 @@ Quick starting guide for new plugin devs:
- Together with a custom eslint [plugin](https://github.com/obsidianmd/eslint-plugin) for Obsidan specific code guidelines.
- A GitHub action is preconfigured to automatically lint every commit on all branches.
## Document your code with TSDoc
- The sample code documents its classes, functions and settings with [TSDoc](https://tsdoc.org/) comments (`/** ... */`).
- Your editor shows these comments when you hover over a name or pick it from autocomplete, the same way it shows the documentation in `obsidian.d.ts`.
- You can document your own code the same way if you like. It is optional, and most helpful where a name alone does not explain what something does.
## Funding URL
You can include funding URLs where people who use your plugin can financially support it.
+20
View File
@@ -14,9 +14,19 @@ import {
// Remember to rename these classes and interfaces!
/**
* The plugin's entry point. Obsidian creates one instance of this class
* when the plugin is enabled and calls {@link MyPlugin.onload}.
*/
export default class MyPlugin extends Plugin {
/** The current settings, loaded in {@link MyPlugin.onload}. */
settings!: MyPluginSettings;
/**
* Called when the plugin is enabled. Register commands, views and
* event handlers here, so Obsidian can remove them when the plugin
* is disabled.
*/
async onload() {
await this.loadSettings();
@@ -86,8 +96,16 @@ export default class MyPlugin extends Plugin {
);
}
/**
* Called when the plugin is disabled. Anything registered with the
* `register*` helpers is cleaned up automatically.
*/
onunload() {}
/**
* Loads the saved settings, filling in a default for every value that
* has not been saved yet.
*/
async loadSettings() {
this.settings = Object.assign(
{},
@@ -96,11 +114,13 @@ export default class MyPlugin extends Plugin {
);
}
/** Saves the current settings to the plugin's `data.json`. */
async saveSettings() {
await this.saveData(this.settings);
}
}
/** A modal that shows a short message, opened by the sample commands. */
class SampleModal extends Modal {
onOpen() {
const { contentEl } = this;
+5
View File
@@ -1,14 +1,18 @@
import { App, PluginSettingTab, Setting } from 'obsidian';
import MyPlugin from './main';
/** The settings this plugin saves. */
export interface MyPluginSettings {
/** An example text setting. */
mySetting: string;
}
/** The value of each setting until the user changes it. */
export const DEFAULT_SETTINGS: MyPluginSettings = {
mySetting: 'default',
};
/** The plugin's tab in the Obsidian settings window. */
export class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
@@ -17,6 +21,7 @@ export class SampleSettingTab extends PluginSettingTab {
this.plugin = plugin;
}
/** Builds the tab's content each time the user opens it. */
display(): void {
const { containerEl } = this;