From 7418956c7b01c6023bed52e1a255d12988ad2932 Mon Sep 17 00:00:00 2001 From: Mattia Manzati Date: Fri, 29 May 2026 11:25:41 +0200 Subject: [PATCH] feat: add module shim --- .changeset/add-module-shim.md | 5 +++ _tools/gen_shims/main.go | 1 + go.mod | 2 + go.work | 1 + shim/ls/extra-shim.json | 13 +++--- shim/ls/shim.go | 2 + shim/module/go.mod | 5 +++ shim/module/shim.go | 76 +++++++++++++++++++++++++++++++++++ 8 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 .changeset/add-module-shim.md create mode 100644 shim/module/go.mod create mode 100644 shim/module/shim.go diff --git a/.changeset/add-module-shim.md b/.changeset/add-module-shim.md new file mode 100644 index 00000000..12a3edba --- /dev/null +++ b/.changeset/add-module-shim.md @@ -0,0 +1,5 @@ +--- +"@effect/tsgo": patch +--- + +Expose additional TypeScript-Go shims for module resolution and language service quick info documentation. diff --git a/_tools/gen_shims/main.go b/_tools/gen_shims/main.go index d4750de9..c18969a2 100644 --- a/_tools/gen_shims/main.go +++ b/_tools/gen_shims/main.go @@ -67,6 +67,7 @@ func main() { "ls/lsutil", "lsp", "lsp/lsproto", + "module", "modulespecifiers", "packagejson", "parser", diff --git a/go.mod b/go.mod index cbbbd4ea..7eaec22b 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ replace ( github.com/microsoft/typescript-go/shim/ls/lsutil => ./shim/ls/lsutil github.com/microsoft/typescript-go/shim/lsp => ./shim/lsp github.com/microsoft/typescript-go/shim/lsp/lsproto => ./shim/lsp/lsproto + github.com/microsoft/typescript-go/shim/module => ./shim/module github.com/microsoft/typescript-go/shim/modulespecifiers => ./shim/modulespecifiers github.com/microsoft/typescript-go/shim/packagejson => ./shim/packagejson github.com/microsoft/typescript-go/shim/parser => ./shim/parser @@ -62,6 +63,7 @@ require ( github.com/microsoft/typescript-go/shim/ls/lsconv v0.0.0-00010101000000-000000000000 github.com/microsoft/typescript-go/shim/ls/lsutil v0.0.0-00010101000000-000000000000 github.com/microsoft/typescript-go/shim/lsp/lsproto v0.0.0-00010101000000-000000000000 + github.com/microsoft/typescript-go/shim/module v0.0.0-00010101000000-000000000000 github.com/microsoft/typescript-go/shim/modulespecifiers v0.0.0-00010101000000-000000000000 github.com/microsoft/typescript-go/shim/packagejson v0.0.0-00010101000000-000000000000 github.com/microsoft/typescript-go/shim/parser v0.0.0-00010101000000-000000000000 diff --git a/go.work b/go.work index 041fa093..844412a7 100644 --- a/go.work +++ b/go.work @@ -21,6 +21,7 @@ use ( ./shim/ls/lsutil ./shim/lsp ./shim/lsp/lsproto + ./shim/module ./shim/modulespecifiers ./shim/packagejson ./shim/parser diff --git a/shim/ls/extra-shim.json b/shim/ls/extra-shim.json index 615850dc..e71449f8 100644 --- a/shim/ls/extra-shim.json +++ b/shim/ls/extra-shim.json @@ -1,5 +1,8 @@ -{ - "ExtraFields": { - "LanguageService": ["converters"] - } -} +{ + "ExtraMethods": { + "LanguageService": ["getQuickInfoAndDocumentationForSymbol"] + }, + "ExtraFields": { + "LanguageService": ["converters"] + } +} diff --git a/shim/ls/shim.go b/shim/ls/shim.go index f10a1ea7..4b784ced 100644 --- a/shim/ls/shim.go +++ b/shim/ls/shim.go @@ -83,6 +83,8 @@ const KeywordCompletionFiltersTypeAssertionKeywords = ls.KeywordCompletionFilter const KeywordCompletionFiltersTypeKeyword = ls.KeywordCompletionFiltersTypeKeyword const KeywordCompletionFiltersTypeKeywords = ls.KeywordCompletionFiltersTypeKeywords type LanguageService = ls.LanguageService +//go:linkname LanguageService_getQuickInfoAndDocumentationForSymbol github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getQuickInfoAndDocumentationForSymbol +func LanguageService_getQuickInfoAndDocumentationForSymbol(recv *ls.LanguageService, c *checker.Checker, symbol *ast.Symbol, node *ast.Node, contentFormat lsproto.MarkupKind, vc *checker.VerbosityContext) (string, string) type extra_LanguageService struct { projectPath tspath.Path host ls.Host diff --git a/shim/module/go.mod b/shim/module/go.mod new file mode 100644 index 00000000..2fa48412 --- /dev/null +++ b/shim/module/go.mod @@ -0,0 +1,5 @@ +module github.com/microsoft/typescript-go/shim/module + +go 1.26 + +require github.com/microsoft/typescript-go v0.0.0 diff --git a/shim/module/shim.go b/shim/module/shim.go new file mode 100644 index 00000000..f3e4c813 --- /dev/null +++ b/shim/module/shim.go @@ -0,0 +1,76 @@ + +// Code generated by _tools/gen_shims. DO NOT EDIT. + +package module + +import "github.com/microsoft/typescript-go/internal/ast" +import "github.com/microsoft/typescript-go/internal/collections" +import "github.com/microsoft/typescript-go/internal/core" +import "github.com/microsoft/typescript-go/internal/diagnostics" +import "github.com/microsoft/typescript-go/internal/module" +import _ "unsafe" + +//go:linkname ComparePatternKeys github.com/microsoft/typescript-go/internal/module.ComparePatternKeys +func ComparePatternKeys(a string, b string) int +type DiagAndArgs = module.DiagAndArgs +type Ending = module.Ending +const EndingChangeable = module.EndingChangeable +const EndingExtensionChangeable = module.EndingExtensionChangeable +const EndingFixed = module.EndingFixed +//go:linkname GetAutomaticTypeDirectiveNames github.com/microsoft/typescript-go/internal/module.GetAutomaticTypeDirectiveNames +func GetAutomaticTypeDirectiveNames(options *core.CompilerOptions, host module.ResolutionHost) []string +//go:linkname GetCompilerOptionsWithRedirect github.com/microsoft/typescript-go/internal/module.GetCompilerOptionsWithRedirect +func GetCompilerOptionsWithRedirect(compilerOptions *core.CompilerOptions, redirectedReference module.ResolvedProjectReference) *core.CompilerOptions +//go:linkname GetConditions github.com/microsoft/typescript-go/internal/module.GetConditions +func GetConditions(options *core.CompilerOptions, resolutionMode core.ResolutionMode) []string +//go:linkname GetPackageNameFromTypesPackageName github.com/microsoft/typescript-go/internal/module.GetPackageNameFromTypesPackageName +func GetPackageNameFromTypesPackageName(mangledName string) string +//go:linkname GetResolutionDiagnostic github.com/microsoft/typescript-go/internal/module.GetResolutionDiagnostic +func GetResolutionDiagnostic(options *core.CompilerOptions, resolvedModule *module.ResolvedModule, file *ast.SourceFile) *diagnostics.Message +//go:linkname GetTypesPackageName github.com/microsoft/typescript-go/internal/module.GetTypesPackageName +func GetTypesPackageName(packageName string) string +const InferredTypesContainingFile = module.InferredTypesContainingFile +//go:linkname IsApplicableVersionedTypesKey github.com/microsoft/typescript-go/internal/module.IsApplicableVersionedTypesKey +func IsApplicableVersionedTypesKey(key string) bool +//go:linkname MangleScopedPackageName github.com/microsoft/typescript-go/internal/module.MangleScopedPackageName +func MangleScopedPackageName(packageName string) string +//go:linkname MatchPatternOrExact github.com/microsoft/typescript-go/internal/module.MatchPatternOrExact +func MatchPatternOrExact(patterns *module.ParsedPatterns, candidate string) core.Pattern +type ModeAwareCache[T any] = module.ModeAwareCache[T] +type ModeAwareCacheKey = module.ModeAwareCacheKey +//go:linkname NewResolver github.com/microsoft/typescript-go/internal/module.NewResolver +func NewResolver(host module.ResolutionHost, options *core.CompilerOptions, typingsLocation string, projectName string) *module.Resolver +//go:linkname NewResolverWithOptions github.com/microsoft/typescript-go/internal/module.NewResolverWithOptions +func NewResolverWithOptions(host module.ResolutionHost, compilerOptions *core.CompilerOptions, typingsLocation string, projectName string, opts module.ResolverOptions) *module.Resolver +type NodeResolutionFeatures = module.NodeResolutionFeatures +const NodeResolutionFeaturesAll = module.NodeResolutionFeaturesAll +const NodeResolutionFeaturesBundlerDefault = module.NodeResolutionFeaturesBundlerDefault +const NodeResolutionFeaturesExports = module.NodeResolutionFeaturesExports +const NodeResolutionFeaturesExportsPatternTrailers = module.NodeResolutionFeaturesExportsPatternTrailers +const NodeResolutionFeaturesImports = module.NodeResolutionFeaturesImports +const NodeResolutionFeaturesImportsPatternRoot = module.NodeResolutionFeaturesImportsPatternRoot +const NodeResolutionFeaturesNode16Default = module.NodeResolutionFeaturesNode16Default +const NodeResolutionFeaturesNodeNextDefault = module.NodeResolutionFeaturesNodeNextDefault +const NodeResolutionFeaturesNone = module.NodeResolutionFeaturesNone +const NodeResolutionFeaturesSelfName = module.NodeResolutionFeaturesSelfName +type PackageId = module.PackageId +//go:linkname ParseNodeModuleFromPath github.com/microsoft/typescript-go/internal/module.ParseNodeModuleFromPath +func ParseNodeModuleFromPath(resolved string, isFolder bool) string +//go:linkname ParsePackageName github.com/microsoft/typescript-go/internal/module.ParsePackageName +func ParsePackageName(moduleName string) (packageName string, rest string) +type ParsedPatterns = module.ParsedPatterns +type ResolutionHost = module.ResolutionHost +//go:linkname ResolveConfig github.com/microsoft/typescript-go/internal/module.ResolveConfig +func ResolveConfig(moduleName string, containingFile string, host module.ResolutionHost) *module.ResolvedModule +type ResolvedEntrypoint = module.ResolvedEntrypoint +type ResolvedModule = module.ResolvedModule +type ResolvedProjectReference = module.ResolvedProjectReference +type ResolvedTypeReferenceDirective = module.ResolvedTypeReferenceDirective +type Resolver = module.Resolver +type ResolverOptions = module.ResolverOptions +//go:linkname TryGetJSExtensionForFile github.com/microsoft/typescript-go/internal/module.TryGetJSExtensionForFile +func TryGetJSExtensionForFile(fileName string, options *core.CompilerOptions) string +//go:linkname TryParsePatterns github.com/microsoft/typescript-go/internal/module.TryParsePatterns +func TryParsePatterns(pathMappings *collections.OrderedMap[string, []string]) *module.ParsedPatterns +//go:linkname UnmangleScopedPackageName github.com/microsoft/typescript-go/internal/module.UnmangleScopedPackageName +func UnmangleScopedPackageName(packageName string) string