dsl_knowledge/entry.rs
1//! Shape of a single knowledge-base entry.
2
3use serde::Serialize;
4
5/// One entry in the knowledge base.
6///
7/// `signature` is set only for functions; for keywords and types it stays
8/// `None` because they don't have a meaningful arity.
9#[derive(Debug, Clone, Serialize)]
10pub struct Entry {
11 /// Display label in canonical case (`"SELECT"`, `"now"`, `"UUID"`).
12 pub label: &'static str,
13 /// What this entry represents. Drives the LSP completion item kind.
14 pub kind: Kind,
15 /// One-line semantic description.
16 pub doc: &'static str,
17 /// Optional formal signature, only for functions.
18 pub signature: Option<&'static str>,
19 /// Short SQL snippet showing canonical usage.
20 pub example: &'static str,
21 /// Link to the canonical Postgres documentation page.
22 pub url: &'static str,
23}
24
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
26pub enum Kind {
27 Keyword,
28 Type,
29 Function,
30}
31
32/// Canonical Postgres docs base URL. Every `Entry::url` resolves against
33/// this string so URLs stay internally consistent.
34pub const PG_DOCS_BASE: &str = "https://www.postgresql.org/docs/current/";
35
36/// Helper used by the per-table seed functions to build a Postgres docs URL
37/// from a relative path fragment.
38pub(crate) fn pg(path: &'static str) -> &'static str {
39 // Allocate once at first call and leak. The table is built once and
40 // never freed, so leaking is exactly the right ownership shape.
41 Box::leak(format!("{PG_DOCS_BASE}{path}").into_boxed_str())
42}