MCPcopy Create free account
hub / github.com/microsoft/typescript-go / Run

Method Run

internal/api/server.go:57–124  ·  view source on GitHub ↗

Run starts the server and blocks until the connection closes.

(ctx context.Context)

Source from the content-addressed store, hash-verified

55
56// Run starts the server and blocks until the connection closes.
57func (s *StdioServer) Run(ctx context.Context) error {
58 var transport Transport
59 if s.options.PipePath != "" {
60 t, err := NewPipeTransport(s.options.PipePath)
61 if err != nil {
62 return fmt.Errorf("failed to create pipe transport: %w", err)
63 }
64 defer t.Close()
65 transport = t
66 } else {
67 t := NewStdioTransport(s.options.In, s.options.Out)
68 defer t.Close()
69 transport = t
70 }
71
72 fs := bundled.WrapFS(osvfs.FS())
73
74 // Wrap the base FS with callbackFS if callbacks are requested
75 var callbackFS *callbackFS
76 if len(s.options.Callbacks) > 0 {
77 callbackFS = newCallbackFS(fs, s.options.Callbacks)
78 fs = callbackFS
79 }
80
81 projectSession := project.NewSession(&project.SessionInit{
82 BackgroundCtx: ctx,
83 Logger: nil, // TODO: Add logging support
84 FS: fs,
85 Options: &project.SessionOptions{
86 CurrentDirectory: s.options.Cwd,
87 DefaultLibraryPath: s.options.DefaultLibraryPath,
88 PositionEncoding: lsproto.PositionEncodingKindUTF8,
89 LoggingEnabled: false,
90 },
91 })
92
93 session := NewSession(projectSession, &SessionOptions{
94 UseBinaryResponses: !s.options.Async, // Only msgpack uses binary responses
95 })
96 defer session.Close()
97
98 // Accept connection from transport
99 rwc, err := transport.Accept()
100 if err != nil {
101 return fmt.Errorf("failed to accept connection: %w", err)
102 }
103
104 // Create protocol and connection based on async mode
105 var conn Conn
106 if s.options.Async {
107 protocol := NewJSONRPCProtocol(rwc)
108 asyncConn := NewAsyncConnWithProtocol(rwc, protocol, session)
109 asyncConn.SetCollectTiming(s.options.CollectTiming)
110 conn = asyncConn
111 } else {
112 protocol := NewMessagePackProtocol(rwc)
113 syncConn := NewSyncConn(rwc, protocol, session)
114 syncConn.SetCollectTiming(s.options.CollectTiming)

Callers 1

runAPIFunction · 0.95

Calls 15

CloseMethod · 0.95
CloseMethod · 0.95
AcceptMethod · 0.95
SetCollectTimingMethod · 0.95
SetConnectionMethod · 0.95
RunMethod · 0.95
WrapFSFunction · 0.92
FSFunction · 0.92
NewSessionFunction · 0.92
NewPipeTransportFunction · 0.85
NewStdioTransportFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected