Instruction file imported from YukikazeOrz/vscode-bold-code (
.github/instructions/best-practices.instructions.md). Copyright stays with the author.
Best Practices
Buttons & Actions
- Don't create a new class or custom CSS to render a button or action. Reuse the existing
Buttonclass (vs/base/browser/ui/button/button.ts) and the existingActiontypes (vs/base/common/actions.ts). This keeps theming, accessibility, and behavior consistent. - Render actions inside a toolbar rather than by hand. Prefer
MenuWorkbenchToolBar(vs/platform/actions/browser/toolbar.ts): give it aMenuIdso actions can be contributed from anywhere (contributions, other components) without coupling. - Use
WorkbenchToolBarwhen you need explicit control over which actions render and where separators go. - Never add a separator while rendering an action. Add separators with the existing
Separatorclass (vs/base/common/actions.ts). - If a
MenuWorkbenchToolBarlives in a widget/view that can be rendered multiple times at once, give the toolbar a scopedIContextKeyServicewhich is scoped to the dom element of that widget/view and set the context keys per individual widget/view instance.
Editor/Session Actions
- Don't assume the action runs on the active editor/session. An action (e.g. one contributed to some editor or session related toolbar) can be triggered for an editor/session that isn't active. The
runmethod receives arguments describing the invocation context (such as the originating editor group or the originating session). - Resolve editor action arguments with
resolveCommandsContext(vs/workbench/browser/parts/editor/editorCommandsContext.ts) to get the correct editor(s) instead of readingeditorService.activeEditor. - Support multi-selection. The resolved editor actions context can contain several editors (e.g. multi-selected tabs).
URI
- Don't hardcode URI scheme strings like
'file','untitled', or'vscode-remote'. Use theSchemasconstants fromvs/base/common/network.ts(e.g.Schemas.file,Schemas.untitled,Schemas.vscodeRemote). - Don't compare URIs with
===oruri.toString(). Use the comparison utilities fromvs/base/common/resources.ts:isEqualfor equality,isEqualOrParentfor containment, andgetComparisonKeywhen a URI is used as a map/set key. These handle path-case sensitivity and fragment/authority correctly. When you need explicit control over case sensitivity, use anExtUriinstance (extUri,extUriIgnorePathCase, orextUriBiasedIgnorePathCase) instead of the bound helpers.
Editor Decorations
- For editor highlights, use a regular editor decoration with an
inlineClassNameorclassNameplus a CSS rule. ICodeEditorService.registerDecorationType/setDecorationsByTypeis reserved for the extension host API and should be avoided at all cost.