polyglot

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package polyglot detects multi-language repository structures by scanning manifest files (go.mod, package.json, Cargo.toml, etc.) and grouping source files into language-specific layers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyLayerRole

func ClassifyLayerRole(sources []string) string

ClassifyLayerRole is the public entry point for role classification. It takes source code snippets from a single layer and returns one of: "server", "client", "worker", or "library".

func DominantLanguage added in v1.22.2

func DominantLanguage(files []*ingest.File) string

DominantLanguage returns the most common language among the given files, counting only files with a non-empty Language. Returns "" if files is empty or no file has a recognised language.

This is the canonical implementation shared by every package that needs "most frequent language among a file set" — do not reimplement the argmax locally.

func DominantLanguageFromCounts added in v1.22.2

func DominantLanguageFromCounts(counts map[string]int) string

DominantLanguageFromCounts returns the language with the highest count. Returns "" if the map is empty. Ties resolve by Go's non-deterministic map iteration order, matching prior per-package implementations.

Types

type CargoInfo

type CargoInfo struct {
	Name             string
	Version          string
	Edition          string
	Dependencies     []string
	DevDependencies  []string
	WorkspaceMembers []string
}

CargoInfo contains metadata extracted from a Cargo.toml file.

func ParseCargoToml

func ParseCargoToml(data []byte) CargoInfo

ParseCargoToml extracts dependency and metadata from Cargo.toml content. Uses simple line-based parsing to avoid adding a TOML dependency.

type Layer

type Layer struct {
	Name     string
	Role     string
	RootDir  string
	Language string
	Files    int
}

Layer represents a distinct language area within the repository, typically rooted at a manifest file (go.mod, package.json, etc.).

type Manifest

type Manifest struct {
	Path     string
	Type     string
	Language string
}

Manifest represents a detected build/dependency manifest file.

type RepoStructure

type RepoStructure struct {
	Layers    []Layer
	Languages map[string]int
	Manifests []Manifest
}

RepoStructure describes the detected language layout of a repository.

func DetectStructure

func DetectStructure(files []*ingest.File) *RepoStructure

DetectStructure scans a list of ingested files for manifest files, groups files by the nearest manifest root, and builds layers.

func (*RepoStructure) IsPolyglot

func (rs *RepoStructure) IsPolyglot() bool

IsPolyglot reports whether the repository contains 2 or more languages each with at least polyglotThreshold source files.

Directories

Path Synopsis
Package pinned extracts container image references from indexed repo files.
Package pinned extracts container image references from indexed repo files.

Jump to

Keyboard shortcuts

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