diff --git a/.changeset/remove-effect-diagnostics-api.md b/.changeset/remove-effect-diagnostics-api.md new file mode 100644 index 00000000..9c32f352 --- /dev/null +++ b/.changeset/remove-effect-diagnostics-api.md @@ -0,0 +1,5 @@ +--- +"@effect/tsgo": patch +--- + +Remove the unused native `getEffectDiagnostics` API hook from the patched TypeScript-Go API. diff --git a/_patches/001-cmd-tsgo-main.patch b/_patches/001-cmd-tsgo-main.patch index 41a3bb33..f0579f1e 100644 --- a/_patches/001-cmd-tsgo-main.patch +++ b/_patches/001-cmd-tsgo-main.patch @@ -2,12 +2,11 @@ diff --git a/cmd/tsgo/main.go b/cmd/tsgo/main.go index 8d6816fa3d..49c6cbecba 100644 --- a/cmd/tsgo/main.go +++ b/cmd/tsgo/main.go -@@ -6,6 +6,12 @@ import ( +@@ -6,6 +6,11 @@ import ( "os/signal" "syscall" + // Import Effect hooks to register via init() -+ _ "github.com/effect-ts/tsgo/etsapihooks" // native API hooks + _ "github.com/effect-ts/tsgo/etsexecutehooks" // exit-code filtering hooks + _ "github.com/effect-ts/tsgo/etscheckerhooks" // checker diagnostics hooks + _ "github.com/effect-ts/tsgo/etslshooks" // LS codefix hooks diff --git a/_patches/028-api-effect-diagnostics.patch b/_patches/028-api-effect-diagnostics.patch deleted file mode 100644 index c71d471f..00000000 --- a/_patches/028-api-effect-diagnostics.patch +++ /dev/null @@ -1,121 +0,0 @@ -diff --git a/internal/api/proto.go b/internal/api/proto.go ---- a/internal/api/proto.go -+++ b/internal/api/proto.go -@@ -4,6 +4,7 @@ import ( - "errors" - "fmt" - -+ "github.com/effect-ts/tsgo/etscore" - "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/checker" - "github.com/microsoft/typescript-go/internal/core" -@@ -142,6 +143,7 @@ const ( - MethodGetSyntacticDiagnostics Method = "getSyntacticDiagnostics" - MethodGetBindDiagnostics Method = "getBindDiagnostics" - MethodGetSemanticDiagnostics Method = "getSemanticDiagnostics" -+ MethodGetEffectDiagnostics Method = "getEffectDiagnostics" - MethodGetSuggestionDiagnostics Method = "getSuggestionDiagnostics" - MethodGetDeclarationDiagnostics Method = "getDeclarationDiagnostics" - MethodGetProgramDiagnostics Method = "getProgramDiagnostics" -@@ -415,6 +417,7 @@ var unmarshalers = map[Method]func([]byte) (any, error){ - MethodGetSyntacticDiagnostics: unmarshallerFor[GetDiagnosticsParams], - MethodGetBindDiagnostics: unmarshallerFor[GetDiagnosticsParams], - MethodGetSemanticDiagnostics: unmarshallerFor[GetDiagnosticsParams], -+ MethodGetEffectDiagnostics: unmarshallerFor[GetEffectDiagnosticsParams], - MethodGetSuggestionDiagnostics: unmarshallerFor[GetDiagnosticsParams], - MethodGetDeclarationDiagnostics: unmarshallerFor[GetDiagnosticsParams], - MethodGetProgramDiagnostics: unmarshallerFor[GetProjectDiagnosticsParams], -@@ -994,6 +997,15 @@ type GetDiagnosticsParams struct { - File *DocumentIdentifier `json:"file,omitempty"` - } - -+// GetEffectDiagnosticsParams are parameters for Effect diagnostic rules. -+type GetEffectDiagnosticsParams struct { -+ Snapshot SnapshotID `json:"snapshot"` -+ Project ProjectID `json:"project"` -+ File DocumentIdentifier `json:"file"` -+ Options *etscore.EffectPluginOptions `json:"options,omitempty"` -+ Rules []string `json:"rules,omitempty"` -+} -+ - // GetProjectDiagnosticsParams are parameters for project-wide diagnostic methods. - type GetProjectDiagnosticsParams struct { - Snapshot SnapshotID `json:"snapshot"` -diff --git a/internal/api/session.go b/internal/api/session.go ---- a/internal/api/session.go -+++ b/internal/api/session.go -@@ -9,6 +9,7 @@ import ( - "sync" - "sync/atomic" - -+ "github.com/effect-ts/tsgo/etscore" - "github.com/microsoft/typescript-go/internal/api/encoder" - "github.com/microsoft/typescript-go/internal/ast" - "github.com/microsoft/typescript-go/internal/astnav" -@@ -27,6 +28,15 @@ import ( - "github.com/microsoft/typescript-go/internal/tspath" - ) - -+// GetEffectDiagnosticsCallback is invoked by the API getEffectDiagnostics method. -+// It is registered by external packages to keep Effect rule evaluation outside TypeScript-Go. -+var GetEffectDiagnosticsCallback func(ctx context.Context, program *compiler.Program, c *checker.Checker, sourceFile *ast.SourceFile, options *etscore.EffectPluginOptions, rules []string) ([]*ast.Diagnostic, error) -+ -+// RegisterGetEffectDiagnosticsCallback registers the getEffectDiagnostics API callback. -+func RegisterGetEffectDiagnosticsCallback(cb func(ctx context.Context, program *compiler.Program, c *checker.Checker, sourceFile *ast.SourceFile, options *etscore.EffectPluginOptions, rules []string) ([]*ast.Diagnostic, error)) { -+ GetEffectDiagnosticsCallback = cb -+} -+ - var sessionIDCounter atomic.Uint64 - - // snapshotData holds the per-snapshot state including the snapshot itself -@@ -675,6 +685,8 @@ func (s *Session) HandleRequest(ctx context.Context, method string, params json. - return s.handleGetBindDiagnostics(ctx, parsed.(*GetDiagnosticsParams)) - case string(MethodGetSemanticDiagnostics): - return s.handleGetSemanticDiagnostics(ctx, parsed.(*GetDiagnosticsParams)) -+ case string(MethodGetEffectDiagnostics): -+ return s.handleGetEffectDiagnostics(ctx, parsed.(*GetEffectDiagnosticsParams)) - case string(MethodGetSuggestionDiagnostics): - return s.handleGetSuggestionDiagnostics(ctx, parsed.(*GetDiagnosticsParams)) - case string(MethodGetDeclarationDiagnostics): -@@ -2484,6 +2496,41 @@ func (s *Session) handleGetSemanticDiagnostics(ctx context.Context, params *GetD - return NewDiagnosticResponses(diags), nil - } - -+// handleGetEffectDiagnostics returns Effect diagnostics for a file using explicit API options. -+func (s *Session) handleGetEffectDiagnostics(ctx context.Context, params *GetEffectDiagnosticsParams) ([]*DiagnosticResponse, error) { -+ if GetEffectDiagnosticsCallback == nil { -+ return nil, fmt.Errorf("getEffectDiagnostics callback is not registered") -+ } -+ -+ ctx = core.WithCheckerLifetime(ctx, core.CheckerLifetimeDiagnostics) -+ sd, err := s.getSnapshotData(params.Snapshot) -+ if err != nil { -+ return nil, err -+ } -+ -+ program, err := sd.getProgram(params.Project) -+ if err != nil { -+ return nil, err -+ } -+ -+ sourceFile := program.GetSourceFile(params.File.ToFileName()) -+ if sourceFile == nil { -+ return nil, fmt.Errorf("source file not found: %s", params.File.ToFileName()) -+ } -+ -+ c, done := program.GetTypeCheckerForFileExclusive(ctx, sourceFile) -+ defer done() -+ -+ // Ensure the source file is checked before running rules that rely on type information. -+ c.GetDiagnostics(ctx, sourceFile) -+ -+ diags, err := GetEffectDiagnosticsCallback(ctx, program, c, sourceFile, params.Options, params.Rules) -+ if err != nil { -+ return nil, err -+ } -+ return NewDiagnosticResponses(diags), nil -+} -+ - // handleGetSuggestionDiagnostics returns suggestion diagnostics for a file or all files. - func (s *Session) handleGetSuggestionDiagnostics(ctx context.Context, params *GetDiagnosticsParams) ([]*DiagnosticResponse, error) { - ctx = core.WithCheckerLifetime(ctx, core.CheckerLifetimeDiagnostics) diff --git a/etsapihooks/doc.go b/etsapihooks/doc.go deleted file mode 100644 index 82645155..00000000 --- a/etsapihooks/doc.go +++ /dev/null @@ -1,5 +0,0 @@ -// Package etsapihooks registers Effect API hooks for TypeScript-Go. -// -// This package should be imported with a blank identifier by the main entry point -// to register API-only Effect diagnostics. -package etsapihooks diff --git a/etsapihooks/init.go b/etsapihooks/init.go deleted file mode 100644 index 1ddfaa31..00000000 --- a/etsapihooks/init.go +++ /dev/null @@ -1,25 +0,0 @@ -package etsapihooks - -import ( - "context" - - "github.com/effect-ts/tsgo/etscore" - "github.com/effect-ts/tsgo/internal/effectconfigraw" - "github.com/effect-ts/tsgo/internal/rulerunner" - "github.com/microsoft/typescript-go/shim/api" - "github.com/microsoft/typescript-go/shim/ast" - "github.com/microsoft/typescript-go/shim/checker" - "github.com/microsoft/typescript-go/shim/compiler" -) - -func init() { - effectconfigraw.Register() - api.RegisterGetEffectDiagnosticsCallback(getEffectDiagnostics) -} - -func getEffectDiagnostics(ctx context.Context, program *compiler.Program, c *checker.Checker, sf *ast.SourceFile, options *etscore.EffectPluginOptions, ruleNames []string) ([]*ast.Diagnostic, error) { - if options == nil { - options = program.Options().Effect - } - return rulerunner.Run(ctx, program, c, sf, options, ruleNames) -} diff --git a/shim/api/shim.go b/shim/api/shim.go index 2e266e7b..c084fba2 100644 --- a/shim/api/shim.go +++ b/shim/api/shim.go @@ -3,12 +3,9 @@ package api -import "context" -import "github.com/effect-ts/tsgo/etscore" import "github.com/microsoft/typescript-go/internal/api" import "github.com/microsoft/typescript-go/internal/ast" import "github.com/microsoft/typescript-go/internal/checker" -import "github.com/microsoft/typescript-go/internal/compiler" import "github.com/microsoft/typescript-go/internal/project" import "io" import _ "unsafe" @@ -36,8 +33,6 @@ type GetCompletionsAtPositionParams = api.GetCompletionsAtPositionParams type GetContextualTypeParams = api.GetContextualTypeParams type GetDefaultProjectForFileParams = api.GetDefaultProjectForFileParams type GetDiagnosticsParams = api.GetDiagnosticsParams -var GetEffectDiagnosticsCallback = api.GetEffectDiagnosticsCallback -type GetEffectDiagnosticsParams = api.GetEffectDiagnosticsParams type GetIntrinsicTypeParams = api.GetIntrinsicTypeParams type GetNonNullableTypeParams = api.GetNonNullableTypeParams type GetParameterTypeParams = api.GetParameterTypeParams @@ -100,7 +95,6 @@ const MethodGetDeclarationDiagnostics = api.MethodGetDeclarationDiagnostics const MethodGetDeclaredTypeOfSymbol = api.MethodGetDeclaredTypeOfSymbol const MethodGetDefaultProjectForFile = api.MethodGetDefaultProjectForFile const MethodGetESSymbolType = api.MethodGetESSymbolType -const MethodGetEffectDiagnostics = api.MethodGetEffectDiagnostics const MethodGetExportSymbolOfSymbol = api.MethodGetExportSymbolOfSymbol const MethodGetExportsOfSymbol = api.MethodGetExportsOfSymbol const MethodGetExtendsTypeOfType = api.MethodGetExtendsTypeOfType @@ -213,8 +207,6 @@ type ProjectResponse = api.ProjectResponse type Protocol = api.Protocol type RawBinary = api.RawBinary type ReferencedSymbolEntry = api.ReferencedSymbolEntry -//go:linkname RegisterGetEffectDiagnosticsCallback github.com/microsoft/typescript-go/internal/api.RegisterGetEffectDiagnosticsCallback -func RegisterGetEffectDiagnosticsCallback(cb func(ctx context.Context, program *compiler.Program, c *checker.Checker, sourceFile *ast.SourceFile, options *etscore.EffectPluginOptions, rules []string) ([]*ast.Diagnostic, error)) type ReleaseParams = api.ReleaseParams type ResolveNameParams = api.ResolveNameParams type Session = api.Session