Merge pull request #16 from KristianJBorgwarth/feat/link-completion

feat(completion/link): completion stub
This commit is contained in:
Kristian 2026-04-10 23:59:37 +02:00 committed by GitHub
commit f2fc6ee0ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 61 additions and 0 deletions

View file

@ -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)

View file

@ -0,0 +1,35 @@
package completion
import (
"context"
"encoding/json"
"log/slog"
)
type completeLinkCommand struct {
Query string `json:"query"`
}
type completionItem struct {
Slug string `json:"slug"`
}
type CompleteLinkHandler struct{}
func NewCompleteLinkHandler() *CompleteLinkHandler {
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)
return []completionItem{
{Slug: "standard-streams"},
{Slug: "unit-of-work"},
{Slug: "treesitter-basics"},
}, nil
}

View file

@ -0,0 +1,2 @@
// Package completion provides handlers for completion commands
package completion

BIN
dendrite

Binary file not shown.

View file

@ -10,6 +10,7 @@ import (
type ILinkRepository interface {
GetByNoteID(ctx context.Context, fromNoteID string) ([]*models.Link, error)
GetBySlug(ctx context.Context, targetSlug string) ([]*models.Link, error)
Search(ctx context.Context, query string) ([]*models.Link, error)
}
type linkRepository struct {
@ -59,3 +60,23 @@ func (r *linkRepository) GetBySlug(ctx context.Context, targetSlug string) ([]*m
return links, nil
}
func (r *linkRepository) Search(ctx context.Context, query string) ([]*models.Link, error) {
rows, err := r.Transaction.QueryContext(ctx, `SELECT id, from_note_id, target_slug, raw, display, line, col FROM links WHERE raw LIKE ?`, "%"+query+"%")
if err != nil {
return nil, err
}
defer rows.Close()
var links []*models.Link
for rows.Next() {
var id, fromNoteID, targetSlug, raw, display string
var line, col int
if err := rows.Scan(&id, &fromNoteID, &targetSlug, &raw, &display, &line, &col); err != nil {
return nil, err
}
links = append(links, models.NewLink(id, fromNoteID, targetSlug, raw, display, line, col))
}
return links, nil
}