diff --git a/docs/config/overview.md b/docs/config/overview.md index 45f1e1c..b81bc30 100644 --- a/docs/config/overview.md +++ b/docs/config/overview.md @@ -9,9 +9,9 @@ They are, in order of parsing / precidence (last location wins): - GitHub Action arguments - Environment variables - Command-line flags (CLI) - - Rich-codex config files + - Rich-codex config files (`.rich-codex.yml`) - Per-image: - - Rich-codex config files + - Rich-codex config files (`.rich-codex.yml`) - Markdown config diff --git a/docs/inputs/config_file.md b/docs/inputs/config_file.md index 161b6bb..01f2cc1 100644 --- a/docs/inputs/config_file.md +++ b/docs/inputs/config_file.md @@ -54,3 +54,78 @@ outputs: There are many other config keys also available. See the [configuration docs](../config/overview.md) for more details. + +### Install IDE Validation + +You can validate your `.rich-codex.yml` files in your IDEs using JSONSchema. + +#### VSCode + +1. Install the [VSCode-YAML extension](https://marketplace.visualstudio.com/items?itemName=redhat.vscode-yaml) + +2. In your repo, create a `.vscode/settings.jsonc` or `.vscode/settings.template.jsonc` file containing the following data. This is what tells the extension which schema to associate with each file. + +```json +{ + "yaml.schemas": { + "https://raw.githubusercontent.com/ewels/rich-codex/main/src/rich_codex/config-schema.yml": [ + ".rich-codex.yml", + ".rich-codex.yaml" + ] + } +} +``` + +3. To prompt other users to install the YAML extension, create a `.vscode/extensions.json` file containing the following data inside your repo: + +```json +{ + "recommendations": ["redhat.vscode-yaml"] +} +``` + +#### JetBrains (PyCharm, IntelliJ, etc.) + +There are two ways to set this up. + +You can either add the following data to your `.idea/jsonSchemas.xml`: + +```xml + + + + + + + + + + + + + + + + +``` + +Or you can do this manually in **Preferences > Languages & Frameworks > Schemas and DTDs > Json Schema Mappings**: + +- **Name**: `rich-codex` +- **Schema File or URL**: `https://raw.githubusercontent.com/dbt-labs/dbt-jsonschema/main/schemas/dbt_project.json` +- **Schema Version:** JSON schema version 4 +- **Mappings**: + - `.rich-codex.yml` + - `.rich-codex.yaml` diff --git a/src/rich_codex/codex_search.py b/src/rich_codex/codex_search.py index 5e6e2b6..ac2129a 100644 --- a/src/rich_codex/codex_search.py +++ b/src/rich_codex/codex_search.py @@ -30,6 +30,7 @@ def __init__( no_confirm, snippet_syntax, timeout, + working_dir, before_command, after_command, hide_command, @@ -53,12 +54,20 @@ def __init__( self.search_exclude = ["**/.git*", "**/.git*/**", "**/node_modules/**"] if search_exclude is not None: self.search_exclude.extend(self._clean_list(search_exclude.splitlines())) - self.configs = [".rich-codex.yml", ".github/rich-codex.yml", "docs/img/rich-codex.yml"] + self.configs = [ + ".rich-codex.yml", + ".rich-codex.yaml", + ".github/rich-codex.yml", + ".github/rich-codex.yaml", + "docs/img/rich-codex.yml", + "docs/img/rich-codex.yaml", + ] if configs is not None: self.configs.extend(self._clean_list(configs.splitlines())) self.no_confirm = no_confirm self.snippet_syntax = snippet_syntax self.timeout = timeout + self.working_dir = working_dir self.before_command = before_command self.after_command = after_command self.hide_command = hide_command @@ -83,6 +92,7 @@ def __init__( self.class_config_attrs = [ "snippet_syntax", "timeout", + "working_dir", "before_command", "after_command", "hide_command", diff --git a/src/rich_codex/config-schema.yml b/src/rich_codex/config-schema.yml index 17e7eff..e9b988c 100644 --- a/src/rich_codex/config-schema.yml +++ b/src/rich_codex/config-schema.yml @@ -10,6 +10,7 @@ properties: # Shared config options snippet_syntax: { "$ref": "#/$defs/snippet_syntax" } timeout: { "$ref": "#/$defs/timeout" } + working_dir: { "$ref": "#/$defs/working_dir" } before_command: { "$ref": "#/$defs/before_command" } after_command: { "$ref": "#/$defs/after_command" } hide_command: { "$ref": "#/$defs/hide_command" } @@ -56,8 +57,6 @@ properties: type: string message: required: Either command or snippet is required - working_dir: - title: Working directory to run command in snippet: title: Code snippet to use type: string @@ -89,6 +88,7 @@ properties: # Shared config options snippet_syntax: { "$ref": "#/$defs/snippet_syntax" } timeout: { "$ref": "#/$defs/timeout" } + working_dir: { "$ref": "#/$defs/working_dir" } before_command: { "$ref": "#/$defs/before_command" } after_command: { "$ref": "#/$defs/after_command" } hide_command: { "$ref": "#/$defs/hide_command" } @@ -114,6 +114,9 @@ properties: timeout: title: Maximum run time for command (seconds) type: integer + working_dir: + title: Working directory to run command in + type: string before_command: title: Setup commands to run before running main output command type: string diff --git a/src/rich_codex/utils.py b/src/rich_codex/utils.py index 0e1510d..c3be00b 100644 --- a/src/rich_codex/utils.py +++ b/src/rich_codex/utils.py @@ -66,6 +66,16 @@ def check_git_status(): return (True, "Git repo looks good.") +def clean_list(unclean_lines): + """Remove empty strings from a list.""" + clean_lines = [] + for line in unclean_lines: + line = line.strip() + if not line.startswith("#") and line: + clean_lines.append(line) + return clean_lines + + def validate_config(schema, config, filename, line_number=None): """Validate a config file string against the rich-codex JSON schema.""" ln_text = f"line {line_number} " if line_number else ""