@@ -16,9 +16,9 @@ import (
1616 "github.com/arduino/go-paths-helper"
1717 "github.com/bcmi-labs/arduino-language-server/handler/sourcemapper"
1818 "github.com/bcmi-labs/arduino-language-server/handler/textutils"
19+ "github.com/bcmi-labs/arduino-language-server/lsp"
1920 "github.com/bcmi-labs/arduino-language-server/streams"
2021 "github.com/pkg/errors"
21- lsp "github.com/sourcegraph/go-lsp"
2222 "github.com/sourcegraph/jsonrpc2"
2323)
2424
@@ -39,11 +39,11 @@ func Setup(cliPath string, clangdPath string, _enableLogging bool, _asyncProcess
3939type CLangdStarter func () (stdin io.WriteCloser , stdout io.ReadCloser , stderr io.ReadCloser )
4040
4141// 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 {
4343 handler := & InoHandler {
4444 data : map [lsp.DocumentURI ]* FileData {},
4545 trackedFiles : map [lsp.DocumentURI ]lsp.TextDocumentItem {},
46- config : BoardConfig {
46+ config : lsp. BoardConfig {
4747 SelectedBoard : board ,
4848 },
4949 }
@@ -77,7 +77,7 @@ type InoHandler struct {
7777 trackedFiles map [lsp.DocumentURI ]lsp.TextDocumentItem
7878
7979 data map [lsp.DocumentURI ]* FileData
80- config BoardConfig
80+ config lsp. BoardConfig
8181 synchronizer Synchronizer
8282}
8383
@@ -114,7 +114,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
114114 // Handle LSP methods: transform parameters and send to clangd
115115 var uri lsp.DocumentURI
116116
117- params , err := readParams (req .Method , req .Params )
117+ params , err := lsp . ReadParams (req .Method , req .Params )
118118 if err != nil {
119119 return nil , err
120120 }
@@ -147,7 +147,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
147147 err = handler .ino2cppTextDocumentPositionParams (& p .TextDocumentPositionParams )
148148 log .Printf (" --> completion(%s:%d:%d)\n " , p .TextDocument .URI , p .Position .Line , p .Position .Character )
149149
150- case * HoverParams :
150+ case * lsp. HoverParams :
151151 // method: "textDocument/hover"
152152 uri = p .TextDocument .URI
153153 doc := & p .TextDocumentPositionParams
@@ -230,7 +230,7 @@ func (handler *InoHandler) HandleMessageFromIDE(ctx context.Context, conn *jsonr
230230 } else {
231231 ctx , cancel := context .WithTimeout (ctx , 800 * time .Millisecond )
232232 defer cancel ()
233- result , err = sendRequest (ctx , handler .ClangdConn , req .Method , params )
233+ result , err = lsp . SendRequest (ctx , handler .ClangdConn , req .Method , params )
234234 if enableLogging {
235235 log .Println (" sent" , req .Method , "request id" , req .ID , " to clangd" )
236236 }
@@ -609,7 +609,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
609609 switch r := result .(type ) {
610610 case * lsp.CompletionList : // "textDocument/completion":
611611 handler .cpp2inoCompletionList (r , uri )
612- case * []* commandOrCodeAction : // "textDocument/codeAction":
612+ case * []* lsp. CommandOrCodeAction : // "textDocument/codeAction":
613613 for index := range * r {
614614 command := (* r )[index ].Command
615615 if command != nil {
@@ -620,7 +620,7 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
620620 handler .cpp2inoCodeAction (codeAction , uri )
621621 }
622622 }
623- case * Hover : // "textDocument/hover":
623+ case * lsp. Hover : // "textDocument/hover":
624624 if len (r .Contents .Value ) == 0 {
625625 return nil
626626 }
@@ -647,15 +647,15 @@ func (handler *InoHandler) transformClangdResult(method string, uri lsp.Document
647647 for index := range * r {
648648 handler .cpp2inoTextEdit (& (* r )[index ], uri )
649649 }
650- case * []* documentSymbolOrSymbolInformation : // "textDocument/documentSymbol":
650+ case * []* lsp. DocumentSymbolOrSymbolInformation : // "textDocument/documentSymbol":
651651 if len (* r ) == 0 {
652652 return result
653653 }
654654
655655 slice := * r
656656 if slice [0 ].DocumentSymbol != nil {
657657 // Treat the input as []DocumentSymbol
658- symbols := make ([]DocumentSymbol , len (slice ))
658+ symbols := make ([]lsp. DocumentSymbol , len (slice ))
659659 for index := range slice {
660660 symbols [index ] = * slice [index ].DocumentSymbol
661661 }
@@ -694,7 +694,7 @@ func (handler *InoHandler) cpp2inoCompletionList(list *lsp.CompletionList, uri l
694694 }
695695}
696696
697- func (handler * InoHandler ) cpp2inoCodeAction (codeAction * CodeAction , uri lsp.DocumentURI ) {
697+ func (handler * InoHandler ) cpp2inoCodeAction (codeAction * lsp. CodeAction , uri lsp.DocumentURI ) {
698698 codeAction .Edit = handler .cpp2inoWorkspaceEdit (codeAction .Edit )
699699 if data , ok := handler .data [uri ]; ok {
700700 for index := range codeAction .Diagnostics {
@@ -732,7 +732,7 @@ func (handler *InoHandler) cpp2inoWorkspaceEdit(origEdit *lsp.WorkspaceEdit) *ls
732732 return & newEdit
733733}
734734
735- func (handler * InoHandler ) cpp2inoHover (hover * Hover , uri lsp.DocumentURI ) {
735+ func (handler * InoHandler ) cpp2inoHover (hover * lsp. Hover , uri lsp.DocumentURI ) {
736736 if data , ok := handler .data [uri ]; ok {
737737 r := hover .Range
738738 if r != nil {
@@ -760,13 +760,13 @@ func (handler *InoHandler) cpp2inoTextEdit(edit *lsp.TextEdit, uri lsp.DocumentU
760760 }
761761}
762762
763- func (handler * InoHandler ) cpp2inoDocumentSymbols (origSymbols []DocumentSymbol , uri lsp.DocumentURI ) []DocumentSymbol {
763+ func (handler * InoHandler ) cpp2inoDocumentSymbols (origSymbols []lsp. DocumentSymbol , uri lsp.DocumentURI ) []lsp. DocumentSymbol {
764764 data , ok := handler .data [uri ]
765765 if ! ok || len (origSymbols ) == 0 {
766766 return origSymbols
767767 }
768768
769- symbolIdx := make (map [string ]* DocumentSymbol )
769+ symbolIdx := make (map [string ]* lsp. DocumentSymbol )
770770 for i := 0 ; i < len (origSymbols ); i ++ {
771771 symbol := & origSymbols [i ]
772772 _ , symbol .Range = data .sourceMap .CppToInoRange (symbol .Range )
@@ -787,7 +787,7 @@ func (handler *InoHandler) cpp2inoDocumentSymbols(origSymbols []DocumentSymbol,
787787 symbolIdx [symbol .Name ] = symbol
788788 }
789789
790- newSymbols := make ([]DocumentSymbol , len (symbolIdx ))
790+ newSymbols := make ([]lsp. DocumentSymbol , len (symbolIdx ))
791791 j := 0
792792 for _ , s := range symbolIdx {
793793 newSymbols [j ] = * s
@@ -825,7 +825,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
825825 handler .synchronizer .DataMux .RLock ()
826826 defer handler .synchronizer .DataMux .RUnlock ()
827827
828- params , err := readParams (req .Method , req .Params )
828+ params , err := lsp . ReadParams (req .Method , req .Params )
829829 if err != nil {
830830 return nil , errors .WithMessage (err , "parsing JSON message from clangd" )
831831 }
@@ -877,7 +877,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
877877 return nil , err
878878 }
879879
880- case * ApplyWorkspaceEditParams :
880+ case * lsp. ApplyWorkspaceEditParams :
881881 // "workspace/applyEdit"
882882 p .Edit = * handler .cpp2inoWorkspaceEdit (& p .Edit )
883883 }
@@ -893,7 +893,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
893893 log .Println ("From clangd:" , req .Method )
894894 }
895895 } else {
896- result , err = sendRequest (ctx , handler .StdioConn , req .Method , params )
896+ result , err = lsp . SendRequest (ctx , handler .StdioConn , req .Method , params )
897897 if enableLogging {
898898 log .Println ("From clangd:" , req .Method , "id" , req .ID )
899899 }
0 commit comments