Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(hogql): generate language service function list (#100911)

Paweł Szczur836337ecadf5
diff --git a/posthog/hogql/functions/generate_language_service_functions.py b/posthog/hogql/functions/generate_language_service_functions.py
new file mode 100644
index 000000000000..6ece17e2c38f
--- /dev/null
+++ b/posthog/hogql/functions/generate_language_service_functions.py
@@ -0,0 +1,33 @@
+import sys
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[3]
+sys.path.insert(0, str(REPO_ROOT))
+
+from posthog.hogql.functions.mapping import ALL_EXPOSED_FUNCTION_NAMES # noqa: E402
+
+OUTPUT_PATH = REPO_ROOT / "services/hogql-language-service/internal/completion/functions.go"
+
+
+def render() -> str:
+ names = sorted(set(ALL_EXPOSED_FUNCTION_NAMES))
+ lines = [" ".join(names[index : index + 20]) for index in range(0, len(names), 20)]
+ body = "\n".join(lines)
+ return f"""// Code generated by posthog/hogql/functions/generate_language_service_functions.py; DO NOT EDIT.
+
+package completion
+
+import "strings"
+
+var hogQLFunctions = strings.Fields(`
+{body}
+`)
+"""
+
+
+def main() -> None:
+ OUTPUT_PATH.write_text(render(), encoding="utf-8")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/posthog/hogql/test/test_generated_language_service_functions.py b/posthog/hogql/test/test_generated_language_service_functions.py
new file mode 100644
index 000000000000..710d68a6e6e3
--- /dev/null
+++ b/posthog/hogql/test/test_generated_language_service_functions.py
@@ -0,0 +1,8 @@
+from posthog.hogql.functions.generate_language_service_functions import OUTPUT_PATH, render
+
+
+def test_language_service_functions_match_generated_output() -> None:
+ assert OUTPUT_PATH.read_text(encoding="utf-8") == render(), (
+ "HogQL language service functions are out of sync with ALL_EXPOSED_FUNCTION_NAMES. "
+ "Run: python posthog/hogql/functions/generate_language_service_functions.py"
+ )
diff --git a/services/hogql-language-service/internal/completion/functions.go b/services/hogql-language-service/internal/completion/functions.go
index 90dbb5792a63..7bc94dca248d 100644
--- a/services/hogql-language-service/internal/completion/functions.go
+++ b/services/hogql-language-service/internal/completion/functions.go
@@ -1,9 +1,9 @@
+// Code generated by posthog/hogql/functions/generate_language_service_functions.py; DO NOT EDIT.
+
package completion
import "strings"
-// Keep this list aligned with ALL_EXPOSED_FUNCTION_NAMES in posthog/hogql/functions/mapping.py.
-// Embedding it avoids duplicating global data in each permission-scoped catalog.
var hogQLFunctions = strings.Fields(`
IPv4CIDRToRange IPv4NumToString IPv4StringToNum IPv4StringToNumOrDefault IPv4StringToNumOrNull IPv4ToIPv6 IPv6CIDRToRange IPv6NumToString IPv6StringToNum IPv6StringToNumOrDefault IPv6StringToNumOrNull JSONArrayLength JSONExtract JSONExtractArrayRaw JSONExtractBool JSONExtractFloat JSONExtractInt JSONExtractKeys JSONExtractKeysAndValues JSONExtractKeysAndValuesRaw
JSONExtractRaw JSONExtractString JSONExtractUInt JSONHas JSONLength JSONType JSON_VALUE L1Distance L1Norm L1Normalize L2Distance L2Norm L2Normalize LinfDistance LinfNorm LinfNormalize LpDistance LpNorm LpNormalize MD5