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 (
|
import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/completion"
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/note"
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/note"
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/vault"
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/handlers/vault"
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/logging"
|
"github.com/KristianJBorgwarth/dendrite.daemon/core/logging"
|
||||||
|
|
@ -16,6 +18,7 @@ func main() {
|
||||||
|
|
||||||
server.RegisterHandler("initialize", vault.NewInitializeHandler())
|
server.RegisterHandler("initialize", vault.NewInitializeHandler())
|
||||||
server.RegisterHandler("create_note", note.NewCreateNoteHandler())
|
server.RegisterHandler("create_note", note.NewCreateNoteHandler())
|
||||||
|
server.RegisterHandler("completion/link", completion.NewCompleteLinkHandler())
|
||||||
|
|
||||||
if err := server.Run(os.Stdin, os.Stdout); err != nil {
|
if err := server.Run(os.Stdin, os.Stdout); err != nil {
|
||||||
slog.Error("server error", "error", err)
|
slog.Error("server error", "error", err)
|
||||||
|
|
|
||||||
|
|
@ -3,45 +3,33 @@ package completion
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log/slog"
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/models"
|
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/core/utils"
|
|
||||||
"github.com/KristianJBorgwarth/dendrite.daemon/persistence/repositories"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type completeLinkCommand struct {
|
type completeLinkCommand struct {
|
||||||
LinkQuery string `json:"linkQuery"`
|
Query string `json:"query"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CompleteLinkHandler struct{
|
type completionItem struct {
|
||||||
uow *repositories.UnitOfWork
|
Slug string `json:"slug"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CompleteLinkHandler struct{}
|
||||||
|
|
||||||
func NewCompleteLinkHandler() *CompleteLinkHandler {
|
func NewCompleteLinkHandler() *CompleteLinkHandler {
|
||||||
return &CompleteLinkHandler{repositories.NewUnitOfWork()}
|
return &CompleteLinkHandler{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *CompleteLinkHandler) Handle(ctx context.Context, raw json.RawMessage) (any, error) {
|
func (h *CompleteLinkHandler) Handle(ctx context.Context, raw json.RawMessage) (any, error) {
|
||||||
var cmd completeLinkCommand
|
var cmd completeLinkCommand
|
||||||
|
|
||||||
if err := json.Unmarshal(raw, &cmd); err != nil {
|
if err := json.Unmarshal(raw, &cmd); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
slog.Debug("handling complete link command", "query", cmd.Query)
|
||||||
|
|
||||||
tx, err := h.uow.Begin()
|
return []completionItem{
|
||||||
if err != nil {
|
{Slug: "standard-streams"},
|
||||||
return nil, err
|
{Slug: "unit-of-work"},
|
||||||
}
|
{Slug: "treesitter-basics"},
|
||||||
|
}, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
BIN
dendrite
BIN
dendrite
Binary file not shown.
Loading…
Add table
Reference in a new issue