diff --git a/MAINTAINERS.md b/MAINTAINERS.md index 48a6f17..fb33125 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -4,10 +4,10 @@ This is a monorepo with two Go modules: -| Directory | Go module | Description | -|-----------|-----------|-------------| -| `function/` | `github.com/crossplane-contrib/function-hcl/function` | Crossplane composition function | -| `language-server/` | `github.com/crossplane-contrib/function-hcl/language-server` | LSP language server | +| Directory | Go module | Description | +|--------------------|--------------------------------------------------------------|---------------------------------| +| `function/` | `github.com/crossplane-contrib/function-hcl/function` | Crossplane composition function | +| `language-server/` | `github.com/crossplane-contrib/function-hcl/language-server` | LSP language server | Other top-level directories (`vscode/`, `jetbrains/`, `docs-site/`, `Formula/`) are not Go modules and are released as part of the same workflow. @@ -102,15 +102,15 @@ git push origin main v0.3.0-rc1 function/v0.3.0-rc1 language-server/v0.3.0-rc1 - ## Required repository secrets -| Secret | Used by | -|--------|---------| -| `XPKG_ACCESS_ID` | Push Crossplane package to xpkg.upbound.io | -| `XPKG_TOKEN` | Push Crossplane package to xpkg.upbound.io | -| `VSCE_PAT` | Publish VS Code extension | -| `JETBRAINS_PUBLISH_TOKEN` | Publish JetBrains plugin | -| `JETBRAINS_CERTIFICATE_CHAIN` | Sign JetBrains plugin | -| `JETBRAINS_PRIVATE_KEY` | Sign JetBrains plugin | -| `JETBRAINS_PRIVATE_KEY_PASSWORD` | Sign JetBrains plugin | +| Secret | Used by | +|----------------------------------|--------------------------------------------| +| `XPKG_ACCESS_ID` | Push Crossplane package to xpkg.upbound.io | +| `XPKG_TOKEN` | Push Crossplane package to xpkg.upbound.io | +| `VSCE_PAT` | Publish VS Code extension | +| `JETBRAINS_PUBLISH_TOKEN` | Publish JetBrains plugin | +| `JETBRAINS_CERTIFICATE_CHAIN` | Sign JetBrains plugin | +| `JETBRAINS_PRIVATE_KEY` | Sign JetBrains plugin | +| `JETBRAINS_PRIVATE_KEY_PASSWORD` | Sign JetBrains plugin | ## Go module tagging diff --git a/README.md b/README.md index c2fea40..8e00899 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,16 @@ A crossplane function that uses an opinionated DSL built on [HCL](https://github.com/hashicorp/hcl) to model desired resources. It has more than a passing familiarity with Terraform syntax. +This is a monorepo that contains +the [function implementation](function/), +[language server](language-server/), +[VS code extension](vscode/), +[Jetbrains extension](jetbrains/), +[documentation content](docs-site/), +and [homebrew formula](Formula/). + +Detailed documentation [can be found here](https://crossplane-contrib.github.io/function-hcl/). + ![CI](https://github.com/crossplane-contrib/function-hcl/actions/workflows/ci.yaml/badge.svg?branch=main) [![Go Report Card](https://goreportcard.com/badge/github.com/crossplane-contrib/function-hcl)](https://goreportcard.com/report/github.com/crossplane-contrib/function-hcl) [![function-hcl coverage](https://github.com/crossplane-contrib/function-hcl/wiki/coverage.svg)](https://raw.githack.com/wiki/crossplane-contrib/function-hcl/coverage.html) @@ -90,7 +100,7 @@ In addition, it emits an event for every such discarded resource telling you exa and maintains a status condition explicitly for this purpose. This allows you to fix any typos that prevent resources from being rendered as opposed to unknown dependency state. -Start with the [examples](example/README.md), then read the [spec](spec.md). +Start with the [examples](example/README.md), then [read the docs](https://crossplane-contrib.github.io/function-hcl/). There is also tooling in [fn-hcl-tools](cmd/fn-hcl-tools) that can package multiple HCL files into txtar format after static analysis. It also provides a formatter for canonical formatting of HCL files. diff --git a/docs-site/content/en/docs/getting-started/crd-setup.md b/docs-site/content/en/docs/getting-started/crd-setup.md new file mode 100644 index 0000000..b87f396 --- /dev/null +++ b/docs-site/content/en/docs/getting-started/crd-setup.md @@ -0,0 +1,170 @@ +--- +title: "Set up CRDs" +linkTitle: "CRD setup" +weight: 4 +description: > + Create local CRD definitions for language server use. +--- + +The language server provides completion for language constructs by default. +To enable completions for XRD and CRD fields, you need to supply two pieces of information: + +1. **The composite type** — tells the language server which XRD this composition targets, enabling + completions for the `req.composite` variable. +2. **CRD definitions** — tells the language server what resource types exist, enabling completions + for `apiVersion`, `kind`, and resource-specific fields. + +## Declaring the composite type + +Create a `composition.yaml` file in the same directory as your `.hcl` files. +This file tells the language server which XRD your composition targets: + +```yaml +xrd: + apiVersion: example.com/v1 + kind: XExample +``` + +The language server reads this file when you open any `.hcl` file in the directory. +It uses the `apiVersion` and `kind` to look up the matching XRD schema from the CRD definitions you have +configured (see below), and uses that schema to provide completions for the built-in `composite` variable. + +If `composition.yaml` is absent, or if either field is empty, the language server still works but cannot +provide composite-specific field completions. + +## Setting up CRD definitions + +You use the `fn-hcl-tools extract-crds` command to extract CRD definitions from your YAML files and OCI images, +then place those definitions where the language server can find them. + +## How the language server discovers CRDs + +When you open an HCL file, the language server walks up the directory tree from the file's location +looking for one of two things (in this order): + +1. A file named `.crd-sources.yaml` — an explicit configuration listing which YAML files to load. +2. A directory named `.crds/` — the default drop location for extracted CRD files. + +Once found, it loads matching YAML files in the background and starts providing completions for the +resource types it finds. It watches for file changes and reloads automatically. + +## Extracting CRDs + +`fn-hcl-tools extract-crds` reads YAML files and pulls out CRD and XRD definitions. It can also +follow `Provider` and `Configuration` object references and pull CRDs from the referenced OCI images. + +**Install `fn-hcl-tools`** if you have not already — see [Installation](../installation#install-fn-hcl-tools). + +### From local YAML files + +Point the command at any YAML files that contain CRDs, XRDs, Providers, or Configurations: + +```bash +fn-hcl-tools extract-crds --output-dir .crds providers.yaml crossplane.yaml +``` + +The tool writes one YAML file per processed image into `.crds/`. Objects from local files +are grouped under a file named `local-objects.yaml`. + +### From stdin (filter mode) + +When called with no arguments, the command acts as a filter: reads YAML from stdin and writes to stdout. +Use `-` to explicitly request stdin while also passing file arguments: + +```bash +cat providers.yaml | fn-hcl-tools extract-crds --output-dir .crds - +fn-hcl-tools extract-crds --output-dir .crds - extra.yaml < providers.yaml +``` + +Note: the tool processes individual YAML documents, not Kubernetes `List` objects. +If your source produces a `List`, extract the individual items first before piping. + +### From a Helm chart + +`helm template` renders chart manifests as individual YAML documents, which the extractor handles +directly. This is useful for pulling CRDs out of provider charts: + +```bash +helm template --include-crds my-release oci://registry-1.docker.io/bitnamicharts/crossplane \ + | fn-hcl-tools extract-crds --output-dir .crds - +``` + +```bash +helm template my-release ./my-provider-chart --include-crds \ + | fn-hcl-tools extract-crds --output-dir .crds - +``` + +## Simple setup: the `.crds/` directory + +The simplest configuration is to create a `.crds/` directory in (or above) your compositions directory +and run `extract-crds` into it. No further configuration is needed. + +``` +my-compositions/ + .crds/ + local-objects.yaml # extracted from local YAML files + xpkg-upbound-io-...yaml # extracted from a Provider image + compositions/ + composition1/ + composition.yaml + main.hcl +``` + +The language server loads all `*.yaml` files from `.crds/` and makes all resource types +(both cluster-scoped and namespace-scoped) available for completion. + +## Advanced setup: `.crd-sources.yaml` + +Create a `.crd-sources.yaml` file when you need more control — for example, to load files from +a different location or to limit completions to a specific resource scope. + +```yaml +scope: both # "namespaced", "cluster", or "both" (default: "both") +paths: + - .crds/*.yaml # paths are relative to this file's directory + - /absolute/path/to/more/crds/**/*.yaml +``` + +| Field | Values | Default | Description | +|---------|-------------------------------------|----------|-------------------------------------------------------| +| `scope` | `namespaced`, `cluster`, `both` | `both` | Which resource scopes to include in completions. | +| `paths` | list of file paths or glob patterns | required | Files to load; relative paths resolve from this file. | + +The `paths` field supports `**` double-star globs for recursive matching. + +### Example: separate CRD directories per scope + +```yaml +scope: cluster +paths: + - cluster-crds/*.yaml + - /shared/xrds/*.yaml +``` + +## Placement + +Put `.crds/` or `.crd-sources.yaml` in the root of your compositions repository so that all +composition files in subdirectories share a single CRD configuration. + +``` +repo-root/ + .crds/ # or .crd-sources.yaml here + providers.yaml + xrds.yaml + compositions/ + postgres/ + composition.hcl # language server finds .crds/ by walking up + redis/ + composition.hcl # same +``` + +## Keeping CRDs up to date + +Re-run `extract-crds` whenever you add a new Provider, Configuration, or XRD to your setup. +The language server detects file changes and reloads without requiring a restart. + +```bash +fn-hcl-tools extract-crds --output-dir .crds crossplane.yaml +``` + +Use `--progress=false` and `--warnings=false` to suppress diagnostic output in scripts. diff --git a/docs-site/content/en/docs/getting-started/ide-setup.md b/docs-site/content/en/docs/getting-started/ide-setup.md index d84a6f7..d9b830c 100644 --- a/docs-site/content/en/docs/getting-started/ide-setup.md +++ b/docs-site/content/en/docs/getting-started/ide-setup.md @@ -19,6 +19,20 @@ The language server provides: - Document symbols - Semantic token highlighting -## Installation instructions +## Installation -Coming soon. Watch this space... +### Visual Studio Code + +Install the [Crossplane Function HCL](https://marketplace.visualstudio.com/items?itemName=function-hcl-authors.function-hcl) extension shown below. + +{{< figure src="../vscode-extension.png" >}} + +### Jetbrains products + +Install the [function-hcl plugin](https://plugins.jetbrains.com/plugin/30965-function-hcl) as shown below. + +{{< figure src="../jetbrains-plugin.png" >}} + +### Post-install + +Follow the instructions [on this page](../crd-setup) to register types with the language server. diff --git a/docs-site/content/en/docs/getting-started/installation.md b/docs-site/content/en/docs/getting-started/installation.md index eaf4a40..21944b4 100644 --- a/docs-site/content/en/docs/getting-started/installation.md +++ b/docs-site/content/en/docs/getting-started/installation.md @@ -43,12 +43,37 @@ You should see `HEALTHY: True` and `INSTALLED: True` in the output. ## Install fn-hcl-tools `fn-hcl-tools` is the companion CLI for packaging, formatting, and analyzing your HCL files. -Install it with `go install`: + +### Prebuilt release + +Install it by downloading the [appropriate file for your OS for the latest release](https://github.com/crossplane-contrib/function-hcl/releases) + +### Homebrew + +For MacOS, you can also use homebrew to install it. + +```bash +# since the formula comes from the same monorepo, you need to run the `tap` subcommand as follows +brew tap crossplane-contrib/function-hcl https://github.com/crossplane-contrib/function-hcl +brew trust crossplane-contrib/function-hcl +brew install fn-hcl-tools +``` + +To upgrade the version: + +```bash +brew update +brew upgrade fn-hcl-tools +``` + +### Install from source ```bash go install github.com/crossplane-contrib/function-hcl/function/cmd/fn-hcl-tools@{{< version >}} ``` +Note that the version printed by `fn-hcl-tools version` will be incorrect using this method. + Verify it works: ```bash diff --git a/docs-site/content/en/docs/getting-started/jetbrains-plugin.png b/docs-site/content/en/docs/getting-started/jetbrains-plugin.png new file mode 100644 index 0000000..dd9543a Binary files /dev/null and b/docs-site/content/en/docs/getting-started/jetbrains-plugin.png differ diff --git a/docs-site/content/en/docs/getting-started/vscode-extension.png b/docs-site/content/en/docs/getting-started/vscode-extension.png new file mode 100644 index 0000000..5ffcba1 Binary files /dev/null and b/docs-site/content/en/docs/getting-started/vscode-extension.png differ diff --git a/docs-site/content/en/docs/language-guide/hcl-basics.md b/docs-site/content/en/docs/language-guide/hcl-basics.md index 082fe17..4ba4ff8 100644 --- a/docs-site/content/en/docs/language-guide/hcl-basics.md +++ b/docs-site/content/en/docs/language-guide/hcl-basics.md @@ -36,13 +36,6 @@ resource my-bucket { body = { /* ... */ } } -# Block with two labels -resource my-bucket { - # 'composite' is the block type, 'status' is a label - composite status { - body = { /* ... */ } - } -} ``` Unlike attributes, some block types **can** appear multiple times in the same scope. For example, @@ -85,6 +78,7 @@ body = { {{% alert title="Note" color="info" %}} HCL also allows `:` as a delimiter inside object literals (e.g. `kind: "Bucket"`). Both `=` and `:` are valid, but this documentation uses `=` consistently for clarity. +The formatter also normalizes colons and replaces them with equal signs. {{% /alert %}} An attribute can only be set **once** in a given scope. Setting the same attribute name twice @@ -201,12 +195,10 @@ Some commonly used ones: ```hcl locals { - merged = merge(defaults, overrides) - safe = try(obj.field, "fallback") - ok = can(obj.field) - items = join(",", list) - encoded = base64encode(secret) - count = length(names) + merged = merge(defaults, overrides) # merge overrides + safe = try(obj.field, "fallback") # handle optional fields + ok = can(obj.field) # check if an optional field is present + encoded = base64encode(secret) # encode a secret value for Crossplane use } ``` diff --git a/docs-site/content/en/docs/language-guide/local-variables.md b/docs-site/content/en/docs/language-guide/local-variables.md index 11330ef..a85eb89 100644 --- a/docs-site/content/en/docs/language-guide/local-variables.md +++ b/docs-site/content/en/docs/language-guide/local-variables.md @@ -25,7 +25,7 @@ All `locals` blocks in a given scope are processed together and variable orderin Dependencies are resolved automatically. This is the same behavior as Terraform. ```hcl -# These two blocks are treated identically: +# These two blocks are treated exactly the same as the single block in the previous section locals { computedName = "${baseName}-bucket" } diff --git a/docs-site/content/en/docs/language-guide/source-format.md b/docs-site/content/en/docs/language-guide/source-format.md index 9b5ecb1..0153023 100644 --- a/docs-site/content/en/docs/language-guide/source-format.md +++ b/docs-site/content/en/docs/language-guide/source-format.md @@ -76,7 +76,7 @@ You should always use the `fn-hcl-tools package` command to produce the txtar sc HCL source files -- even for a single file. Do not hand-craft txtar bundles. ```bash -fn-hcl-tools package ./my-composition/*.hcl +fn-hcl-tools package ./my-composition/ ``` Before producing the txtar output, `fn-hcl-tools package` **analyzes** every HCL file and will diff --git a/docs-site/content/en/docs/reference/dsl-specification.md b/docs-site/content/en/docs/reference/dsl-specification.md index a3fb2c1..675cef5 100644 --- a/docs-site/content/en/docs/reference/dsl-specification.md +++ b/docs-site/content/en/docs/reference/dsl-specification.md @@ -7,7 +7,7 @@ description: > --- {{% alert title="Source of truth" color="info" %}} -This page is derived from [`spec.md`](https://github.com/crossplane-contrib/function-hcl/blob/main/spec.md) +This page is derived from [`spec.md`](https://github.com/crossplane-contrib/function-hcl/blob/main/function/spec.md) in the repository. If you find a discrepancy, the repository version is authoritative. {{% /alert %}} @@ -20,16 +20,16 @@ via the `input` field of the Composition pipeline step. All files are treated as Created automatically from the `RunFunctionRequest`. Accessed as `req.`. -| Variable | Type | Description | -|----------|------|-------------| -| `req.composite` | object | Observed composite resource (XR) | -| `req.composite_connection` | map(string, bytes) | Observed connection details of the composite | -| `req.resource` | map(string, object) | Observed resource bodies, keyed by crossplane name | -| `req.connection` | map(string, map(string, bytes)) | Observed connection details, keyed by resource name | -| `req.resources` | map(string, list(object)) | Observed resource collections, keyed by base name | -| `req.connections` | map(string, list(map(string, bytes))) | Connection details of collections | -| `req.context` | map(string, any) | Pipeline context | -| `req.extra_resources` | map(string, list(object)) | Extra resources from `requirement` blocks | +| Variable | Type | Description | +|----------------------------|---------------------------------------|-----------------------------------------------------| +| `req.composite` | object | Observed composite resource (XR) | +| `req.composite_connection` | map(string, bytes) | Observed connection details of the composite | +| `req.resource` | map(string, object) | Observed resource bodies, keyed by crossplane name | +| `req.connection` | map(string, map(string, bytes)) | Observed connection details, keyed by resource name | +| `req.resources` | map(string, list(object)) | Observed resource collections, keyed by base name | +| `req.connections` | map(string, list(map(string, bytes))) | Connection details of collections | +| `req.context` | map(string, any) | Pipeline context | +| `req.extra_resources` | map(string, list(object)) | Extra resources from `requirement` blocks | ## Top-Level Blocks diff --git a/docs-site/content/en/docs/reference/fn-hcl-tools.md b/docs-site/content/en/docs/reference/fn-hcl-tools.md index 4487f7a..0cfb230 100644 --- a/docs-site/content/en/docs/reference/fn-hcl-tools.md +++ b/docs-site/content/en/docs/reference/fn-hcl-tools.md @@ -11,9 +11,8 @@ HCL compositions. ## Installation -```bash -go install github.com/crossplane-contrib/function-hcl/function/cmd/fn-hcl-tools@{{< version >}} -``` +see [Installation](../../getting-started/installation#install-fn-hcl-tools). + ## Commands @@ -23,7 +22,7 @@ Packages a directory of HCL files into a single txtar bundle, suitable for embed `input` field. ```bash -fn-hcl-tools package *.hcl +fn-hcl-tools package . ``` The tool runs basic static analysis on the HCL before packing, catching syntax errors early. @@ -42,7 +41,7 @@ my-composition/ Run: ```bash -fn-hcl-tools package my-composition/*.hcl +fn-hcl-tools package my-composition/ ``` Output (suitable for pasting into a Composition YAML `input` field): @@ -78,7 +77,7 @@ if the supplied files are not correctly formatted. Analyzes HCL syntax files and reports diagnostics. ```bash -fn-hcl-tools analyze *.hcl +fn-hcl-tools analyze . ``` ### `version` @@ -102,5 +101,5 @@ A typical development workflow: ```bash # Package and copy to clipboard (macOS) -fn-hcl-tools package ./my-composition/*.hcl | pbcopy +fn-hcl-tools package ./my-composition/ | pbcopy ``` diff --git a/docs-site/content/en/docs/tips-and-pitfalls/best-practices.md b/docs-site/content/en/docs/tips-and-pitfalls/best-practices.md index 498dbbb..026247c 100644 --- a/docs-site/content/en/docs/tips-and-pitfalls/best-practices.md +++ b/docs-site/content/en/docs/tips-and-pitfalls/best-practices.md @@ -6,7 +6,7 @@ description: > Conventions and patterns for writing clean, maintainable function-hcl compositions. --- -## Always use fn-hcl-tools package +## Always use fn-hcl-tools to package composition scripts Run `fn-hcl-tools package` to produce your txtar script rather than hand-crafting it. This validates your HCL before it reaches the cluster, catching typos in variable names, bad block @@ -63,6 +63,11 @@ group { } ``` +{{% alert title="Tip" color="info" %}} +It's a good idea to have a single file (say, `init.hcl`) that contains locals you want to use everywhere. +Wrap the contents of other files in a `group` so that all locals defined in that file are scoped to the file. +{{% /alert %}} + ## Put composite status inside resource blocks Write `composite status` inside the `resource` block where the data originates, not at the diff --git a/docs-site/content/en/docs/tips-and-pitfalls/gotchas.md b/docs-site/content/en/docs/tips-and-pitfalls/gotchas.md index 0e26ee0..565054a 100644 --- a/docs-site/content/en/docs/tips-and-pitfalls/gotchas.md +++ b/docs-site/content/en/docs/tips-and-pitfalls/gotchas.md @@ -109,12 +109,6 @@ locals { } ``` -## resource vs resources -- singular matters - -`resource` (singular) creates one resource. `resources` (plural) creates a collection with -`for_each`. Using the wrong one is a schema error. The observed state variables follow the -same pattern: `req.resource` (singular) vs `req.resources` (plural). - ## User functions cannot access req, self, or each Functions are pure -- they only have access to their declared arguments and their own locals. diff --git a/function/README.md b/function/README.md new file mode 100644 index 0000000..b49cd21 --- /dev/null +++ b/function/README.md @@ -0,0 +1,4 @@ +function +--- + +This directory is the root of the Go module containing the function implementation. diff --git a/jetbrains/README.md b/jetbrains/README.md index 9e0e57b..5cab48f 100644 --- a/jetbrains/README.md +++ b/jetbrains/README.md @@ -27,7 +27,3 @@ Features: Download the [latest release](https://github.com/crossplane-contrib/function-hcl/releases/latest) and install it manually using Settings/Preferences > Plugins > ⚙️ > Install plugin from disk... - -## Development - -See [HACKING.md](HACKING.md) for build instructions and project layout. diff --git a/language-server/go.mod b/language-server/go.mod index 8a72e19..14b0c63 100644 --- a/language-server/go.mod +++ b/language-server/go.mod @@ -13,7 +13,6 @@ require ( github.com/google/go-cmp v0.7.0 github.com/google/go-containerregistry v0.20.7 github.com/hashicorp/go-uuid v1.0.3 - github.com/hashicorp/go-version v1.7.0 github.com/hashicorp/hcl/v2 v2.24.1-0.20260327001625-d4195a120f30 github.com/pkg/errors v0.9.1 github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 diff --git a/language-server/go.sum b/language-server/go.sum index 2f2ac64..6ab44f5 100644 --- a/language-server/go.sum +++ b/language-server/go.sum @@ -121,8 +121,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= -github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/hcl/v2 v2.24.1-0.20260327001625-d4195a120f30 h1:IQMtUW+S2J6QFXpd+hMrMJmGMElL1/2VrixOkjCmmkk= github.com/hashicorp/hcl/v2 v2.24.1-0.20260327001625-d4195a120f30/go.mod h1:WS1ymNdBhhwYKDVlGnUb9fmqB2hw1djJva6S8Bj/WfI= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/language-server/internal/langserver/handlers/crd_notification.go b/language-server/internal/langserver/handlers/crd_notification.go index c644530..dec59a7 100644 --- a/language-server/internal/langserver/handlers/crd_notification.go +++ b/language-server/internal/langserver/handlers/crd_notification.go @@ -8,7 +8,7 @@ import ( lsp "github.com/crossplane-contrib/function-hcl/language-server/internal/langserver/protocol" ) -const crdSetupURL = "https://github.com/crossplane-contrib/function-hcl/language-server/blob/main/README.md" +const crdSetupURL = "https://crossplane-contrib.github.io/function-hcl/docs/getting-started/crd-setup/" func (svc *service) startCRDNotificationHandler(ctx context.Context) { events := svc.eventBus.SubscribeToNoCRDSourcesEvents("handlers.crd_notification") diff --git a/language-server/main.go b/language-server/main.go index fa2a763..329d102 100644 --- a/language-server/main.go +++ b/language-server/main.go @@ -6,39 +6,19 @@ package main import ( _ "embed" "log" - "strings" "github.com/crossplane-contrib/function-hcl/language-server/internal/cmd" - goversion "github.com/hashicorp/go-version" "github.com/spf13/cobra" ) -var ( - // The next version number that will be released. This will be updated after every release - // Version must conform to the format expected by github.com/hashicorp/go-version - // for tests to work. - // A pre-release marker for the version can also be specified (e.g -dev). If this is omitted - // then it means that it is a final release. Otherwise, this is a pre-release - // such as "dev" (in development), "beta", "rc1", etc. - //go:embed version/VERSION - rawVersion string - - version = goversion.Must(goversion.NewVersion(strings.TrimSpace(rawVersion))) -) - -// VersionString returns the complete version string, including prerelease -func VersionString() string { - return version.String() -} - func main() { root := &cobra.Command{ Use: "function-hcl-ls", Short: "Language server for function-hcl", } - cmd.Version = VersionString() + cmd.Version = getBuildInfo().Version + AddVersionCommand(root) cmd.AddServeCommand(root) - cmd.AddVersionCommand(root) cmd.AddDumpASTCommand(root) if err := root.Execute(); err != nil { diff --git a/language-server/internal/cmd/version.go b/language-server/version.go similarity index 60% rename from language-server/internal/cmd/version.go rename to language-server/version.go index 884c6f8..9b90417 100644 --- a/language-server/internal/cmd/version.go +++ b/language-server/version.go @@ -1,52 +1,48 @@ -package cmd +package main import ( "encoding/json" "fmt" + "runtime" "runtime/debug" "github.com/pkg/errors" "github.com/spf13/cobra" ) -type versionOutput struct { - Version string `json:"version"` - buildInfo -} +var Version = "" type buildInfo struct { + Version string `json:"version,omitempty"` GoVersion string `json:"go,omitempty"` GoOS string `json:"os,omitempty"` GoArch string `json:"arch,omitempty"` - Compiler string `json:"compiler,omitempty"` } -func showVersion(jsonOutput bool) error { - info, ok := debug.ReadBuildInfo() - output := versionOutput{ - Version: Version, - buildInfo: buildInfo{ - GoVersion: "unknown", - GoOS: "unknown", - GoArch: "unknown", - Compiler: "unknown", - }, +func getBuildInfo() buildInfo { + output := buildInfo{ + Version: "dev", + GoVersion: "unknown", + GoOS: runtime.GOOS, + GoArch: runtime.GOARCH, } + + info, ok := debug.ReadBuildInfo() if ok { - output.GoVersion = info.GoVersion - for _, setting := range info.Settings { - // Filter for VCS-related info - switch setting.Key { - case "GOOS": - output.GoOS = setting.Value - case "GOARCH": - output.GoArch = setting.Value - case "compiler": - output.Compiler = setting.Value + if Version == "" { + if info.Main.Version != "" && info.Main.Version != "(devel)" { + output.Version = info.Main.Version } + } else { + output.Version = Version } + output.GoVersion = info.GoVersion } + return output +} +func showVersion(jsonOutput bool) error { + output := getBuildInfo() if jsonOutput { out, err := json.MarshalIndent(output, "", " ") if err != nil { @@ -56,8 +52,8 @@ func showVersion(jsonOutput bool) error { return nil } - fmt.Printf("%s\nplatform: %s/%s\ngo: %s\ncompiler: %s\n", - Version, output.GoOS, output.GoArch, output.GoVersion, output.Compiler) + fmt.Printf("%s\nplatform: %s/%s\ngo: %s\n", + output.Version, output.GoOS, output.GoArch, output.GoVersion) return nil } diff --git a/language-server/version/VERSION b/language-server/version/VERSION deleted file mode 100644 index 8acdd82..0000000 --- a/language-server/version/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.0.1 diff --git a/vscode/README.md b/vscode/README.md index cdbd86b..b4354e0 100644 --- a/vscode/README.md +++ b/vscode/README.md @@ -6,5 +6,3 @@ A VSCode extension that provides function-hcl support via its language server. Portions of this extension are derived from the [Terraform VS Code extension](https://github.com/hashicorp/vscode-terraform), Copyright (c) HashiCorp, Inc., and are used under the terms of the Mozilla Public License 2.0 (MPL-2.0). See [LICENSE-MPL-2.0.txt](LICENSE-MPL-2.0.txt) for the full license text and [NOTICE](NOTICE) for details on which files are covered. - -See [HACKING.md](HACKING.md) for development, building, and publishing instructions.