Skip to content

Commit 1942ec4

Browse files
committed
Big refactoring to get rid of all legacy lsp/jsonrpc2 stuff
1 parent 08181a1 commit 1942ec4

File tree

11 files changed

+873
-707
lines changed

11 files changed

+873
-707
lines changed

Diff for: go.mod

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ module github.com/arduino/arduino-language-server
22

33
go 1.12
44

5+
replace go.bug.st/lsp => ../lsp
6+
7+
replace go.bug.st/json => ../go-json
8+
59
require (
610
github.com/arduino/arduino-cli v0.0.0-20201215104024-6a177ebf56f2
7-
github.com/arduino/go-paths-helper v1.5.0
11+
github.com/arduino/go-paths-helper v1.6.1
812
github.com/fatih/color v1.7.0
913
github.com/pkg/errors v0.9.1
1014
github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37
1115
github.com/stretchr/testify v1.6.1
16+
go.bug.st/json v1.0.0
17+
go.bug.st/lsp v0.0.0-00010101000000-000000000000
1218
)

Diff for: go.sum

+2-42
Large diffs are not rendered by default.

Diff for: handler/builder.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ package handler
22

33
import (
44
"bytes"
5-
"context"
6-
"encoding/json"
7-
"log"
85
"strings"
96
"time"
107

118
"github.com/arduino/arduino-cli/arduino/libraries"
129
"github.com/arduino/arduino-cli/executils"
13-
"github.com/arduino/arduino-language-server/lsp"
1410
"github.com/arduino/arduino-language-server/streams"
1511
"github.com/arduino/go-paths-helper"
12+
"github.com/fatih/color"
1613
"github.com/pkg/errors"
14+
"go.bug.st/json"
15+
"go.bug.st/lsp"
1716
)
1817

1918
func (handler *InoHandler) scheduleRebuildEnvironment() {
@@ -25,6 +24,7 @@ func (handler *InoHandler) scheduleRebuildEnvironment() {
2524

2625
func (handler *InoHandler) rebuildEnvironmentLoop() {
2726
defer streams.CatchAndLogPanic()
27+
logger := streams.NewPrefixLogger(color.New(color.FgHiMagenta), "RBLD---")
2828

2929
grabDeadline := func() *time.Time {
3030
handler.rebuildSketchDeadlineMutex.Lock()
@@ -68,24 +68,24 @@ func (handler *InoHandler) rebuildEnvironmentLoop() {
6868
case <-time.After(time.Millisecond * 400):
6969
msg := "compiling" + dots[count%3]
7070
count++
71-
handler.progressHandler.Report("arduinoLanguageServerRebuild", &lsp.WorkDoneProgressReport{Message: &msg})
71+
handler.progressHandler.Report("arduinoLanguageServerRebuild", &lsp.WorkDoneProgressReport{Message: msg})
7272
case <-done:
7373
msg := "done"
74-
handler.progressHandler.End("arduinoLanguageServerRebuild", &lsp.WorkDoneProgressEnd{Message: &msg})
74+
handler.progressHandler.End("arduinoLanguageServerRebuild", &lsp.WorkDoneProgressEnd{Message: msg})
7575
return
7676
}
7777
}
7878
}()
7979

80-
handler.dataLock("RBLD---")
81-
handler.initializeWorkbench(context.Background(), nil)
82-
handler.dataUnlock("RBLD---")
80+
handler.writeLock(logger, false)
81+
handler.initializeWorkbench(logger, nil)
82+
handler.writeUnlock(logger)
8383
done <- true
8484
close(done)
8585
}
8686
}
8787

88-
func (handler *InoHandler) generateBuildEnvironment(buildPath *paths.Path) error {
88+
func (handler *InoHandler) generateBuildEnvironment(logger streams.PrefixLogger, buildPath *paths.Path) error {
8989
sketchDir := handler.sketchRoot
9090
fqbn := handler.config.SelectedBoard.Fqbn
9191

@@ -130,7 +130,7 @@ func (handler *InoHandler) generateBuildEnvironment(buildPath *paths.Path) error
130130
cmdOutput := &bytes.Buffer{}
131131
cmd.RedirectStdoutTo(cmdOutput)
132132
cmd.SetDirFromPath(sketchDir)
133-
log.Println("running: ", strings.Join(args, " "))
133+
logger("running: %s", strings.Join(args, " "))
134134
if err := cmd.Run(); err != nil {
135135
return errors.Errorf("running %s: %s", strings.Join(args, " "), err)
136136
}
@@ -150,7 +150,7 @@ func (handler *InoHandler) generateBuildEnvironment(buildPath *paths.Path) error
150150
if err := json.Unmarshal(cmdOutput.Bytes(), &res); err != nil {
151151
return errors.Errorf("parsing arduino-cli output: %s", err)
152152
}
153-
log.Println("arduino-cli output:", cmdOutput)
153+
logger("arduino-cli output: %s", cmdOutput)
154154

155155
return nil
156156
}

0 commit comments

Comments
 (0)