@@ -480,10 +480,8 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) {
480
480
break
481
481
}
482
482
483
- input := FindInput (
484
- uri .ToPath (l .clientIdentifier , file ),
485
- uri .ToPath (l .clientIdentifier , l .workspaceRootURI ),
486
- )
483
+ workspacePath := uri .ToPath (l .clientIdentifier , l .workspaceRootURI )
484
+ input := FindInput (uri .ToPath (l .clientIdentifier , file ), workspacePath )
487
485
488
486
result , err := l .EvalWorkspacePath (ctx , path , input )
489
487
if err != nil {
@@ -492,16 +490,43 @@ func (l *LanguageServer) StartCommandWorker(ctx context.Context) {
492
490
break
493
491
}
494
492
495
- responseParams := map [string ]any {
496
- "result" : result ,
497
- "line" : line ,
498
- }
493
+ if l .clientIdentifier == clients .IdentifierVSCode {
494
+ responseParams := map [string ]any {
495
+ "result" : result ,
496
+ "line" : line ,
497
+ }
499
498
500
- responseResult := map [string ]any {}
499
+ responseResult := map [string ]any {}
501
500
502
- err = l .conn .Call (ctx , "regal/showEvalResult" , responseParams , & responseResult )
503
- if err != nil {
504
- l .logError (fmt .Errorf ("failed %s notify: %v" , "regal/hello" , err .Error ()))
501
+ err = l .conn .Call (ctx , "regal/showEvalResult" , responseParams , & responseResult )
502
+ if err != nil {
503
+ l .logError (fmt .Errorf ("failed %s notify: %v" , "regal/hello" , err .Error ()))
504
+ }
505
+ } else {
506
+ output := filepath .Join (workspacePath , "output.json" )
507
+
508
+ var f * os.File
509
+
510
+ f , err = os .OpenFile (output , os .O_CREATE | os .O_TRUNC | os .O_WRONLY , 0o755 )
511
+
512
+ if err == nil {
513
+ var jsonVal []byte
514
+
515
+ value := result .Value
516
+ if result .IsUndefined {
517
+ // Display undefined as an empty object
518
+ // we could also go with "<undefined>" or similar
519
+ value = make (map [string ]any )
520
+ }
521
+
522
+ jsonVal , err = json .MarshalIndent (value , "" , " " )
523
+ if err == nil {
524
+ // staticcheck thinks err here is never used, but I think that's false?
525
+ _ , err = f .Write (jsonVal ) //nolint:staticcheck
526
+ }
527
+
528
+ f .Close ()
529
+ }
505
530
}
506
531
}
507
532
@@ -1000,13 +1025,6 @@ func (l *LanguageServer) handleTextDocumentCodeLens(
1000
1025
return nil , fmt .Errorf ("failed to unmarshal params: %w" , err )
1001
1026
}
1002
1027
1003
- if l .clientIdentifier != clients .IdentifierVSCode {
1004
- // only VSCode has the client side capability to handle the callback request
1005
- // to handle the result of evaluation, so displaying code lenses for any other
1006
- // editor is likely just going to result in a bad experience
1007
- return nil , nil // return a null response, as per the spec
1008
- }
1009
-
1010
1028
module , ok := l .cache .GetModule (params .TextDocument .URI )
1011
1029
if ! ok {
1012
1030
l .logError (fmt .Errorf ("failed to get module for uri %q" , params .TextDocument .URI ))
@@ -1736,16 +1754,10 @@ func (l *LanguageServer) handleInitialize(
1736
1754
LabelDetailsSupport : true ,
1737
1755
},
1738
1756
},
1757
+ CodeLensProvider : & types.CodeLensOptions {},
1739
1758
},
1740
1759
}
1741
1760
1742
- // Since evaluation requires some client side handling, this can't be supported
1743
- // purely by the LSP. Clients that are capable of handling the code lens callback
1744
- // should be added here though.
1745
- if l .clientIdentifier == clients .IdentifierVSCode {
1746
- initializeResult .Capabilities .CodeLensProvider = & types.CodeLensOptions {}
1747
- }
1748
-
1749
1761
if l .workspaceRootURI != "" {
1750
1762
configFile , err := config .FindConfig (uri .ToPath (l .clientIdentifier , l .workspaceRootURI ))
1751
1763
if err == nil {
0 commit comments