@@ -247,7 +247,6 @@ func (s *GwirlLspServer) Handle() {
247
247
case lsp .MethodTextDocumentHover :
248
248
go handleRequest [lsp.HoverParams , * lsp.Hover ](s , method , s .Hover , s .context , bytes )
249
249
default :
250
- s .logf ("Not handling method \" %s\" " , method )
251
250
}
252
251
}
253
252
}
@@ -514,27 +513,12 @@ func (s *GwirlLspServer) DidChange(ctx context.Context, params *lsp.DidChangeTex
514
513
515
514
res := s .parser .Parse (s .fileContents [params .TextDocument .URI ], params .TextDocument .URI .Filename ())
516
515
517
- diagnostics := make ([]lsp.Diagnostic , len (res .Errors ), len (res .Errors ))
518
- for i , e := range res .Errors {
519
- s .logf ("error: %v" , e )
520
- line := uint32 (e .Line ())
521
- column := uint32 (e .Column ())
522
- d := lsp.Diagnostic {
523
- Range : lsp.Range {
524
- Start : lsp.Position {Line : line , Character : column },
525
- End : lsp.Position {Line : line , Character : column },
526
- },
527
- Severity : lsp .DiagnosticSeverityError ,
528
- Source : "gwirl-lsp" ,
529
- Message : e .String (),
530
- }
531
- diagnostics [i ] = d
532
- }
516
+ diagnostics := createDiagnosticsFromErrors (res .Errors )
533
517
534
- s .sendNotification ("textDocument/publishDiagnostics" , lsp.PublishDiagnosticsParams {
535
- Diagnostics : diagnostics ,
536
- URI : params .TextDocument .URI ,
537
- })
518
+ s .sendNotification ("textDocument/publishDiagnostics" , lsp.PublishDiagnosticsParams {
519
+ Diagnostics : diagnostics ,
520
+ URI : params .TextDocument .URI ,
521
+ })
538
522
539
523
return nil
540
524
}
@@ -562,21 +546,7 @@ func (s *GwirlLspServer) DidOpen(ctx context.Context, params *lsp.DidOpenTextDoc
562
546
563
547
res := s .parser .Parse (params .TextDocument .Text , params .TextDocument .URI .Filename ())
564
548
565
- diagnostics := make ([]lsp.Diagnostic , len (res .Errors ), len (res .Errors ))
566
- for i , e := range res .Errors {
567
- line := uint32 (e .Line ())
568
- column := uint32 (e .Column ())
569
- d := lsp.Diagnostic {
570
- Range : lsp.Range {
571
- Start : lsp.Position {Line : line , Character : column },
572
- End : lsp.Position {Line : line , Character : column },
573
- },
574
- Severity : lsp .DiagnosticSeverityError ,
575
- Source : "gwirl-lsp" ,
576
- Message : e .String (),
577
- }
578
- diagnostics [i ] = d
579
- }
549
+ diagnostics := createDiagnosticsFromErrors (res .Errors )
580
550
581
551
s .sendNotification ("textDocument/publishDiagnostics" , lsp.PublishDiagnosticsParams {
582
552
Diagnostics : diagnostics ,
@@ -725,3 +695,20 @@ func (s *GwirlLspServer) Moniker(ctx context.Context, params *lsp.MonikerParams)
725
695
func (s * GwirlLspServer ) Request (ctx context.Context , method string , params interface {}) (result interface {}, err error ) {
726
696
return nil , nil
727
697
}
698
+
699
+ func createDiagnosticsFromErrors (errors []parser.ParseError ) []lsp.Diagnostic {
700
+ diagnostics := make ([]lsp.Diagnostic , len (errors ), len (errors ))
701
+ for i , e := range errors {
702
+ d := lsp.Diagnostic {
703
+ Range : lsp.Range {
704
+ Start : ParserPosToLspPos (e .Start ),
705
+ End : ParserPosToLspPos (e .End ),
706
+ },
707
+ Severity : lsp .DiagnosticSeverityError ,
708
+ Source : "gwirl-lsp" ,
709
+ Message : e .Err ,
710
+ }
711
+ diagnostics [i ] = d
712
+ }
713
+ return diagnostics
714
+ }
0 commit comments