Skip to content

Commit

Permalink
fix: lsp autocomplete and hover items to match current FTL (#3965)
Browse files Browse the repository at this point in the history
Fixes #3963

---------

Co-authored-by: Copilot <[email protected]>
  • Loading branch information
wesbillman and Copilot authored Jan 10, 2025
1 parent b5f43e7 commit 0950eae
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 57 deletions.
28 changes: 14 additions & 14 deletions internal/lsp/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ var cronExpressionCompletionDocs string
//go:embed markdown/completion/retry.md
var retryCompletionDocs string

//go:embed markdown/completion/configDeclare.md
var declareConfigCompletionDocs string
//go:embed markdown/completion/retryWithCatch.md
var retryWithCatchCompletionDocs string

//go:embed markdown/completion/secretDeclare.md
var declareSecretCompletionDocs string
//go:embed markdown/completion/config.md
var configCompletionDocs string

//go:embed markdown/completion/secret.md
var secretCompletionDocs string

//go:embed markdown/completion/pubSubTopic.md
var declarePubSubTopicCompletionDocs string
var pubSubTopicCompletionDocs string

//go:embed markdown/completion/pubSubSubscription.md
var declarePubSubSubscriptionCompletionDocs string

//go:embed markdown/completion/pubSubSink.md
var definePubSubSinkCompletionDocs string
var pubSubSubscriptionCompletionDocs string

// Markdown is split by "---". First half is completion docs, second half is insert text.
var completionItems = []protocol.CompletionItem{
Expand All @@ -59,11 +59,11 @@ var completionItems = []protocol.CompletionItem{
completionItem("ftl:cron", "FTL Cron", cronCompletionDocs),
completionItem("ftl:cron:expression", "FTL Cron with expression", cronExpressionCompletionDocs),
completionItem("ftl:retry", "FTL Retry", retryCompletionDocs),
completionItem("ftl:config:declare", "Declare config", declareConfigCompletionDocs),
completionItem("ftl:secret:declare", "Declare secret", declareSecretCompletionDocs),
completionItem("ftl:pubsub:topic", "Declare PubSub topic", declarePubSubTopicCompletionDocs),
completionItem("ftl:pubsub:subscription", "Declare a PubSub subscription", declarePubSubSubscriptionCompletionDocs),
completionItem("ftl:pubsub:sink", "Define a PubSub sink", definePubSubSinkCompletionDocs),
completionItem("ftl:retry:catch", "FTL Retry with catch", retryWithCatchCompletionDocs),
completionItem("ftl:config", "Create a new configuration value", configCompletionDocs),
completionItem("ftl:secret", "Create a new secret value", secretCompletionDocs),
completionItem("ftl:pubsub:topic", "Create a PubSub topic", pubSubTopicCompletionDocs),
completionItem("ftl:pubsub:subscription", "Create a PubSub subscription", pubSubSubscriptionCompletionDocs),
}

// Track which directives are //ftl: prefixed, so the we can autocomplete them via `/`.
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/hoveritems.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ Declare a config variable.
Configuration values are named, typed values. They are managed by the `ftl config` command-line.

```go
var defaultUser = ftl.Config[string]("defaultUser")
// Will create a config value called "myConfig" in the FTL schema
type MyConfig = ftl.Config[string]
```

See https://block.github.io/ftl/docs/reference/secretsconfig/
---

var ${1:configVar} = ftl.Config[${2:Type}]("${1:configVar}")
type ${1:Name} = ftl.Config[${2:Type}]
2 changes: 1 addition & 1 deletion internal/lsp/markdown/completion/cron.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Declare a cron job.

A cron job is an Empty verb that will be called on a schedule.
A cron job is an Empty verb that will be called on a schedule. Supports both cron expressions and duration format.

```go
//ftl:cron 0 * * * *
Expand Down
5 changes: 4 additions & 1 deletion internal/lsp/markdown/completion/cronExpression.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Declare a cron job, autocompleting on a cron expression.

A cron job is an Empty verb that will be called on a schedule.
A cron job is an Empty verb that will be called on a schedule. Supports both cron expressions and duration format.

```go
//ftl:cron 0 * * * *
func Hourly(ctx context.Context) error {}

//ftl:cron 6h
func EverySixHours(ctx context.Context) error {}

//ftl:cron Mon
func Mondays(ctx context.Context) error {}
```

See https://block.github.io/ftl/docs/reference/cron/
Expand Down
5 changes: 3 additions & 2 deletions internal/lsp/markdown/completion/enumType.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Declare a type enum (sum types).
Declare a type enum (sum type).

A type enum is a set of types that can be used as a single type, which `go` does not directly support.
Type enums allow you to define a set of related types that implement a common interface. This provides sum type functionality that Go doesn't natively support.

```go
//ftl:enum
Expand All @@ -20,4 +20,5 @@ See https://block.github.io/ftl/docs/reference/types/
type ${1:Type} interface { ${2:interface}() }

type ${3:Value} struct {}

func (${3:Value}) ${2:interface}() {}
8 changes: 4 additions & 4 deletions internal/lsp/markdown/completion/enumValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ A value enum is an enumerated set of string or integer values.

```go
//ftl:enum
type Colour string
type Color string

const (
Red Colour = "red"
Green Colour = "green"
Blue Colour = "blue"
Red Color = "red"
Green Color = "green"
Blue Color = "blue"
)
```

Expand Down
4 changes: 2 additions & 2 deletions internal/lsp/markdown/completion/ingress.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Declare an ingress function.

Verbs annotated with `ftl:ingress` will be exposed via HTTP (http is the default ingress type). These endpoints will then be available on one of our default ingress ports (local development defaults to http://localhost:8891).
Verbs annotated with `ftl:ingress` will be exposed via HTTP. These endpoints will be available on default ingress ports (local development defaults to http://localhost:8891).

```go
type GetPathParams struct {
Expand Down Expand Up @@ -34,7 +34,7 @@ type ${1:Func}Response struct {
}

//ftl:ingress ${2:GET} ${3:/url/path}
func ${1:Func}(ctx context.Context, req builtin.HttpRequest[ftl.Unit, flt.Unit, ${1:Func}Request]) (builtin.HttpResponse[${1:Func}Response, string], error) {
func ${1:Func}(ctx context.Context, req builtin.HttpRequest[ftl.Unit, ftl.Unit, ${1:Func}Request]) (builtin.HttpResponse[${1:Func}Response, string], error) {
${4:// TODO: Implement}
return builtin.HttpResponse[${1:Func}Response, string]{
Status: 200,
Expand Down
17 changes: 0 additions & 17 deletions internal/lsp/markdown/completion/pubSubSink.md

This file was deleted.

15 changes: 13 additions & 2 deletions internal/lsp/markdown/completion/pubSubSubscription.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
Declare a subscription to a topic.

A subscription consumes events from a topic, starting either from the beginning of the topic or only new events.

```go
var _ = ftl.Subscription(invoicesTopic, "emailInvoices")
//ftl:subscribe payments.invoices from=beginning
func SendInvoiceEmail(ctx context.Context, in Invoice) error {
// Process the invoice event
return nil
}
```

See https://block.github.io/ftl/docs/reference/pubsub/
---

var _ = ftl.Subscription(${1:topicVar}, "${2:subscriptionName}")
//ftl:subscribe ${1:topicName} from=${2:beginning}
func ${3:OnEvent}(ctx context.Context, in ${4:EventType}) error {
${5:// TODO: Implement}
return nil
}

Loading

0 comments on commit 0950eae

Please sign in to comment.