Skip to content

Proposal: Global language definition registry for extensions #338

Description

@David-Noble-at-work

Migrated from NobleFactor/noblefactor-engprod#45 (star now lives in this repository; GitHub blocks private→public transfers). Original discussion remains there.

Summary

Create a shared internal/language package that provides language definitions for all extensions to use. This would centralize:

  • File extension mappings
  • Filename mappings (Makefile, Dockerfile, etc.)
  • Shebang pattern matching
  • Comment styles (line and block)
  • Language metadata

Motivation

Currently, the copyright package embeds its own language definitions in internal/copyright/defaults.yaml. Other extensions may need similar language information:

  • Documentation generators need comment styles
  • Code formatters need language detection
  • Linters need file type identification
  • Syntax highlighters need language metadata

Duplicating language definitions across extensions is error-prone and inconsistent.

Proposal

1. Create internal/language package

// internal/language/language.go
type Language struct {
    ID          string   // e.g., "go", "python", "javascript"
    Name        string   // Display name: "Go", "Python", "JavaScript"
    Extensions  []string // [".go"], [".py", ".pyw"], etc.
    Filenames   []string // ["Makefile"], ["Dockerfile"], etc.
    Shebangs    []string // Regex patterns for shebang detection
    LineComment string   // "//", "#", "--", etc.
    BlockComment struct {
        Start  string // "/*", "<!--", etc.
        Prefix string // " *", "  ", etc.
        End    string // "*/", "-->", etc.
    }
    Aliases     []string // ["golang"], ["python3", "py"], etc.
}

2. Data source: VS Code language contributions

VS Code's language definitions are MIT-licensed and cover 100+ languages:

We could:

  1. Extract and convert VS Code definitions to our format
  2. Maintain a curated subset manually
  3. Generate from VS Code at build time

3. Starlark receiver

# In Starlark scripts
lang = language.detect("script.py")
# Returns: {language: "python", method: "extension", comment_line: "#", ...}

lang = language.get("python")
# Returns full language definition

langs = language.all()
# Returns list of all supported languages

4. Integration with copyright package

The copyright package would use internal/language for detection and comment styles, adding only copyright-specific config (header templates, match patterns).

Alternatives Considered

  1. Keep language definitions per-extension: Current approach. Simple but duplicates data.
  2. External dependency: Use a third-party language detection library. Adds dependency complexity.
  3. Minimal shared detection: Only share extension → language mapping, let extensions define their own comment styles. Partial solution.

Implementation Plan

  1. Create internal/language package with types
  2. Extract/create language definitions YAML
  3. Implement detector with extension/filename/shebang priority
  4. Create language Starlark receiver
  5. Migrate copyright package to use shared language detection
  6. Document for extension authors

References

Activity

  1. David-Noble-at-work commented on Nov 9, 2026

    @David-Noble-at-work
    ContributorAuthor

    star github triage sweep added this issue to Triage: devlore, for the rule it breaks:

    • no-evidence: no Evidence of completion section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions