|
6 | 6 | "encoding/binary" |
7 | 7 | "fmt" |
8 | 8 | "io" |
| 9 | + "os" |
9 | 10 | "runtime/debug" |
10 | 11 | "strconv" |
11 | 12 | "strings" |
@@ -70,6 +71,7 @@ const ( |
70 | 71 | CallbackGetPackageJsonScopeIfApplicable |
71 | 72 | CallbackGetPackageScopeForPath |
72 | 73 | CallbackGetImpliedNodeFormatForFile |
| 74 | + CallbackIsNodeSourceFile |
73 | 75 | ) |
74 | 76 |
|
75 | 77 | type ServerOptions struct { |
@@ -173,6 +175,26 @@ func (h *hostWrapper) SessionOptions() *project.SessionOptions { |
173 | 175 |
|
174 | 176 | // IsNodeSourceFile implements project.ProjectHost. |
175 | 177 | 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 | + } |
176 | 198 | return h.inner.IsNodeSourceFile(path) |
177 | 199 | } |
178 | 200 |
|
@@ -506,6 +528,8 @@ func (s *Server) enableCallback(callback string) error { |
506 | 528 | s.enabledCallbacks |= CallbackGetPackageScopeForPath |
507 | 529 | case "getImpliedNodeFormatForFile": |
508 | 530 | s.enabledCallbacks |= CallbackGetImpliedNodeFormatForFile |
| 531 | + case "isNodeSourceFile": |
| 532 | + s.enabledCallbacks |= CallbackIsNodeSourceFile |
509 | 533 | default: |
510 | 534 | return fmt.Errorf("unknown callback: %s", callback) |
511 | 535 | } |
|
0 commit comments