@@ -23,7 +23,6 @@ import (
2323 "github.com/microsoft/typescript-go/internal/lsp/lsproto"
2424 "github.com/microsoft/typescript-go/internal/project"
2525 "github.com/microsoft/typescript-go/internal/project/ata"
26- "github.com/microsoft/typescript-go/internal/project/logging"
2726 "github.com/microsoft/typescript-go/internal/tspath"
2827 "github.com/microsoft/typescript-go/internal/vfs"
2928 "golang.org/x/sync/errgroup"
@@ -40,27 +39,17 @@ type ServerOptions struct {
4039 TypingsLocation string
4140 ParseCache * project.ParseCache
4241 NpmInstall func (cwd string , args []string ) ([]byte , error )
43-
44- // Test options
45- Client project.Client
46- Logger logging.Logger
4742}
4843
4944func NewServer (opts * ServerOptions ) * Server {
5045 if opts .Cwd == "" {
5146 panic ("Cwd is required" )
5247 }
53- var logger logging.Logger
54- if opts .Logger != nil {
55- logger = opts .Logger
56- } else {
57- logger = logging .NewLogger (opts .Err )
58- }
59- return & Server {
48+
49+ s := & Server {
6050 r : opts .In ,
6151 w : opts .Out ,
6252 stderr : opts .Err ,
63- logger : logger ,
6453 requestQueue : make (chan * lsproto.RequestMessage , 100 ),
6554 outgoingQueue : make (chan * lsproto.Message , 100 ),
6655 pendingClientRequests : make (map [lsproto.ID ]pendingClientRequest ),
@@ -71,9 +60,11 @@ func NewServer(opts *ServerOptions) *Server {
7160 typingsLocation : opts .TypingsLocation ,
7261 parseCache : opts .ParseCache ,
7362 npmInstall : opts .NpmInstall ,
74- client : opts .Client ,
7563 initComplete : make (chan struct {}),
7664 }
65+ s .logger = newLogger (s )
66+
67+ return s
7768}
7869
7970var (
@@ -143,7 +134,8 @@ type Server struct {
143134
144135 stderr io.Writer
145136
146- logger logging.Logger
137+ logger * logger
138+ initStarted atomic.Bool
147139 clientSeq atomic.Int32
148140 requestQueue chan * lsproto.RequestMessage
149141 outgoingQueue chan * lsproto.Message
@@ -293,7 +285,7 @@ func (s *Server) RequestConfiguration(ctx context.Context) (*lsutil.UserPreferen
293285 if err != nil {
294286 return nil , fmt .Errorf ("configure request failed: %w" , err )
295287 }
296- s .Log ( fmt . Sprintf ( " \n \n configuration : %+v, %T\n \n " , configs , configs ) )
288+ s .logger . Infof ( "configuration : %+v, %T" , configs , configs )
297289 userPreferences := s .session .NewUserPreferences ()
298290 for _ , item := range configs {
299291 if parsed := userPreferences .Parse (item ); parsed != nil {
@@ -508,7 +500,7 @@ func (s *Server) handleRequestOrNotification(ctx context.Context, req *lsproto.R
508500 if handler := handlers ()[req .Method ]; handler != nil {
509501 return handler (s , ctx , req )
510502 }
511- s .Log ("unknown method" , req .Method )
503+ s .logger . Warn ("unknown method" , req .Method )
512504 if req .ID != nil {
513505 s .sendError (req .ID , lsproto .ErrorCodeInvalidRequest )
514506 }
@@ -701,11 +693,11 @@ func (c *crossProjectOrchestrator) RecoverWith(r any) {
701693
702694func (s * Server ) recoverWith (req * lsproto.RequestMessage , r any ) {
703695 stack := debug .Stack ()
704- s .Log ("panic handling request" , req .Method , r , string (stack ))
696+ s .logger . Error ("panic handling request" , req .Method , r , string (stack ))
705697 if req .ID != nil {
706698 s .sendError (req .ID , fmt .Errorf ("%w: panic handling request %s: %v" , lsproto .ErrorCodeInternalError , req .Method , r ))
707699 } else {
708- s .Log ("unhandled panic in notification" , req .Method , r )
700+ s .logger . Error ("unhandled panic in notification" , req .Method , r )
709701 }
710702}
711703
@@ -720,15 +712,16 @@ func (s *Server) handleInitialize(ctx context.Context, params *lsproto.Initializ
720712 return nil , lsproto .ErrorCodeInvalidRequest
721713 }
722714
715+ s .initStarted .Store (true )
716+
723717 s .initializeParams = params
724- s .clientCapabilities = resolveClientCapabilities (params .Capabilities )
718+ s .clientCapabilities = lsproto . ResolveClientCapabilities (params .Capabilities )
725719
726- if _ , err := fmt .Fprint (s .stderr , "Resolved client capabilities: " ); err != nil {
727- return nil , err
728- }
729- if err := jsonutil .MarshalIndentWrite (s .stderr , & s .clientCapabilities , "" , "\t " ); err != nil {
720+ capabilitiesJSON , err := jsonutil .MarshalIndent (& s .clientCapabilities , "" , "\t " )
721+ if err != nil {
730722 return nil , err
731723 }
724+ s .logger .Info ("Resolved client capabilities: " + string (capabilitiesJSON ))
732725
733726 s .positionEncoding = lsproto .PositionEncodingKindUTF16
734727 if slices .Contains (s .clientCapabilities .General .PositionEncodings , lsproto .PositionEncodingKindUTF8 ) {
@@ -1160,10 +1153,6 @@ func (s *Server) handleCallHierarchyOutgoingCalls(
11601153 return languageService .ProvideCallHierarchyOutgoingCalls (ctx , params .Item )
11611154}
11621155
1163- func (s * Server ) Log (msg ... any ) {
1164- fmt .Fprintln (s .stderr , msg ... )
1165- }
1166-
11671156// !!! temporary; remove when we have `handleDidChangeConfiguration`/implicit project config support
11681157func (s * Server ) SetCompilerOptionsForInferredProjects (ctx context.Context , options * core.CompilerOptions ) {
11691158 s .compilerOptionsForInferredProjects = options
@@ -1196,29 +1185,3 @@ func isBlockingMethod(method lsproto.Method) bool {
11961185func ptrTo [T any ](v T ) * T {
11971186 return & v
11981187}
1199-
1200- func resolveClientCapabilities (caps * lsproto.ClientCapabilities ) lsproto.ResolvedClientCapabilities {
1201- resolved := lsproto .ResolveClientCapabilities (caps )
1202-
1203- // Some clients claim that push and pull diagnostics have different capabilities,
1204- // including vscode-languageclient v9. Work around this by defaulting any missing
1205- // pull diagnostic caps with the pull diagnostic equivalents.
1206- //
1207- // TODO: remove when we upgrade to vscode-languageclient v10, which fixes this issue.
1208- publish := resolved .TextDocument .PublishDiagnostics
1209- diagnostic := & resolved .TextDocument .Diagnostic
1210- if ! diagnostic .RelatedInformation && publish .RelatedInformation {
1211- diagnostic .RelatedInformation = true
1212- }
1213- if ! diagnostic .CodeDescriptionSupport && publish .CodeDescriptionSupport {
1214- diagnostic .CodeDescriptionSupport = true
1215- }
1216- if ! diagnostic .DataSupport && publish .DataSupport {
1217- diagnostic .DataSupport = true
1218- }
1219- if len (diagnostic .TagSupport .ValueSet ) == 0 && len (publish .TagSupport .ValueSet ) > 0 {
1220- diagnostic .TagSupport .ValueSet = publish .TagSupport .ValueSet
1221- }
1222-
1223- return resolved
1224- }
0 commit comments