金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

writing-hashql-diagnostics

writing-hashql-diagnostics 是面向效率工具的 Agent Skill,来自 hashintel/hash。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

HashQL diagnostic writing patterns using hashql-diagnostics crate. Use when creating error messages, warnings, Labels, Messages, Severity levels, Patches, Suggestions, or improving diagnostic quality in HashQL code.

SKILL.md

下载 MD ↓
namewriting-hashql-diagnostics
descriptionHashQL diagnostic writing patterns using hashql-diagnostics crate. Use when creating error messages, warnings, Labels, Messages, Severity levels, Patches, Suggestions, or improving diagnostic quality in HashQL code.
licenseAGPL-3.0
metadata{"triggers": {"type": "domain", "enforcement": "suggest", "priority": "high", "keywords": ["diagnostic", "hashql-diagnostics", "Label", "Message", "Severity", "Patch", "Suggestions"], "intent-patterns": ["\\b(create|write|add|improve)\\b.*?\\bdiagnostic\\b", "\\b(error|warning)\\b.*?\\bmessage\\b"]}}

HashQL Diagnostic Writing

Provides HASH-specific patterns for writing high-quality diagnostics using the hashql-diagnostics crate, ensuring messages are helpful, actionable, and follow consistent style conventions.

Core Principles

Diagnostics should be helpful, not just correct:

✅ DO:

  • Start messages with lowercase
  • Use backticks for code elements: expected `bool`, found `String`
  • Make messages actionable and specific
  • Use "invalid" not "illegal"
  • Keep help messages as imperatives: "add type annotations"

❌ DON'T:

  • End messages with punctuation (unless multi-sentence)
  • Use apologetic language ("sorry", "unfortunately")
  • Write vague messages ("something went wrong")
  • Capitalize message starts (unless code identifier)

Quick Reference

Creating a Diagnostic

use hashql_diagnostics::{Diagnostic, Label, Message, Severity};

let mut diagnostic = Diagnostic::new(category, Severity::Error)
    .primary(Label::new(span, "expected `bool`, found `String`"));

diagnostic.add_label(Label::new(other_span, "expected because of this"));
diagnostic.add_message(Message::help("try using a comparison"));

Severity Levels

Severity When to Use
Bug Internal compiler error
Fatal Unrecoverable error
Error Must be fixed to compile
Warning Suspicious code to review
Note Informational context

Message Style

// ✅ Good
"cannot find variable `count` in this scope"
"expected `;` after expression"

// ❌ Bad
"Error: Variable not found."  // capitalized, punctuation
"Sorry, there's a type mismatch"  // apologetic

Adding Suggestions

use hashql_diagnostics::{Message, Patch, Suggestions};

let suggestion = Suggestions::patch(Patch::new(span, "corrected_code"));
diagnostic.add_message(
    Message::help("fix the typo").with_suggestions(suggestion)
);

References

来源:hashintel/hash · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本