mirror of
https://github.com/foambubble/foam.git
synced 2026-01-10 14:38:13 -05:00
docs: add contributing to vscode ext
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
> [[todo]] [[good-first-task]] This contribution guide itself could be improved 😅
|
||||
|
||||
Foam is open to contributions of any kind, including but not limited to code, documentation, ideas and feedback. Here's how to get started on contributing to Foam:
|
||||
Foam is open to contributions of any kind, including but not limited to code, documentation, ideas and feedback. Here are some general tips on how to get started on contributing to Foam:
|
||||
|
||||
- Use Foam for yourself, figure out what could be improved.
|
||||
- Check out [[roadmap]] to see what's already in the plans. I have thoughts about how to implement some of these, but open to ideas and code contributions!
|
||||
@@ -12,7 +12,7 @@ Foam is open to contributions of any kind, including but not limited to code, do
|
||||
- Foam code and documentation live in the monorepo at [foambubble/foam](https://github.com/foambubble/foam/)
|
||||
- [/docs](https://github.com/foambubble/foam/docs): documentation and [[recipes]]
|
||||
- [/packages/foam-vscode](https://github.com/foambubble/foam/tree/master/packages/foam-vscode): the core VSCode plugin
|
||||
- [/packages/foam-workspace-manager](https://github.com/foambubble/foam/tree/master/packages/foam-workspace-manager): Foam workspace automations
|
||||
- [/packages/foam-workspace-manager](https://github.com/foambubble/foam/tree/master/packages/foam-workspace-manager): Foam workspace automations
|
||||
- Exceptions to the monorepo are:
|
||||
- The starter template at [foambubble/foam-template](https://github.com/foambubble/)
|
||||
- All other [[recommended-extensions]] live in their respective GitHub repos.
|
||||
@@ -26,3 +26,87 @@ Foam is open to contributions of any kind, including but not limited to code, do
|
||||
[recipes]: recipes "Recipes"
|
||||
[recommended-extensions]: recommended-extensions "Recommended Extensions"
|
||||
[//end]: # "Autogenerated link references"
|
||||
|
||||
## Contributing to the VS Code Extension
|
||||
|
||||
If you're interested in contributing to the VS Code extension (aka `foam-vscode`), this guide will help you get things set up locally.
|
||||
|
||||
1. Clone the repo locally:
|
||||
|
||||
`git clone https://github.com/foambubble/foam.git`
|
||||
2. Install the necessary dependencies by running this command from the root:
|
||||
|
||||
`yarn install`
|
||||
3. This project uses [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/).`foam-vscode` relies on `foam-workspace-manager`. This means we need to compile it before we do any extension development. From the root, run the command:
|
||||
|
||||
`yarn workspace foam-workspace-manager build`
|
||||
4. Now we'll use the launch configuration defined at [`.vscode/launch.json`](https://github.com/foambubble/foam/blob/master/.vscode/launch.json) to start a new extension host of VS Code. From the root, or the `foam-vscode` workspace, press f5.
|
||||
5. In the new extension host of VS Code that launched, open a Foam workspace (e.g. your personal one, or a test-specific one created from foam-template). This is strictly not necessary, but the extension won't auto-run unless it's in a workspace with a `.vscode/foam`.json file.
|
||||
6. Test a command to make sure it's working as expected. Open the Command Palette (Ctrl/Cmd + Shift + P) and select "Foam: Update Markdown Reference List". If you see no errors, it's good to go!
|
||||
|
||||
### Tutorial: Adding a New Command
|
||||
|
||||
Let's try adding a new command to `foam-vscode`.
|
||||
1. Navigate to `packages/foam-vscode/src/extension.ts`
|
||||
2. Find the `activate` function
|
||||
3. Register a new command:
|
||||
|
||||
```diff
|
||||
export function activate(context: ExtensionContext) {
|
||||
context.subscriptions.push(
|
||||
commands.registerCommand(
|
||||
"foam-vscode.update-wikilinks",
|
||||
updateReferenceList
|
||||
),
|
||||
+ commands.registerCommand(
|
||||
+ "foam-vscode.hello-friend",
|
||||
+ () => {
|
||||
+ . window.showInformationMessage("Hello, friend!);
|
||||
+ }
|
||||
+ ),
|
||||
workspace.onWillSaveTextDocument(onWillSave),
|
||||
languages.registerCodeLensProvider(
|
||||
mdDocSelector,
|
||||
new WikilinkReferenceCodeLensProvider()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
```
|
||||
4. Navigate to `packages/foam-vscode/package.json`
|
||||
5. Add your command to the `contributes.commands` array:
|
||||
|
||||
```diff
|
||||
"contributes": {
|
||||
"commands": [
|
||||
{
|
||||
"command": "foam-vscode.update-wikilinks",
|
||||
"title": "Foam: Update Markdown Reference List"
|
||||
+ },
|
||||
+ {
|
||||
+ "command": "foam-vscode.hello-friend",
|
||||
+ "title": "Foam: Hello Friend",
|
||||
+ },
|
||||
]
|
||||
},
|
||||
```
|
||||
6. Press f5 to run the new extension host, or restart the extension host if it's already running.
|
||||
7. Test out your new command. Open the Command Palette (Ctrl/Cmd + Shift + P) and select "Foam: Hello Friend". You should see an information pop up in the corner of the screen.
|
||||
|
||||
And that's how you add new commands! We look forward to your contributions.
|
||||
|
||||
More resources:
|
||||
- [Your First Extension](https://code.visualstudio.com/api/get-started/your-first-extension)
|
||||
- [`vscode-extension-samples`](https://github.com/microsoft/vscode-extension-samples)
|
||||
|
||||
### F.A.Q.
|
||||
|
||||
**How do I write a test for my extension addition?**
|
||||
|
||||
This is still a work in progress. We've opted for [Jest](https://jestjs.io/) as our testing framework. There are currently no end-to-end tests (contributions are welcome!). However, we would encourage you to write tests for anything that you can test. We're happy to discuss on PRs too!
|
||||
|
||||
**How do I know if using the local version of the Foam extension vs. the produciton one while testing locally?**
|
||||
|
||||
When you start the extension development host, the local version of the extension "shadows" or overrides any installed versions of the package with the same ID. So when you F5/start the extension host, you should always be running the local version, plus any other extensions your workspace/vscode is configured to run.
|
||||
|
||||
As far as we know, you can't run the "shadowed" base install while running the local extension
|
||||
Reference in New Issue
Block a user