@@ -155,6 +155,7 @@ func NewINOLanguageServer(stdin io.Reader, stdout io.Writer, config *Config) *IN
155
155
return ls
156
156
}
157
157
158
+ // InitializeReqFromIDE initializes a new request from the IDE
158
159
func (ls * INOLanguageServer ) InitializeReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.InitializeParams ) (* lsp.InitializeResult , * jsonrpc.ResponseError ) {
159
160
ls .writeLock (logger , false )
160
161
ls .sketchRoot = ideParams .RootURI .AsPath ()
@@ -363,6 +364,7 @@ func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger js
363
364
return resp , nil
364
365
}
365
366
367
+ // ShutdownReqFromIDE executes a shutdown request from the IDE
366
368
func (ls * INOLanguageServer ) ShutdownReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger ) * jsonrpc.ResponseError {
367
369
done := make (chan bool )
368
370
go func () {
@@ -374,6 +376,7 @@ func (ls *INOLanguageServer) ShutdownReqFromIDE(ctx context.Context, logger json
374
376
return nil
375
377
}
376
378
379
+ // TextDocumentCompletionReqFromIDE handles a text document completion request received from the IDE
377
380
func (ls * INOLanguageServer ) TextDocumentCompletionReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.CompletionParams ) (* lsp.CompletionList , * jsonrpc.ResponseError ) {
378
381
ls .readLock (logger , true )
379
382
defer ls .readUnlock (logger )
@@ -468,6 +471,7 @@ func (ls *INOLanguageServer) TextDocumentCompletionReqFromIDE(ctx context.Contex
468
471
return ideCompletionList , nil
469
472
}
470
473
474
+ // TextDocumentHoverReqFromIDE handles a text document hover request received from the IDE
471
475
func (ls * INOLanguageServer ) TextDocumentHoverReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.HoverParams ) (* lsp.Hover , * jsonrpc.ResponseError ) {
472
476
ls .readLock (logger , true )
473
477
defer ls .readUnlock (logger )
@@ -519,6 +523,7 @@ func (ls *INOLanguageServer) TextDocumentHoverReqFromIDE(ctx context.Context, lo
519
523
return & ideResp , nil
520
524
}
521
525
526
+ // TextDocumentSignatureHelpReqFromIDE handles a text document signature help request received from the IDE
522
527
func (ls * INOLanguageServer ) TextDocumentSignatureHelpReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.SignatureHelpParams ) (* lsp.SignatureHelp , * jsonrpc.ResponseError ) {
523
528
ls .readLock (logger , true )
524
529
defer ls .readUnlock (logger )
@@ -550,6 +555,7 @@ func (ls *INOLanguageServer) TextDocumentSignatureHelpReqFromIDE(ctx context.Con
550
555
return ideSignatureHelp , nil
551
556
}
552
557
558
+ // TextDocumentDefinitionReqFromIDE handles a text document definition request received from the IDE
553
559
func (ls * INOLanguageServer ) TextDocumentDefinitionReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.DefinitionParams ) ([]lsp.Location , []lsp.LocationLink , * jsonrpc.ResponseError ) {
554
560
ls .readLock (logger , true )
555
561
defer ls .readUnlock (logger )
@@ -594,6 +600,7 @@ func (ls *INOLanguageServer) TextDocumentDefinitionReqFromIDE(ctx context.Contex
594
600
return ideLocations , ideLocationLinks , nil
595
601
}
596
602
603
+ // TextDocumentTypeDefinitionReqFromIDE handles a text document type definition request received from the IDE
597
604
func (ls * INOLanguageServer ) TextDocumentTypeDefinitionReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.TypeDefinitionParams ) ([]lsp.Location , []lsp.LocationLink , * jsonrpc.ResponseError ) {
598
605
// XXX: This capability is not advertised in the initialization message (clangd
599
606
// does not advertise it either, so maybe we should just not implement it)
@@ -640,6 +647,7 @@ func (ls *INOLanguageServer) TextDocumentTypeDefinitionReqFromIDE(ctx context.Co
640
647
return ideLocations , ideLocationLinks , nil
641
648
}
642
649
650
+ // TextDocumentImplementationReqFromIDE handles a text document implementation request received from the IDE
643
651
func (ls * INOLanguageServer ) TextDocumentImplementationReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.ImplementationParams ) ([]lsp.Location , []lsp.LocationLink , * jsonrpc.ResponseError ) {
644
652
ls .readLock (logger , true )
645
653
defer ls .readUnlock (logger )
@@ -684,6 +692,7 @@ func (ls *INOLanguageServer) TextDocumentImplementationReqFromIDE(ctx context.Co
684
692
return ideLocations , inoLocationLinks , nil
685
693
}
686
694
695
+ // TextDocumentDocumentHighlightReqFromIDE handles a text document highlight request received from the IDE
687
696
func (ls * INOLanguageServer ) TextDocumentDocumentHighlightReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.DocumentHighlightParams ) ([]lsp.DocumentHighlight , * jsonrpc.ResponseError ) {
688
697
ls .readLock (logger , true )
689
698
defer ls .readUnlock (logger )
@@ -731,6 +740,7 @@ func (ls *INOLanguageServer) TextDocumentDocumentHighlightReqFromIDE(ctx context
731
740
return ideHighlights , nil
732
741
}
733
742
743
+ // TextDocumentDocumentSymbolReqFromIDE handles a text document symbol request received from the IDE
734
744
func (ls * INOLanguageServer ) TextDocumentDocumentSymbolReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.DocumentSymbolParams ) ([]lsp.DocumentSymbol , []lsp.SymbolInformation , * jsonrpc.ResponseError ) {
735
745
ls .readLock (logger , true )
736
746
defer ls .readUnlock (logger )
@@ -762,13 +772,13 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
762
772
// Convert response for IDE
763
773
var ideDocSymbols []lsp.DocumentSymbol
764
774
if clangDocSymbols != nil {
765
- if s , err := ls .clang2IdeDocumentSymbols (logger , clangDocSymbols , clangParams .TextDocument .URI , ideParams .TextDocument .URI ); err != nil {
775
+ s , err := ls .clang2IdeDocumentSymbols (logger , clangDocSymbols , clangParams .TextDocument .URI , ideParams .TextDocument .URI )
776
+ if err != nil {
766
777
logger .Logf ("Error: %s" , err )
767
778
ls .Close ()
768
779
return nil , nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : err .Error ()}
769
- } else {
770
- ideDocSymbols = s
771
780
}
781
+ ideDocSymbols = s
772
782
}
773
783
var ideSymbolsInformation []lsp.SymbolInformation
774
784
if clangSymbolsInformation != nil {
@@ -777,6 +787,7 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
777
787
return ideDocSymbols , ideSymbolsInformation , nil
778
788
}
779
789
790
+ // TextDocumentCodeActionReqFromIDE handles a text document code action request received from the IDE
780
791
func (ls * INOLanguageServer ) TextDocumentCodeActionReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.CodeActionParams ) ([]lsp.CommandOrCodeAction , * jsonrpc.ResponseError ) {
781
792
ls .readLock (logger , true )
782
793
defer ls .readUnlock (logger )
@@ -846,6 +857,7 @@ func (ls *INOLanguageServer) TextDocumentCodeActionReqFromIDE(ctx context.Contex
846
857
return ideCommandsOrCodeActions , nil
847
858
}
848
859
860
+ // TextDocumentFormattingReqFromIDE handles a text document formatting request received from the IDE
849
861
func (ls * INOLanguageServer ) TextDocumentFormattingReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.DocumentFormattingParams ) ([]lsp.TextEdit , * jsonrpc.ResponseError ) {
850
862
ls .writeLock (logger , true )
851
863
defer ls .writeUnlock (logger )
@@ -860,12 +872,12 @@ func (ls *INOLanguageServer) TextDocumentFormattingReqFromIDE(ctx context.Contex
860
872
}
861
873
clangURI := clangTextDocument .URI
862
874
863
- if cleanup , err := ls .createClangdFormatterConfig (logger , clangURI ); err != nil {
875
+ cleanup , err := ls .createClangdFormatterConfig (logger , clangURI )
876
+ if err != nil {
864
877
logger .Logf ("Error: %s" , err )
865
878
return nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : err .Error ()}
866
- } else {
867
- defer cleanup ()
868
879
}
880
+ defer cleanup ()
869
881
870
882
clangParams := & lsp.DocumentFormattingParams {
871
883
WorkDoneProgressParams : ideParams .WorkDoneProgressParams ,
@@ -894,13 +906,14 @@ func (ls *INOLanguageServer) TextDocumentFormattingReqFromIDE(ctx context.Contex
894
906
}
895
907
896
908
// Edits may span over multiple .ino files, filter only the edits relative to the currently displayed file
897
- if inoEdits , ok := ideEdits [ideURI ]; ! ok {
909
+ inoEdits , ok := ideEdits [ideURI ]
910
+ if ! ok {
898
911
return []lsp.TextEdit {}, nil
899
- } else {
900
- return inoEdits , nil
901
912
}
913
+ return inoEdits , nil
902
914
}
903
915
916
+ // TextDocumentRangeFormattingReqFromIDE handles a text document range formatting request received from the IDE
904
917
func (ls * INOLanguageServer ) TextDocumentRangeFormattingReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.DocumentRangeFormattingParams ) ([]lsp.TextEdit , * jsonrpc.ResponseError ) {
905
918
ls .writeLock (logger , true )
906
919
defer ls .writeUnlock (logger )
@@ -918,12 +931,12 @@ func (ls *INOLanguageServer) TextDocumentRangeFormattingReqFromIDE(ctx context.C
918
931
Range : clangRange ,
919
932
}
920
933
921
- if cleanup , e := ls .createClangdFormatterConfig (logger , clangURI ); e != nil {
934
+ cleanup , e := ls .createClangdFormatterConfig (logger , clangURI )
935
+ if e != nil {
922
936
logger .Logf ("cannot create formatter config file: %v" , err )
923
937
return nil , & jsonrpc.ResponseError {Code : jsonrpc .ErrorCodesInternalError , Message : err .Error ()}
924
- } else {
925
- defer cleanup ()
926
938
}
939
+ defer cleanup ()
927
940
928
941
clangEdits , clangErr , err := ls .Clangd .conn .TextDocumentRangeFormatting (ctx , clangParams )
929
942
if err != nil {
@@ -947,23 +960,26 @@ func (ls *INOLanguageServer) TextDocumentRangeFormattingReqFromIDE(ctx context.C
947
960
}
948
961
949
962
// Edits may span over multiple .ino files, filter only the edits relative to the currently displayed file
950
- if inoEdits , ok := sketchEdits [ideURI ]; ! ok {
963
+ inoEdits , ok := sketchEdits [ideURI ]
964
+ if ! ok {
951
965
return []lsp.TextEdit {}, nil
952
- } else {
953
- return inoEdits , nil
954
966
}
967
+ return inoEdits , nil
955
968
}
956
969
970
+ // InitializedNotifFromIDE initializes a notification from the IDE
957
971
func (ls * INOLanguageServer ) InitializedNotifFromIDE (logger jsonrpc.FunctionLogger , ideParams * lsp.InitializedParams ) {
958
972
logger .Logf ("Notification is not propagated to clangd" )
959
973
}
960
974
975
+ // ExitNotifFromIDE logs an exit notification from the IDE
961
976
func (ls * INOLanguageServer ) ExitNotifFromIDE (logger jsonrpc.FunctionLogger ) {
962
977
ls .Clangd .conn .Exit ()
963
978
logger .Logf ("Arduino Language Server is shutting down." )
964
979
os .Exit (0 )
965
980
}
966
981
982
+ // TextDocumentDidOpenNotifFromIDE handles a notification from the IDE that TextDocument is open
967
983
func (ls * INOLanguageServer ) TextDocumentDidOpenNotifFromIDE (logger jsonrpc.FunctionLogger , ideParam * lsp.DidOpenTextDocumentParams ) {
968
984
ls .writeLock (logger , true )
969
985
defer ls .writeUnlock (logger )
@@ -1023,6 +1039,7 @@ func (ls *INOLanguageServer) TextDocumentDidOpenNotifFromIDE(logger jsonrpc.Func
1023
1039
}
1024
1040
}
1025
1041
1042
+ // TextDocumentDidChangeNotifFromIDE handles a notification from the IDE that TextDocument changed
1026
1043
func (ls * INOLanguageServer ) TextDocumentDidChangeNotifFromIDE (logger jsonrpc.FunctionLogger , ideParams * lsp.DidChangeTextDocumentParams ) {
1027
1044
ls .writeLock (logger , true )
1028
1045
defer ls .writeUnlock (logger )
@@ -1119,6 +1136,7 @@ func (ls *INOLanguageServer) TextDocumentDidChangeNotifFromIDE(logger jsonrpc.Fu
1119
1136
}
1120
1137
}
1121
1138
1139
+ // TextDocumentDidSaveNotifFromIDE handles a notification from the IDE that TextDocument has been saved
1122
1140
func (ls * INOLanguageServer ) TextDocumentDidSaveNotifFromIDE (logger jsonrpc.FunctionLogger , ideParams * lsp.DidSaveTextDocumentParams ) {
1123
1141
ls .writeLock (logger , true )
1124
1142
defer ls .writeUnlock (logger )
@@ -1130,6 +1148,7 @@ func (ls *INOLanguageServer) TextDocumentDidSaveNotifFromIDE(logger jsonrpc.Func
1130
1148
ls .triggerRebuild ()
1131
1149
}
1132
1150
1151
+ // TextDocumentDidCloseNotifFromIDE handles a notification from the IDE that TextDocument has been closed
1133
1152
func (ls * INOLanguageServer ) TextDocumentDidCloseNotifFromIDE (logger jsonrpc.FunctionLogger , ideParams * lsp.DidCloseTextDocumentParams ) {
1134
1153
ls .writeLock (logger , true )
1135
1154
defer ls .writeUnlock (logger )
@@ -1173,14 +1192,16 @@ func (ls *INOLanguageServer) TextDocumentDidCloseNotifFromIDE(logger jsonrpc.Fun
1173
1192
}
1174
1193
}
1175
1194
1195
+ // FullBuildCompletedFromIDE receives a full build from the IDE and copies the results
1176
1196
func (ls * INOLanguageServer ) FullBuildCompletedFromIDE (logger jsonrpc.FunctionLogger , params * DidCompleteBuildParams ) {
1177
1197
ls .writeLock (logger , true )
1178
1198
defer ls .writeUnlock (logger )
1179
1199
1180
- ls .CopyFullBuildResults (logger , params .BuildOutputUri .AsPath ())
1200
+ ls .CopyFullBuildResults (logger , params .BuildOutputURI .AsPath ())
1181
1201
ls .triggerRebuild ()
1182
1202
}
1183
1203
1204
+ // CopyFullBuildResults copies the results of a full build
1184
1205
func (ls * INOLanguageServer ) CopyFullBuildResults (logger jsonrpc.FunctionLogger , buildPath * paths.Path ) {
1185
1206
fromCache := buildPath .Join ("libraries.cache" )
1186
1207
toCache := ls .buildPath .Join ("libraries.cache" )
@@ -1191,6 +1212,7 @@ func (ls *INOLanguageServer) CopyFullBuildResults(logger jsonrpc.FunctionLogger,
1191
1212
}
1192
1213
}
1193
1214
1215
+ // PublishDiagnosticsNotifFromClangd publishes a diagnostics if notified from Clangd
1194
1216
func (ls * INOLanguageServer ) PublishDiagnosticsNotifFromClangd (logger jsonrpc.FunctionLogger , clangParams * lsp.PublishDiagnosticsParams ) {
1195
1217
if ls .config .DisableRealTimeDiagnostics {
1196
1218
logger .Logf ("Ignored by configuration" )
@@ -1271,6 +1293,7 @@ func (ls *INOLanguageServer) PublishDiagnosticsNotifFromClangd(logger jsonrpc.Fu
1271
1293
}
1272
1294
}
1273
1295
1296
+ // TextDocumentRenameReqFromIDE handles a request from the IDE to rename TextDocument
1274
1297
func (ls * INOLanguageServer ) TextDocumentRenameReqFromIDE (ctx context.Context , logger jsonrpc.FunctionLogger , ideParams * lsp.RenameParams ) (* lsp.WorkspaceEdit , * jsonrpc.ResponseError ) {
1275
1298
ls .writeLock (logger , false )
1276
1299
defer ls .writeUnlock (logger )
@@ -1348,6 +1371,7 @@ func (ls *INOLanguageServer) WindowWorkDoneProgressCreateReqFromClangd(ctx conte
1348
1371
return nil
1349
1372
}
1350
1373
1374
+ // SetTraceNotifFromIDE gets a notification from the IDE to Set Trace to parameters
1351
1375
func (ls * INOLanguageServer ) SetTraceNotifFromIDE (logger jsonrpc.FunctionLogger , params * lsp.SetTraceParams ) {
1352
1376
logger .Logf ("Notification level set to: %s" , params .Value )
1353
1377
ls .Clangd .conn .SetTrace (params )
0 commit comments