Skip to content

Commit 799bbb8

Browse files
authored
Merge pull request #4 from VSC-NeuroPilot/chore/conventions
Add conventions to contributors index
2 parents 1eb4398 + 01afaa8 commit 799bbb8

2 files changed

Lines changed: 74 additions & 2 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ pnpm-debug.log*
2222
.DS_Store
2323

2424
# jetbrains setting folder
25-
.idea/
25+
.idea/
26+
27+
# project files
28+
project-files/

src/content/docs/contributors/index.mdx

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Contributing homepage
33
description: Contributing to NeuroPilot? This page will help get you started!
44
---
55

6+
import { Aside } from '@astrojs/starlight/components'
7+
68
{/* ktrain just wants to write all this so he doesn't forget */}
79

810
To begin contributing, you should read up on the specific area you want to contribute to.
@@ -24,4 +26,71 @@ To begin contributing, you should read up on the specific area you want to contr
2426
- Put everything you're working on inside `project-files/`. This is a folder that is gitignored & vscodeignored by default, allowing you to store work-in-progress files without leaving them untracked.
2527
- Try to open an issue for feature additions/non-patch changes. This will allow us to track progress via milestone, and also allow discussion while being able to link to other issues/PRs.
2628
- Discussing on the thread in the Neuro Discord is also okay, it can also be used to post progress updates that don't need to be posted on GitHub (also gives updates to people who are following the thread but not the repo).
27-
- Anything new, changed or removed should be documented on the docs folder.
29+
- Any new, changed or removed feature should be documented on the [docs repo](https://github.com/VSC-NeuroPilot/docs).
30+
31+
## Conventions
32+
33+
Across NeuroPilot's code, we try to keep a certain convention to ensure productivity and familiarity.
34+
Below is a compilation of our conventions that we use in the code.
35+
36+
<Aside>
37+
38+
Some conventions may have been violated in early code, before these conventions were "standardised".
39+
We're working to refactor these eventually, but going forward everything must follow the conventions below.
40+
41+
</Aside>
42+
43+
### Naming conventions
44+
45+
- Types and type interfaces are capitalised via PascalCase. Functions are capitalised via camelCase. Constants that are initialised at the top of a file are in MACRO_CASE.
46+
- Handler functions follow the `handle<ActionName>` convention, where `<ActionName>` is the name of the action converted to PascalCase (`handle` already takes the first word, so no camelCase for the `<ActionName>` part).
47+
- The object with all the action data that governs how actions are sent, handled and validated follow the `<type>Actions` convention, where `<type>` is the name of the action category converted to camelCase.
48+
- Registration functions that register actions follow the `register<Type>Actions` conventions, where `<Type>` is the name of the action category converted to PascalCase (for the same reasons as handler functions)
49+
- Validator functions often, but aren't *strictly* required to, follow the `validate<Purpose>` or `<Purpose>Validation` conventions, where `<Purpose>` is what the function is validating, converted to PascalCase/camelCase respectively.
50+
- Imports from `@types/vscode` often use the `import * as vscode from 'vscode'` import pattern.
51+
52+
### Placement conventions
53+
54+
These placement conventions apply to files which contain actions (such as `file_actions.ts` or `editing.ts`).
55+
56+
```ts
57+
import * as vscode from 'vscode';
58+
import { NEURO } from '@/constants';
59+
import { PERMISSIONS, getPermissionLevel } from '@/config'
60+
import { RCEAction, stripToActions, ActionData, ActionValidationResult } from '@/neuro_client_helper';
61+
// other imports
62+
63+
function validatePath(actionData: ActionData): ActionValidationResult {
64+
// code goes here
65+
};
66+
67+
// other functions related to validation go here
68+
69+
export const pathActions = {
70+
move_file: {
71+
name: 'move_file', // must match exactly the object key
72+
description: 'Move a file from one place to another.',
73+
schema: {
74+
// schema goes here
75+
},
76+
// other info
77+
},
78+
// other actions similarly structured here
79+
} satisfies Record<string, RCEAction>;
80+
81+
export function registerPathActions() { // only one of these per file!
82+
if (getPermissionLevel(PERMISSIONS.moveFiles)) {
83+
NEURO.client?.registerActions(stripToActions([
84+
pathActions.move_file,
85+
// other actions
86+
]));
87+
},
88+
};
89+
90+
// All handlers go under here
91+
92+
export function handleMoveFile(actionData: ActionData) {
93+
// handling code goes here
94+
};
95+
96+
```

0 commit comments

Comments
 (0)