@@ -24,7 +24,6 @@ import (
2424 "github.com/microsoft/typescript-go/internal/lsp/lsproto"
2525 "github.com/microsoft/typescript-go/internal/project"
2626 "github.com/microsoft/typescript-go/internal/project/ata"
27- "github.com/microsoft/typescript-go/internal/project/logging"
2827 "github.com/microsoft/typescript-go/internal/tspath"
2928 "github.com/microsoft/typescript-go/internal/vfs"
3029 "golang.org/x/sync/errgroup"
@@ -41,27 +40,17 @@ type ServerOptions struct {
4140 TypingsLocation string
4241 ParseCache * project.ParseCache
4342 NpmInstall func (cwd string , args []string ) ([]byte , error )
44-
45- // Test options
46- Client project.Client
47- Logger logging.Logger
4843}
4944
5045func NewServer (opts * ServerOptions ) * Server {
5146 if opts .Cwd == "" {
5247 panic ("Cwd is required" )
5348 }
54- var logger logging.Logger
55- if opts .Logger != nil {
56- logger = opts .Logger
57- } else {
58- logger = logging .NewLogger (opts .Err )
59- }
60- return & Server {
49+
50+ s := & Server {
6151 r : opts .In ,
6252 w : opts .Out ,
6353 stderr : opts .Err ,
64- logger : logger ,
6554 requestQueue : make (chan * lsproto.RequestMessage , 100 ),
6655 outgoingQueue : make (chan * lsproto.Message , 100 ),
6756 pendingClientRequests : make (map [lsproto.ID ]pendingClientRequest ),
@@ -72,9 +61,11 @@ func NewServer(opts *ServerOptions) *Server {
7261 typingsLocation : opts .TypingsLocation ,
7362 parseCache : opts .ParseCache ,
7463 npmInstall : opts .NpmInstall ,
75- client : opts .Client ,
7664 initComplete : make (chan struct {}),
7765 }
66+ s .logger = newLogger (s )
67+
68+ return s
7869}
7970
8071var (
@@ -144,7 +135,8 @@ type Server struct {
144135
145136 stderr io.Writer
146137
147- logger logging.Logger
138+ logger * logger
139+ initStarted atomic.Bool
148140 clientSeq atomic.Int32
149141 requestQueue chan * lsproto.RequestMessage
150142 outgoingQueue chan * lsproto.Message
@@ -294,7 +286,7 @@ func (s *Server) RequestConfiguration(ctx context.Context) (*lsutil.UserPreferen
294286 if err != nil {
295287 return nil , fmt .Errorf ("configure request failed: %w" , err )
296288 }
297- s .Log ( fmt . Sprintf ( " \n \n configuration : %+v, %T\n \n " , configs , configs ) )
289+ s .logger . Infof ( "configuration : %+v, %T" , configs , configs )
298290 userPreferences := s .session .NewUserPreferences ()
299291 for _ , item := range configs {
300292 if parsed := userPreferences .Parse (item ); parsed != nil {
@@ -509,7 +501,7 @@ func (s *Server) handleRequestOrNotification(ctx context.Context, req *lsproto.R
509501 if handler := handlers ()[req .Method ]; handler != nil {
510502 return handler (s , ctx , req )
511503 }
512- s .Log ("unknown method" , req .Method )
504+ s .logger . Warn ("unknown method" , req .Method )
513505 if req .ID != nil {
514506 s .sendError (req .ID , lsproto .ErrorCodeInvalidRequest )
515507 }
@@ -878,11 +870,11 @@ func registerMultiProjectReferenceRequestHandler[Req lsproto.HasTextDocumentPosi
878870func (s * Server ) recover (req * lsproto.RequestMessage ) {
879871 if r := recover (); r != nil {
880872 stack := debug .Stack ()
881- s .Log ("panic handling request" , req .Method , r , string (stack ))
873+ s .logger . Error ("panic handling request" , req .Method , r , string (stack ))
882874 if req .ID != nil {
883875 s .sendError (req .ID , fmt .Errorf ("%w: panic handling request %s: %v" , lsproto .ErrorCodeInternalError , req .Method , r ))
884876 } else {
885- s .Log ("unhandled panic in notification" , req .Method , r )
877+ s .logger . Error ("unhandled panic in notification" , req .Method , r )
886878 }
887879 }
888880}
@@ -892,15 +884,16 @@ func (s *Server) handleInitialize(ctx context.Context, params *lsproto.Initializ
892884 return nil , lsproto .ErrorCodeInvalidRequest
893885 }
894886
887+ s .initStarted .Store (true )
888+
895889 s .initializeParams = params
896- s .clientCapabilities = resolveClientCapabilities (params .Capabilities )
890+ s .clientCapabilities = lsproto . ResolveClientCapabilities (params .Capabilities )
897891
898- if _ , err := fmt .Fprint (s .stderr , "Resolved client capabilities: " ); err != nil {
899- return nil , err
900- }
901- if err := jsonutil .MarshalIndentWrite (s .stderr , & s .clientCapabilities , "" , "\t " ); err != nil {
892+ capabilitiesJSON , err := jsonutil .MarshalIndent (& s .clientCapabilities , "" , "\t " )
893+ if err != nil {
902894 return nil , err
903895 }
896+ s .logger .Info ("Resolved client capabilities: " + string (capabilitiesJSON ))
904897
905898 s .positionEncoding = lsproto .PositionEncodingKindUTF16
906899 if slices .Contains (s .clientCapabilities .General .PositionEncodings , lsproto .PositionEncodingKindUTF8 ) {
@@ -1387,10 +1380,6 @@ func (s *Server) handleCallHierarchyOutgoingCalls(
13871380 return languageService .ProvideCallHierarchyOutgoingCalls (ctx , params .Item )
13881381}
13891382
1390- func (s * Server ) Log (msg ... any ) {
1391- fmt .Fprintln (s .stderr , msg ... )
1392- }
1393-
13941383// !!! temporary; remove when we have `handleDidChangeConfiguration`/implicit project config support
13951384func (s * Server ) SetCompilerOptionsForInferredProjects (ctx context.Context , options * core.CompilerOptions ) {
13961385 s .compilerOptionsForInferredProjects = options
@@ -1423,29 +1412,3 @@ func isBlockingMethod(method lsproto.Method) bool {
14231412func ptrTo [T any ](v T ) * T {
14241413 return & v
14251414}
1426-
1427- func resolveClientCapabilities (caps * lsproto.ClientCapabilities ) lsproto.ResolvedClientCapabilities {
1428- resolved := lsproto .ResolveClientCapabilities (caps )
1429-
1430- // Some clients claim that push and pull diagnostics have different capabilities,
1431- // including vscode-languageclient v9. Work around this by defaulting any missing
1432- // pull diagnostic caps with the pull diagnostic equivalents.
1433- //
1434- // TODO: remove when we upgrade to vscode-languageclient v10, which fixes this issue.
1435- publish := resolved .TextDocument .PublishDiagnostics
1436- diagnostic := & resolved .TextDocument .Diagnostic
1437- if ! diagnostic .RelatedInformation && publish .RelatedInformation {
1438- diagnostic .RelatedInformation = true
1439- }
1440- if ! diagnostic .CodeDescriptionSupport && publish .CodeDescriptionSupport {
1441- diagnostic .CodeDescriptionSupport = true
1442- }
1443- if ! diagnostic .DataSupport && publish .DataSupport {
1444- diagnostic .DataSupport = true
1445- }
1446- if len (diagnostic .TagSupport .ValueSet ) == 0 && len (publish .TagSupport .ValueSet ) > 0 {
1447- diagnostic .TagSupport .ValueSet = publish .TagSupport .ValueSet
1448- }
1449-
1450- return resolved
1451- }
0 commit comments