sourcegraph

package
v0.0.0-...-3b04aa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildQuery

func BuildQuery(baseQuery string, group string, revisions []string, lang string, filePattern string) string

BuildQuery assembles a Sourcegraph search query with filters.

func DiscoverVersions

func DiscoverVersions(mintignoreEntries []string) []string

DiscoverVersions extracts unique version prefixes from .mintignore entries matching the pattern "X.Y.Z/...". Returns versions sorted descending by semver. Falls back to ["main"] if none found.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is a thread-safe TTL cache with a maximum entry count.

func NewCache

func NewCache[T any](ttl time.Duration, maxSize int) *Cache[T]

NewCache creates a new TTL cache.

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string) (T, bool)

Get retrieves a cached value if it exists and hasn't expired.

func (*Cache[T]) Set

func (c *Cache[T]) Set(key string, value T)

Set stores a value in the cache.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides access to Sourcegraph's code search and file content APIs.

func New

func New(opts ...ClientOption) *Client

New creates a new Sourcegraph client.

func (*Client) GetFileContent

func (c *Client) GetFileContent(ctx context.Context, repo, revision, path string) (*FileContent, error)

GetFileContent fetches a file's content from a repository via GraphQL. Results are cached by repo@rev:path.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, searchType SearchType, maxResults int) <-chan SearchEvent

Search streams search results via a channel. The channel is closed when the search completes or the context is cancelled.

func (*Client) SearchSync

func (c *Client) SearchSync(ctx context.Context, query string, searchType SearchType, maxResults int) (*SearchResult, error)

SearchSync performs a search and returns all results at once.

type ClientOption

type ClientOption func(*Client)

ClientOption configures a Client.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client.

func WithInstanceURL

func WithInstanceURL(url string) ClientOption

WithInstanceURL sets the Sourcegraph instance URL.

func WithToken

func WithToken(token string) ClientOption

WithToken sets the Sourcegraph access token.

type FileContent

type FileContent struct {
	Repository string
	Revision   string
	Path       string
	Content    string
	ByteSize   int
}

FileContent is the content of a single file from a repository.

type Filter

type Filter struct {
	Label string
	Value string
	Count int
	Kind  string
}

Filter is a refinement option returned alongside search results.

type Highlight

type Highlight struct {
	Line      int
	Character int
	Length    int
}

Highlight marks a range within a match line.

type Match

type Match struct {
	Type       MatchType
	Repository string
	Revision   string
	Path       string
	LineNumber int
	Content    string
	Highlights []Highlight
	SymbolName string
	SymbolKind string
}

Match represents a single search result match.

type MatchType

type MatchType string

MatchType identifies the kind of match.

const (
	MatchContent MatchType = "content"
	MatchPath    MatchType = "path"
	MatchSymbol  MatchType = "symbol"
	MatchRepo    MatchType = "repo"
	MatchCommit  MatchType = "commit"
	MatchDiff    MatchType = "diff"
)

type RepoGroup

type RepoGroup struct {
	Name        string
	Description string
	RepoFilter  string
}

RepoGroup defines a preset repository filter.

func BazelRepoGroups

func BazelRepoGroups() []RepoGroup

BazelRepoGroups returns the preset Bazel repository groups.

type SearchEvent

type SearchEvent struct {
	Type     string         // "matches", "filters", "progress", "done", "error"
	Matches  []Match        // populated for "matches"
	Filters  []Filter       // populated for "filters"
	Progress SearchProgress // populated for "progress" and "done"
	Error    string         // populated for "error"
}

SearchEvent is a typed event emitted on the search channel.

type SearchProgress

type SearchProgress struct {
	MatchCount int
	Duration   int // milliseconds
	Done       bool
	Skipped    []SkippedReason
}

SearchProgress reports the search execution state.

type SearchResult

type SearchResult struct {
	Matches  []Match
	Filters  []Filter
	Progress SearchProgress
}

SearchResult aggregates all events from a completed search.

type SearchType

type SearchType string

SearchType selects the search mode.

const (
	SearchKeyword  SearchType = "keyword"
	SearchStandard SearchType = "standard"
	SearchRegexp   SearchType = "regexp"
)

type SkippedReason

type SkippedReason struct {
	Reason  string
	Message string
}

SkippedReason describes why some results were omitted.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL