feat(link-completion): completion stub
This commit is contained in:
parent
af4b8a4ad5
commit
6975ae59ba
3 changed files with 16 additions and 25 deletions
|
|
@ -3,6 +3,8 @@ package main
|
|||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/completion"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/note"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/vault"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/logging"
|
||||
|
|
@ -16,6 +18,7 @@ func main() {
|
|||
|
||||
server.RegisterHandler("initialize", vault.NewInitializeHandler())
|
||||
server.RegisterHandler("create_note", note.NewCreateNoteHandler())
|
||||
server.RegisterHandler("completion/link", completion.NewCompleteLinkHandler())
|
||||
|
||||
if err := server.Run(os.Stdin, os.Stdout); err != nil {
|
||||
slog.Error("server error", "error", err)
|
||||
|
|
|
|||
|
|
@ -3,45 +3,33 @@ package completion
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/models"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/utils"
|
||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
type completeLinkCommand struct {
|
||||
LinkQuery string `json:"linkQuery"`
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
type CompleteLinkHandler struct{
|
||||
uow *repositories.UnitOfWork
|
||||
type completionItem struct {
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
|
||||
type CompleteLinkHandler struct{}
|
||||
|
||||
func NewCompleteLinkHandler() *CompleteLinkHandler {
|
||||
return &CompleteLinkHandler{repositories.NewUnitOfWork()}
|
||||
return &CompleteLinkHandler{}
|
||||
}
|
||||
|
||||
func (h *CompleteLinkHandler) Handle(ctx context.Context, raw json.RawMessage) (any, error) {
|
||||
var cmd completeLinkCommand
|
||||
|
||||
if err := json.Unmarshal(raw, &cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
slog.Debug("handling complete link command", "query", cmd.Query)
|
||||
|
||||
tx, err := h.uow.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer h.uow.Rollback()
|
||||
linkRepo := repositories.NewLinkRepository(tx)
|
||||
|
||||
links, err := linkRepo.Search(ctx, cmd.LinkQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
slugs := utils.Select(links, func(l *models.Link) string {return l.TargetSlug()});
|
||||
|
||||
return slugs, nil
|
||||
return []completionItem{
|
||||
{Slug: "standard-streams"},
|
||||
{Slug: "unit-of-work"},
|
||||
{Slug: "treesitter-basics"},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
BIN
dendrite
BIN
dendrite
Binary file not shown.
Loading…
Add table
Reference in a new issue