Skip to content

Commit 0869a5f

Browse files
committed
Terminate LS if we are unable to start clangd
1 parent e13dcc8 commit 0869a5f

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

Diff for: ls/ls.go

+16-22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"log"
9+
"os"
910
"strconv"
1011
"strings"
1112
"sync"
@@ -82,8 +83,18 @@ var yellow = color.New(color.FgHiYellow)
8283
func (ls *INOLanguageServer) writeLock(logger jsonrpc.FunctionLogger, requireClangd bool) {
8384
ls.dataMux.Lock()
8485
logger.Logf(yellow.Sprintf("write-locked"))
85-
if requireClangd {
86-
ls.waitClangdStart(logger)
86+
if requireClangd && ls.Clangd == nil {
87+
// if clangd is not started...
88+
logger.Logf("(throttled: waiting for clangd)")
89+
logger.Logf(yellow.Sprintf("unlocked (waiting clangd)"))
90+
ls.clangdStarted.Wait()
91+
logger.Logf(yellow.Sprintf("locked (waiting clangd)"))
92+
93+
if ls.Clangd == nil {
94+
logger.Logf("clangd startup failed: quitting Language server")
95+
ls.Close()
96+
os.Exit(2)
97+
}
8798
}
8899
}
89100

@@ -117,23 +128,6 @@ func (ls *INOLanguageServer) readUnlock(logger jsonrpc.FunctionLogger) {
117128
ls.dataMux.RUnlock()
118129
}
119130

120-
func (ls *INOLanguageServer) waitClangdStart(logger jsonrpc.FunctionLogger) error {
121-
if ls.Clangd != nil {
122-
return nil
123-
}
124-
125-
logger.Logf("(throttled: waiting for clangd)")
126-
logger.Logf(yellow.Sprintf("unlocked (waiting clangd)"))
127-
ls.clangdStarted.Wait()
128-
logger.Logf(yellow.Sprintf("locked (waiting clangd)"))
129-
130-
if ls.Clangd == nil {
131-
logger.Logf("clangd startup failed: aborting call")
132-
return errors.New("could not start clangd, aborted")
133-
}
134-
return nil
135-
}
136-
137131
// NewINOLanguageServer creates and configures an Arduino Language Server.
138132
func NewINOLanguageServer(stdin io.Reader, stdout io.Writer, board Board) *INOLanguageServer {
139133
logger := NewLSPFunctionLogger(color.HiWhiteString, "LS: ")
@@ -185,6 +179,8 @@ func NewINOLanguageServer(stdin io.Reader, stdout io.Writer, board Board) *INOLa
185179
func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger, inoParams *lsp.InitializeParams) (*lsp.InitializeResult, *jsonrpc.ResponseError) {
186180
go func() {
187181
defer streams.CatchAndLogPanic()
182+
// Unlock goroutines waiting for clangd
183+
defer ls.clangdStarted.Broadcast()
188184

189185
logger := NewLSPFunctionLogger(color.HiCyanString, "INIT --- ")
190186
logger.Logf("initializing workbench: %s", inoParams.RootURI)
@@ -198,6 +194,7 @@ func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger js
198194
return
199195
} else if !success {
200196
logger.Logf("bootstrap build failed!")
197+
return
201198
}
202199

203200
if err := ls.buildPath.Join("compile_commands.json").CopyTo(ls.compileCommandsDir.Join("compile_commands.json")); err != nil {
@@ -249,9 +246,6 @@ func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger js
249246
return
250247
}
251248

252-
// signal that clangd is running now...
253-
ls.clangdStarted.Broadcast()
254-
255249
logger.Logf("Done initializing workbench")
256250
}()
257251

0 commit comments

Comments
 (0)