Skip to content

Commit a11c0f7

Browse files
committed
callback for isNodesourceFile
1 parent a54d5e9 commit a11c0f7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

internal/api/server.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/binary"
77
"fmt"
88
"io"
9+
"os"
910
"runtime/debug"
1011
"strconv"
1112
"strings"
@@ -70,6 +71,7 @@ const (
7071
CallbackGetPackageJsonScopeIfApplicable
7172
CallbackGetPackageScopeForPath
7273
CallbackGetImpliedNodeFormatForFile
74+
CallbackIsNodeSourceFile
7375
)
7476

7577
type ServerOptions struct {
@@ -173,6 +175,26 @@ func (h *hostWrapper) SessionOptions() *project.SessionOptions {
173175

174176
// IsNodeSourceFile implements project.ProjectHost.
175177
func (h *hostWrapper) IsNodeSourceFile(path tspath.Path) bool {
178+
fmt.Fprintf(os.Stderr, "host IsNodeSourceFile %s\n", path)
179+
if h.server.CallbackEnabled(CallbackIsNodeSourceFile) {
180+
fmt.Fprintf(os.Stderr, "IsNodeSourceFile callback %s\n", path)
181+
result, err := h.server.call("isNodeSourceFile", path)
182+
if err != nil {
183+
panic(err)
184+
}
185+
if len(result) > 0 {
186+
var res bool
187+
if err := json.Unmarshal(result, &res); err != nil {
188+
panic(err)
189+
}
190+
if res {
191+
fmt.Fprintf(os.Stderr, "IsNodeSourceFile callback returning true %s\n", path)
192+
} else {
193+
fmt.Fprintf(os.Stderr, "IsNodeSourceFile callback returning false %s\n", path)
194+
}
195+
return res
196+
}
197+
}
176198
return h.inner.IsNodeSourceFile(path)
177199
}
178200

@@ -506,6 +528,8 @@ func (s *Server) enableCallback(callback string) error {
506528
s.enabledCallbacks |= CallbackGetPackageScopeForPath
507529
case "getImpliedNodeFormatForFile":
508530
s.enabledCallbacks |= CallbackGetImpliedNodeFormatForFile
531+
case "isNodeSourceFile":
532+
s.enabledCallbacks |= CallbackIsNodeSourceFile
509533
default:
510534
return fmt.Errorf("unknown callback: %s", callback)
511535
}

0 commit comments

Comments
 (0)