Help us shape the future of Go! Take the 2026 Go Developer Survey

resolve

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package resolve provides shared utilities for determining whether an import path refers to an external dependency, a standard library module, or a local/relative import.

Index

Constants

This section is empty.

Variables

View Source
var CSharpConfig = LangConfig{
	StdlibCheck: func(topLevel string) bool {
		return topLevel == "System" || topLevel == "Microsoft"
	},
	IsRelative: nil,
	IsLocal:    nil,
	ExtractPkgName: func(path string) string {

		parts := strings.Split(path, ".")
		if len(parts) >= 2 {
			return parts[0] + "." + parts[1]
		}
		return path
	},
	Separator: ".",
}

CSharpConfig provides language-specific rules for C# imports.

View Source
var JavaConfig = LangConfig{
	StdlibCheck: func(topLevel string) bool {
		return topLevel == "java" || topLevel == "javax"
	},
	IsRelative: nil,
	IsLocal: func(path, localContext string) bool {
		if localContext == "" {
			return false
		}
		parts := strings.Split(path, ".")
		localParts := strings.Split(localContext, ".")
		if len(localParts) >= 2 && len(parts) >= 2 &&
			localParts[0] == parts[0] && localParts[1] == parts[1] {
			return true
		}
		return false
	},
	ExtractPkgName: func(path string) string {

		parts := strings.Split(path, ".")
		if len(parts) >= 2 {
			return parts[0] + "." + parts[1]
		}
		return path
	},
	Separator: ".",
}

JavaConfig provides language-specific rules for Java imports.

View Source
var PythonConfig = LangConfig{
	StdlibCheck: func(topLevel string) bool {
		return PythonStdlibSet[topLevel]
	},
	IsRelative: func(path string) bool {
		return strings.HasPrefix(path, ".")
	},
	IsLocal: nil,
	ExtractPkgName: func(path string) string {

		if idx := strings.Index(path, "."); idx > 0 {
			return path[:idx]
		}
		return path
	},
	Separator: ".",
}

PythonConfig provides language-specific rules for Python imports.

View Source
var PythonStdlibSet = map[string]bool{
	"os": true, "sys": true, "re": true, "io": true, "json": true,
	"math": true, "time": true, "datetime": true, "collections": true,
	"itertools": true, "functools": true, "pathlib": true, "typing": true,
	"abc": true, "ast": true, "asyncio": true, "base64": true,
	"contextlib": true, "copy": true, "csv": true, "dataclasses": true,
	"enum": true, "errno": true, "glob": true, "hashlib": true,
	"http": true, "importlib": true, "inspect": true, "logging": true,
	"multiprocessing": true, "operator": true, "pickle": true,
	"platform": true, "pprint": true, "queue": true, "random": true,
	"shutil": true, "signal": true, "socket": true, "sqlite3": true,
	"string": true, "struct": true, "subprocess": true, "tempfile": true,
	"textwrap": true, "threading": true, "traceback": true, "unittest": true,
	"urllib": true, "uuid": true, "warnings": true, "weakref": true,
	"xml": true, "zipfile": true, "argparse": true, "configparser": true,
	"email": true, "html": true, "ssl": true, "secrets": true,
	"statistics": true, "types": true,
}

PythonStdlibSet is the set of known Python stdlib top-level modules.

View Source
var RustConfig = LangConfig{
	StdlibCheck: func(topLevel string) bool {
		switch topLevel {
		case "std", "core", "alloc":
			return true
		}
		return false
	},
	IsRelative: func(path string) bool {
		parts := strings.SplitN(path, "::", 2)
		if len(parts) == 0 {
			return false
		}
		switch parts[0] {
		case "crate", "super", "self":
			return true
		}
		return false
	},
	IsLocal: nil,
	ExtractPkgName: func(path string) string {

		if idx := strings.Index(path, "::"); idx > 0 {
			return path[:idx]
		}
		return path
	},
	Separator: "::",
}

RustConfig provides language-specific rules for Rust imports.

View Source
var TypeScriptConfig = LangConfig{
	StdlibCheck: nil,
	IsRelative: func(path string) bool {
		return strings.HasPrefix(path, ".") || strings.HasPrefix(path, "/")
	},
	IsLocal: nil,
	ExtractPkgName: func(path string) string {

		if strings.HasPrefix(path, "@") {
			parts := strings.SplitN(path, "/", 3)
			if len(parts) >= 2 {
				return parts[0] + "/" + parts[1]
			}
			return path
		}

		if idx := strings.Index(path, "/"); idx > 0 {
			return path[:idx]
		}
		return path
	},
	Separator: "/",
}

TypeScriptConfig provides language-specific rules for TypeScript/JavaScript imports.

Functions

func InferExternalRepoURL

func InferExternalRepoURL(path string, localContext string, cfg LangConfig) string

InferExternalRepoURL returns "external://{pkgName}" for external packages, "stdlib" for standard library imports, or "" for relative/local imports. The localContext parameter is optional (used by Java for same-package detection).

Types

type LangConfig

type LangConfig struct {
	// StdlibCheck returns true if the top-level segment indicates stdlib.
	StdlibCheck func(topLevel string) bool
	// IsRelative returns true if the path is a relative/local import.
	IsRelative func(path string) bool
	// IsLocal returns true if the path is local to the project (e.g., same Java package prefix).
	// May be nil if not applicable.
	IsLocal func(path, localContext string) bool
	// ExtractPkgName extracts the package identifier from the full import path.
	// Returns the portion to use after "external://".
	ExtractPkgName func(path string) string
	// Separator is the path component separator ("/" for TS, "." for Java/C#, "::" for Rust).
	Separator string
}

LangConfig provides language-specific rules for external URL inference.

Jump to

Keyboard shortcuts

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