diff --git a/docs-vs-code.sidebars.yaml b/docs-vs-code.sidebars.yaml index 17052147..530b2155 100644 --- a/docs-vs-code.sidebars.yaml +++ b/docs-vs-code.sidebars.yaml @@ -10,7 +10,12 @@ - group: Usage page: docs/vscode/using-redocly-vscode.md items: + - label: Type hints + page: docs/vscode/type-hints.md - label: Cursor context page: docs/vscode/cursor-context.md + - label: Type hints vs Cursor context + page: docs/vscode/type-hints-vs-cursor-context.md - label: Live documentation preview page: docs/vscode/live-preview.md + diff --git a/docs/vscode/type-hints-vs-cursor-context.md b/docs/vscode/type-hints-vs-cursor-context.md new file mode 100644 index 00000000..6813c439 --- /dev/null +++ b/docs/vscode/type-hints-vs-cursor-context.md @@ -0,0 +1,48 @@ +# Type hints vs Cursor context + +The Redocly OpenAPI VS Code extension now includes [Type hints](./type-hints.md), a lightweight alternative to [Cursor context](./cursor-context.md) for identifying node types. +With type hints you can find the `subject` and `property` values you need for [configurable rules](../cli/rules/configurable-rules#configurable-rules) by hovering over any node in your API description (OpenAPI, AsyncAPI, Arazzo, and others). + +## Example: enforcing snake_case operation IDs + +Suppose you need to change all operation IDs to use snake_case instead of camelCase. +To avoid missing any operation, let's create a configurable linting rule that checks every operation ID in the OpenAPI document. + +When writing your rule, you need to target a specific [node](../../learn/openapi/openapi-visual-reference/openapi-node-types) with the `subject` and `property` to which the rule applies. +To find these values, you can either use Cursor context or Type hints. + +### Use [Type hints](./type-hints.md) + +To use [Type hints](./type-hints.md) to find the values of `subject` and `property`: + +1. Hover over `operationId`. +1. Read `subject` and `property` directly from the tooltip. + +![type-hints-tooltip](../../static/images/vscode/openapi-vscode-type-hints.png) + +This approach requires fewer steps and keeps you inside the immediate context of your work, without affecting your focus. + +### Use Cursor context + +To use [Cursor context](./cursor-context.md) to find the values of `subject` and `property`: + +1. Place your cursor on `operationId`. +1. Open the Cursor context panel. +1. Find `subject` and `property` in the panel. + +![cursor-context-panel](../../static/images/vscode/openapi-vscode-cursor-context-migration.png) + +### Rule configuration + +```yaml +extends: + - recommended +rules: + struct: error + rule/id-casing: + subject: + type: Operation + property: operationId + assertions: + casing: snake_case +``` diff --git a/docs/vscode/type-hints.md b/docs/vscode/type-hints.md new file mode 100644 index 00000000..6b0d76c0 --- /dev/null +++ b/docs/vscode/type-hints.md @@ -0,0 +1,21 @@ +# Type hints + +Type hints is a hover feature that helps you identify the correct [node types](../../learn/openapi/openapi-visual-reference/openapi-node-types) used in [configurable rules](../cli/rules/configurable-rules#configurable-rules) and [custom plugins](../cli/custom-plugins#custom-plugins) for writing rules or decorators. + +When you hover over a node in your API description, a tooltip displays the node type, a short description, and a link to the corresponding documentation section. + +## Type hints example + +![type-hints](../../static/images/vscode/openapi-vscode-type-hints.png) + +## Type hints structure + +```md +type [subject.type] › property [subject.property] + +[Documentation link when available] + +paths › [node tree path] + +[description] +``` diff --git a/static/images/vscode/openapi-vscode-cursor-context-migration.png b/static/images/vscode/openapi-vscode-cursor-context-migration.png new file mode 100644 index 00000000..ab0c54cb Binary files /dev/null and b/static/images/vscode/openapi-vscode-cursor-context-migration.png differ diff --git a/static/images/vscode/openapi-vscode-type-hints.png b/static/images/vscode/openapi-vscode-type-hints.png new file mode 100644 index 00000000..e6ef553f Binary files /dev/null and b/static/images/vscode/openapi-vscode-type-hints.png differ