Merge pull request #16 from KristianJBorgwarth/feat/link-completion
feat(completion/link): completion stub
This commit is contained in:
commit
f2fc6ee0ee
5 changed files with 61 additions and 0 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)
|
||||||
|
|
|
||||||
35
core/handlers/completion/complete_link_handler.go
Normal file
35
core/handlers/completion/complete_link_handler.go
Normal 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
|
||||||
|
}
|
||||||
2
core/handlers/completion/doc.go
Normal file
2
core/handlers/completion/doc.go
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Package completion provides handlers for completion commands
|
||||||
|
package completion
|
||||||
BIN
dendrite
BIN
dendrite
Binary file not shown.
|
|
@ -10,6 +10,7 @@ import (
|
||||||
type ILinkRepository interface {
|
type ILinkRepository interface {
|
||||||
GetByNoteID(ctx context.Context, fromNoteID string) ([]*models.Link, error)
|
GetByNoteID(ctx context.Context, fromNoteID string) ([]*models.Link, error)
|
||||||
GetBySlug(ctx context.Context, targetSlug 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 {
|
type linkRepository struct {
|
||||||
|
|
@ -59,3 +60,23 @@ func (r *linkRepository) GetBySlug(ctx context.Context, targetSlug string) ([]*m
|
||||||
|
|
||||||
return links, nil
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue