@@ -16,9 +16,9 @@ import (
16
16
"github.com/arduino/go-paths-helper"
17
17
"github.com/bcmi-labs/arduino-language-server/handler/sourcemapper"
18
18
"github.com/bcmi-labs/arduino-language-server/handler/textutils"
19
+ "github.com/bcmi-labs/arduino-language-server/lsp"
19
20
"github.com/bcmi-labs/arduino-language-server/streams"
20
21
"github.com/pkg/errors"
21
- lsp "github.com/sourcegraph/go-lsp"
22
22
"github.com/sourcegraph/jsonrpc2"
23
23
)
24
24
@@ -39,11 +39,11 @@ func Setup(cliPath string, clangdPath string, _enableLogging bool, _asyncProcess
39
39
type CLangdStarter func () (stdin io.WriteCloser , stdout io.ReadCloser , stderr io.ReadCloser )
40
40
41
41
// NewInoHandler creates and configures an InoHandler.
42
- func NewInoHandler (stdio io.ReadWriteCloser , board Board ) * InoHandler {
42
+ func NewInoHandler (stdio io.ReadWriteCloser , board lsp. Board ) * InoHandler {
43
43
handler := & InoHandler {
44
44
data : map [lsp.DocumentURI ]* FileData {},
45
45
trackedFiles : map [lsp.DocumentURI ]lsp.TextDocumentItem {},
46
- config : BoardConfig {
46
+ config : lsp. BoardConfig {
47
47
SelectedBoard : board ,
48
48
},
49
49
}
@@ -77,7 +77,7 @@ type InoHandler struct {
77
77
trackedFiles map [lsp.DocumentURI ]lsp.TextDocumentItem
78
78
79
79
data map [lsp.DocumentURI ]* FileData
80
- config BoardConfig
80
+ config lsp. BoardConfig
81
81
synchronizer Synchronizer
82
82
}
83
83
@@ -114,7 +114,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
114
114
// Handle LSP methods: transform parameters and send to clangd
115
115
var uri lsp.DocumentURI
116
116
117
- params , err := readParams (req .Method , req .Params )
117
+ params , err := lsp . ReadParams (req .Method , req .Params )
118
118
if err != nil {
119
119
return nil , err
120
120
}
@@ -147,7 +147,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
147
147
err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
148
148
log .Printf (" --> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
149
149
150
- case * HoverParams :
150
+ case * lsp. HoverParams :
151
151
// method: "textDocument/hover"
152
152
uri = p .TextDocument .URI
153
153
doc := & p .TextDocumentPositionParams
@@ -230,7 +230,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
230
230
} else {
231
231
ctx , cancel := context .WithTimeout (ctx , 800 * time .Millisecond )
232
232
defer cancel ()
233
- result , err = sendRequest (ctx , handler .ClangdConn , req .Method , params )
233
+ result , err = lsp . SendRequest (ctx , handler .ClangdConn , req .Method , params )
234
234
if enableLogging {
235
235
log .Println (" sent" , req .Method , "request id" , req .ID , " to clangd" )
236
236
}
@@ -609,7 +609,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
609
609
switch r := result .(type ) {
610
610
case * lsp.CompletionList : // "textDocument/completion":
611
611
handler .cpp2inoCompletionList (r , uri )
612
- case * []* commandOrCodeAction : // "textDocument/codeAction":
612
+ case * []* lsp. CommandOrCodeAction : // "textDocument/codeAction":
613
613
for index := range * r {
614
614
command := (* r )[index ].Command
615
615
if command != nil {
@@ -620,7 +620,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
620
620
handler .cpp2inoCodeAction (codeAction , uri )
621
621
}
622
622
}
623
- case * Hover : // "textDocument/hover":
623
+ case * lsp. Hover : // "textDocument/hover":
624
624
if len (r .Contents .Value ) == 0 {
625
625
return nil
626
626
}
@@ -647,15 +647,15 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
647
647
for index := range * r {
648
648
handler .cpp2inoTextEdit (& (* r )[index ], uri )
649
649
}
650
- case * []* documentSymbolOrSymbolInformation : // "textDocument/documentSymbol":
650
+ case * []* lsp. DocumentSymbolOrSymbolInformation : // "textDocument/documentSymbol":
651
651
if len (* r ) == 0 {
652
652
return result
653
653
}
654
654
655
655
slice := * r
656
656
if slice [0 ].DocumentSymbol != nil {
657
657
// Treat the input as []DocumentSymbol
658
- symbols := make ([]DocumentSymbol , len (slice ))
658
+ symbols := make ([]lsp. DocumentSymbol , len (slice ))
659
659
for index := range slice {
660
660
symbols [index ] = * slice [index ].DocumentSymbol
661
661
}
@@ -694,7 +694,7 @@ func (handler *InoHandler) cpp2inoCompletionList(list *lsp.CompletionList, uri l
694
694
}
695
695
}
696
696
697
- func (handler * InoHandler ) cpp2inoCodeAction (codeAction * CodeAction , uri lsp.DocumentURI ) {
697
+ func (handler * InoHandler ) cpp2inoCodeAction (codeAction * lsp. CodeAction , uri lsp.DocumentURI ) {
698
698
codeAction .Edit = handler .cpp2inoWorkspaceEdit (codeAction .Edit )
699
699
if data , ok := handler .data [uri ]; ok {
700
700
for index := range codeAction .Diagnostics {
@@ -732,7 +732,7 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
732
732
return & newEdit
733
733
}
734
734
735
- func (handler * InoHandler ) cpp2inoHover (hover * Hover , uri lsp.DocumentURI ) {
735
+ func (handler * InoHandler ) cpp2inoHover (hover * lsp. Hover , uri lsp.DocumentURI ) {
736
736
if data , ok := handler .data [uri ]; ok {
737
737
r := hover .Range
738
738
if r != nil {
@@ -760,13 +760,13 @@ func (handler *InoHandler) cpp2inoTextEdit(edit *lsp.TextEdit, uri lsp.DocumentU
760
760
}
761
761
}
762
762
763
- func (handler * InoHandler ) cpp2inoDocumentSymbols (origSymbols []DocumentSymbol , uri lsp.DocumentURI ) []DocumentSymbol {
763
+ func (handler * InoHandler ) cpp2inoDocumentSymbols (origSymbols []lsp. DocumentSymbol , uri lsp.DocumentURI ) []lsp. DocumentSymbol {
764
764
data , ok := handler .data [uri ]
765
765
if ! ok || len (origSymbols ) == 0 {
766
766
return origSymbols
767
767
}
768
768
769
- symbolIdx := make (map [string ]* DocumentSymbol )
769
+ symbolIdx := make (map [string ]* lsp. DocumentSymbol )
770
770
for i := 0 ; i < len (origSymbols ); i ++ {
771
771
symbol := & origSymbols [i ]
772
772
_ , symbol .Range = data .sourceMap .CppToInoRange (symbol .Range )
@@ -787,7 +787,7 @@ func (handler *InoHandler) cpp2inoDocumentSymbols(origSymbols []DocumentSymbol,
787
787
symbolIdx [symbol .Name ] = symbol
788
788
}
789
789
790
- newSymbols := make ([]DocumentSymbol , len (symbolIdx ))
790
+ newSymbols := make ([]lsp. DocumentSymbol , len (symbolIdx ))
791
791
j := 0
792
792
for _ , s := range symbolIdx {
793
793
newSymbols [j ] = * s
@@ -825,7 +825,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
825
825
handler .synchronizer .DataMux .RLock ()
826
826
defer handler .synchronizer .DataMux .RUnlock ()
827
827
828
- params , err := readParams (req .Method , req .Params )
828
+ params , err := lsp . ReadParams (req .Method , req .Params )
829
829
if err != nil {
830
830
return nil , errors .WithMessage (err , "parsing JSON message from clangd" )
831
831
}
@@ -877,7 +877,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
877
877
return nil , err
878
878
}
879
879
880
- case * ApplyWorkspaceEditParams :
880
+ case * lsp. ApplyWorkspaceEditParams :
881
881
// "workspace/applyEdit"
882
882
p .Edit = * handler .cpp2inoWorkspaceEdit (& p .Edit )
883
883
}
@@ -893,7 +893,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
893
893
log .Println ("From clangd:" , req .Method )
894
894
}
895
895
} else {
896
- result , err = sendRequest (ctx , handler .StdioConn , req .Method , params )
896
+ result , err = lsp . SendRequest (ctx , handler .StdioConn , req .Method , params )
897
897
if enableLogging {
898
898
log .Println ("From clangd:" , req .Method , "id" , req .ID )
899
899
}
0 commit comments