Skip to content

Commit ce57032

Browse files
Fix formatting errors in go files
1 parent 983d069 commit ce57032

7 files changed

+166
-40
lines changed

Diff for: ls/builder.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type SketchRebuilder struct {
3232
mutex sync.Mutex
3333
}
3434

35+
// NewSketchBuilder makes a new SketchRebuilder and returns its pointer
3536
func NewSketchBuilder(ls *INOLanguageServer) *SketchRebuilder {
3637
res := &SketchRebuilder{
3738
trigger: make(chan chan<- bool, 1),
@@ -57,6 +58,7 @@ func (ls *INOLanguageServer) triggerRebuild() {
5758
ls.sketchRebuilder.TriggerRebuild(nil)
5859
}
5960

61+
// TriggerRebuild assigns completed to the trigger if ready
6062
func (r *SketchRebuilder) TriggerRebuild(completed chan<- bool) {
6163
r.mutex.Lock()
6264
defer r.mutex.Unlock()
@@ -207,8 +209,8 @@ func (ls *INOLanguageServer) generateBuildEnvironment(ctx context.Context, fullB
207209
Verbose: true,
208210
SkipLibrariesDiscovery: !fullBuild,
209211
}
210-
compileReqJson, _ := json.MarshalIndent(compileReq, "", " ")
211-
logger.Logf("Running build with: %s", string(compileReqJson))
212+
compileReqJSON, _ := json.MarshalIndent(compileReq, "", " ")
213+
logger.Logf("Running build with: %s", string(compileReqJSON))
212214

213215
compRespStream, err := client.Compile(context.Background(), compileReq)
214216
if err != nil {

Diff for: ls/ls.go

+40-16
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func NewINOLanguageServer(stdin io.Reader, stdout io.Writer, config *Config) *IN
155155
return ls
156156
}
157157

158+
// InitializeReqFromIDE initializes a new request from the IDE
158159
func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.InitializeParams) (*lsp.InitializeResult, *jsonrpc.ResponseError) {
159160
ls.writeLock(logger, false)
160161
ls.sketchRoot = ideParams.RootURI.AsPath()
@@ -363,6 +364,7 @@ func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger js
363364
return resp, nil
364365
}
365366

367+
// ShutdownReqFromIDE executes a shutdown request from the IDE
366368
func (ls *INOLanguageServer) ShutdownReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger) *jsonrpc.ResponseError {
367369
done := make(chan bool)
368370
go func() {
@@ -374,6 +376,7 @@ func (ls *INOLanguageServer) ShutdownReqFromIDE(ctx context.Context, logger json
374376
return nil
375377
}
376378

379+
// TextDocumentCompletionReqFromIDE handles a text document completion request received from the IDE
377380
func (ls *INOLanguageServer) TextDocumentCompletionReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.CompletionParams) (*lsp.CompletionList, *jsonrpc.ResponseError) {
378381
ls.readLock(logger, true)
379382
defer ls.readUnlock(logger)
@@ -468,6 +471,7 @@ func (ls *INOLanguageServer) TextDocumentCompletionReqFromIDE(ctx context.Contex
468471
return ideCompletionList, nil
469472
}
470473

474+
// TextDocumentHoverReqFromIDE handles a text document hover request received from the IDE
471475
func (ls *INOLanguageServer) TextDocumentHoverReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.HoverParams) (*lsp.Hover, *jsonrpc.ResponseError) {
472476
ls.readLock(logger, true)
473477
defer ls.readUnlock(logger)
@@ -519,6 +523,7 @@ func (ls *INOLanguageServer) TextDocumentHoverReqFromIDE(ctx context.Context, lo
519523
return &ideResp, nil
520524
}
521525

526+
// TextDocumentSignatureHelpReqFromIDE handles a text document signature help request received from the IDE
522527
func (ls *INOLanguageServer) TextDocumentSignatureHelpReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.SignatureHelpParams) (*lsp.SignatureHelp, *jsonrpc.ResponseError) {
523528
ls.readLock(logger, true)
524529
defer ls.readUnlock(logger)
@@ -550,6 +555,7 @@ func (ls *INOLanguageServer) TextDocumentSignatureHelpReqFromIDE(ctx context.Con
550555
return ideSignatureHelp, nil
551556
}
552557

558+
// TextDocumentDefinitionReqFromIDE handles a text document definition request received from the IDE
553559
func (ls *INOLanguageServer) TextDocumentDefinitionReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.DefinitionParams) ([]lsp.Location, []lsp.LocationLink, *jsonrpc.ResponseError) {
554560
ls.readLock(logger, true)
555561
defer ls.readUnlock(logger)
@@ -594,6 +600,7 @@ func (ls *INOLanguageServer) TextDocumentDefinitionReqFromIDE(ctx context.Contex
594600
return ideLocations, ideLocationLinks, nil
595601
}
596602

603+
// TextDocumentTypeDefinitionReqFromIDE handles a text document type definition request received from the IDE
597604
func (ls *INOLanguageServer) TextDocumentTypeDefinitionReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.TypeDefinitionParams) ([]lsp.Location, []lsp.LocationLink, *jsonrpc.ResponseError) {
598605
// XXX: This capability is not advertised in the initialization message (clangd
599606
// does not advertise it either, so maybe we should just not implement it)
@@ -640,6 +647,7 @@ func (ls *INOLanguageServer) TextDocumentTypeDefinitionReqFromIDE(ctx context.Co
640647
return ideLocations, ideLocationLinks, nil
641648
}
642649

650+
// TextDocumentImplementationReqFromIDE handles a text document implementation request received from the IDE
643651
func (ls *INOLanguageServer) TextDocumentImplementationReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.ImplementationParams) ([]lsp.Location, []lsp.LocationLink, *jsonrpc.ResponseError) {
644652
ls.readLock(logger, true)
645653
defer ls.readUnlock(logger)
@@ -684,6 +692,7 @@ func (ls *INOLanguageServer) TextDocumentImplementationReqFromIDE(ctx context.Co
684692
return ideLocations, inoLocationLinks, nil
685693
}
686694

695+
// TextDocumentDocumentHighlightReqFromIDE handles a text document highlight request received from the IDE
687696
func (ls *INOLanguageServer) TextDocumentDocumentHighlightReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.DocumentHighlightParams) ([]lsp.DocumentHighlight, *jsonrpc.ResponseError) {
688697
ls.readLock(logger, true)
689698
defer ls.readUnlock(logger)
@@ -731,6 +740,7 @@ func (ls *INOLanguageServer) TextDocumentDocumentHighlightReqFromIDE(ctx context
731740
return ideHighlights, nil
732741
}
733742

743+
// TextDocumentDocumentSymbolReqFromIDE handles a text document symbol request received from the IDE
734744
func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.DocumentSymbolParams) ([]lsp.DocumentSymbol, []lsp.SymbolInformation, *jsonrpc.ResponseError) {
735745
ls.readLock(logger, true)
736746
defer ls.readUnlock(logger)
@@ -762,13 +772,13 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
762772
// Convert response for IDE
763773
var ideDocSymbols []lsp.DocumentSymbol
764774
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 {
766777
logger.Logf("Error: %s", err)
767778
ls.Close()
768779
return nil, nil, &jsonrpc.ResponseError{Code: jsonrpc.ErrorCodesInternalError, Message: err.Error()}
769-
} else {
770-
ideDocSymbols = s
771780
}
781+
ideDocSymbols = s
772782
}
773783
var ideSymbolsInformation []lsp.SymbolInformation
774784
if clangSymbolsInformation != nil {
@@ -777,6 +787,7 @@ func (ls *INOLanguageServer) TextDocumentDocumentSymbolReqFromIDE(ctx context.Co
777787
return ideDocSymbols, ideSymbolsInformation, nil
778788
}
779789

790+
// TextDocumentCodeActionReqFromIDE handles a text document code action request received from the IDE
780791
func (ls *INOLanguageServer) TextDocumentCodeActionReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.CodeActionParams) ([]lsp.CommandOrCodeAction, *jsonrpc.ResponseError) {
781792
ls.readLock(logger, true)
782793
defer ls.readUnlock(logger)
@@ -846,6 +857,7 @@ func (ls *INOLanguageServer) TextDocumentCodeActionReqFromIDE(ctx context.Contex
846857
return ideCommandsOrCodeActions, nil
847858
}
848859

860+
// TextDocumentFormattingReqFromIDE handles a text document formatting request received from the IDE
849861
func (ls *INOLanguageServer) TextDocumentFormattingReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.DocumentFormattingParams) ([]lsp.TextEdit, *jsonrpc.ResponseError) {
850862
ls.writeLock(logger, true)
851863
defer ls.writeUnlock(logger)
@@ -860,12 +872,12 @@ func (ls *INOLanguageServer) TextDocumentFormattingReqFromIDE(ctx context.Contex
860872
}
861873
clangURI := clangTextDocument.URI
862874

863-
if cleanup, err := ls.createClangdFormatterConfig(logger, clangURI); err != nil {
875+
cleanup, err := ls.createClangdFormatterConfig(logger, clangURI)
876+
if err != nil {
864877
logger.Logf("Error: %s", err)
865878
return nil, &jsonrpc.ResponseError{Code: jsonrpc.ErrorCodesInternalError, Message: err.Error()}
866-
} else {
867-
defer cleanup()
868879
}
880+
defer cleanup()
869881

870882
clangParams := &lsp.DocumentFormattingParams{
871883
WorkDoneProgressParams: ideParams.WorkDoneProgressParams,
@@ -894,13 +906,14 @@ func (ls *INOLanguageServer) TextDocumentFormattingReqFromIDE(ctx context.Contex
894906
}
895907

896908
// 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 {
898911
return []lsp.TextEdit{}, nil
899-
} else {
900-
return inoEdits, nil
901912
}
913+
return inoEdits, nil
902914
}
903915

916+
// TextDocumentRangeFormattingReqFromIDE handles a text document range formatting request received from the IDE
904917
func (ls *INOLanguageServer) TextDocumentRangeFormattingReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.DocumentRangeFormattingParams) ([]lsp.TextEdit, *jsonrpc.ResponseError) {
905918
ls.writeLock(logger, true)
906919
defer ls.writeUnlock(logger)
@@ -918,12 +931,12 @@ func (ls *INOLanguageServer) TextDocumentRangeFormattingReqFromIDE(ctx context.C
918931
Range: clangRange,
919932
}
920933

921-
if cleanup, e := ls.createClangdFormatterConfig(logger, clangURI); e != nil {
934+
cleanup, e := ls.createClangdFormatterConfig(logger, clangURI)
935+
if e != nil {
922936
logger.Logf("cannot create formatter config file: %v", err)
923937
return nil, &jsonrpc.ResponseError{Code: jsonrpc.ErrorCodesInternalError, Message: err.Error()}
924-
} else {
925-
defer cleanup()
926938
}
939+
defer cleanup()
927940

928941
clangEdits, clangErr, err := ls.Clangd.conn.TextDocumentRangeFormatting(ctx, clangParams)
929942
if err != nil {
@@ -947,23 +960,26 @@ func (ls *INOLanguageServer) TextDocumentRangeFormattingReqFromIDE(ctx context.C
947960
}
948961

949962
// 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 {
951965
return []lsp.TextEdit{}, nil
952-
} else {
953-
return inoEdits, nil
954966
}
967+
return inoEdits, nil
955968
}
956969

970+
// InitializedNotifFromIDE initializes a notification from the IDE
957971
func (ls *INOLanguageServer) InitializedNotifFromIDE(logger jsonrpc.FunctionLogger, ideParams *lsp.InitializedParams) {
958972
logger.Logf("Notification is not propagated to clangd")
959973
}
960974

975+
// ExitNotifFromIDE logs an exit notification from the IDE
961976
func (ls *INOLanguageServer) ExitNotifFromIDE(logger jsonrpc.FunctionLogger) {
962977
ls.Clangd.conn.Exit()
963978
logger.Logf("Arduino Language Server is shutting down.")
964979
os.Exit(0)
965980
}
966981

982+
// TextDocumentDidOpenNotifFromIDE handles a notification from the IDE that TextDocument is open
967983
func (ls *INOLanguageServer) TextDocumentDidOpenNotifFromIDE(logger jsonrpc.FunctionLogger, ideParam *lsp.DidOpenTextDocumentParams) {
968984
ls.writeLock(logger, true)
969985
defer ls.writeUnlock(logger)
@@ -1023,6 +1039,7 @@ func (ls *INOLanguageServer) TextDocumentDidOpenNotifFromIDE(logger jsonrpc.Func
10231039
}
10241040
}
10251041

1042+
// TextDocumentDidChangeNotifFromIDE handles a notification from the IDE that TextDocument changed
10261043
func (ls *INOLanguageServer) TextDocumentDidChangeNotifFromIDE(logger jsonrpc.FunctionLogger, ideParams *lsp.DidChangeTextDocumentParams) {
10271044
ls.writeLock(logger, true)
10281045
defer ls.writeUnlock(logger)
@@ -1119,6 +1136,7 @@ func (ls *INOLanguageServer) TextDocumentDidChangeNotifFromIDE(logger jsonrpc.Fu
11191136
}
11201137
}
11211138

1139+
// TextDocumentDidSaveNotifFromIDE handles a notification from the IDE that TextDocument has been saved
11221140
func (ls *INOLanguageServer) TextDocumentDidSaveNotifFromIDE(logger jsonrpc.FunctionLogger, ideParams *lsp.DidSaveTextDocumentParams) {
11231141
ls.writeLock(logger, true)
11241142
defer ls.writeUnlock(logger)
@@ -1130,6 +1148,7 @@ func (ls *INOLanguageServer) TextDocumentDidSaveNotifFromIDE(logger jsonrpc.Func
11301148
ls.triggerRebuild()
11311149
}
11321150

1151+
// TextDocumentDidCloseNotifFromIDE handles a notification from the IDE that TextDocument has been closed
11331152
func (ls *INOLanguageServer) TextDocumentDidCloseNotifFromIDE(logger jsonrpc.FunctionLogger, ideParams *lsp.DidCloseTextDocumentParams) {
11341153
ls.writeLock(logger, true)
11351154
defer ls.writeUnlock(logger)
@@ -1173,14 +1192,16 @@ func (ls *INOLanguageServer) TextDocumentDidCloseNotifFromIDE(logger jsonrpc.Fun
11731192
}
11741193
}
11751194

1195+
// FullBuildCompletedFromIDE receives a full build from the IDE and copies the results
11761196
func (ls *INOLanguageServer) FullBuildCompletedFromIDE(logger jsonrpc.FunctionLogger, params *DidCompleteBuildParams) {
11771197
ls.writeLock(logger, true)
11781198
defer ls.writeUnlock(logger)
11791199

1180-
ls.CopyFullBuildResults(logger, params.BuildOutputUri.AsPath())
1200+
ls.CopyFullBuildResults(logger, params.BuildOutputURI.AsPath())
11811201
ls.triggerRebuild()
11821202
}
11831203

1204+
// CopyFullBuildResults copies the results of a full build
11841205
func (ls *INOLanguageServer) CopyFullBuildResults(logger jsonrpc.FunctionLogger, buildPath *paths.Path) {
11851206
fromCache := buildPath.Join("libraries.cache")
11861207
toCache := ls.buildPath.Join("libraries.cache")
@@ -1191,6 +1212,7 @@ func (ls *INOLanguageServer) CopyFullBuildResults(logger jsonrpc.FunctionLogger,
11911212
}
11921213
}
11931214

1215+
// PublishDiagnosticsNotifFromClangd publishes a diagnostics if notified from Clangd
11941216
func (ls *INOLanguageServer) PublishDiagnosticsNotifFromClangd(logger jsonrpc.FunctionLogger, clangParams *lsp.PublishDiagnosticsParams) {
11951217
if ls.config.DisableRealTimeDiagnostics {
11961218
logger.Logf("Ignored by configuration")
@@ -1271,6 +1293,7 @@ func (ls *INOLanguageServer) PublishDiagnosticsNotifFromClangd(logger jsonrpc.Fu
12711293
}
12721294
}
12731295

1296+
// TextDocumentRenameReqFromIDE handles a request from the IDE to rename TextDocument
12741297
func (ls *INOLanguageServer) TextDocumentRenameReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, ideParams *lsp.RenameParams) (*lsp.WorkspaceEdit, *jsonrpc.ResponseError) {
12751298
ls.writeLock(logger, false)
12761299
defer ls.writeUnlock(logger)
@@ -1348,6 +1371,7 @@ func (ls *INOLanguageServer) WindowWorkDoneProgressCreateReqFromClangd(ctx conte
13481371
return nil
13491372
}
13501373

1374+
// SetTraceNotifFromIDE gets a notification from the IDE to Set Trace to parameters
13511375
func (ls *INOLanguageServer) SetTraceNotifFromIDE(logger jsonrpc.FunctionLogger, params *lsp.SetTraceParams) {
13521376
logger.Logf("Notification level set to: %s", params.Value)
13531377
ls.Clangd.conn.SetTrace(params)

Diff for: ls/ls_ide_to_clang.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ func (ls *INOLanguageServer) ide2ClangRange(logger jsonrpc.FunctionLogger, ideUR
9494
if ls.clangURIRefersToIno(clangURI) {
9595
if clangRange, ok := ls.sketchMapper.InoToCppLSPRangeOk(ideURI, ideRange); ok {
9696
return clangURI, clangRange, nil
97-
} else {
98-
return lsp.DocumentURI{}, lsp.Range{}, fmt.Errorf("invalid range %s:%s: could not be mapped to Arduino-preprocessed sketck.ino.cpp", ideURI, ideRange)
9997
}
98+
return lsp.DocumentURI{}, lsp.Range{}, fmt.Errorf("invalid range %s:%s: could not be mapped to Arduino-preprocessed sketck.ino.cpp", ideURI, ideRange)
10099
} else if inSketch {
101100
// Convert other sketch file ranges (.cpp/.h)
102101
clangRange := ideRange

0 commit comments

Comments
 (0)