@@ -6,12 +6,10 @@ import (
6
6
"encoding/json"
7
7
"io"
8
8
"log"
9
- "net/url"
10
9
"path/filepath"
11
10
"regexp"
12
11
"strings"
13
12
14
- "github.com/pkg/errors"
15
13
lsp "github.com/sourcegraph/go-lsp"
16
14
"github.com/sourcegraph/jsonrpc2"
17
15
)
@@ -154,6 +152,9 @@ func (handler *InoHandler) transformClangdParams(ctx context.Context, method str
154
152
p := params .(* lsp.RenameParams )
155
153
uri = p .TextDocument .URI
156
154
err = handler .ino2cppRenameParams (p )
155
+ case "workspace/didChangeWatchedFiles" :
156
+ p := params .(* lsp.DidChangeWatchedFilesParams )
157
+ err = handler .ino2cppDidChangeWatchedFilesParams (p )
157
158
}
158
159
return
159
160
}
@@ -233,7 +234,10 @@ func (handler *InoHandler) handleError(ctx context.Context, err error, fqbn stri
233
234
message = "Editor support is disabled because the platform `" + fqbn + "` is not installed."
234
235
message += " Use the Boards Manager to install it."
235
236
} else if strings .Contains (errorStr , "No such file or directory" ) {
236
- exp , _ := regexp .Compile ("([\\ w\\ .\\ -]+)\\ .h: No such file or directory" )
237
+ exp , regexpErr := regexp .Compile ("([\\ w\\ .\\ -]+)\\ .h: No such file or directory" )
238
+ if regexpErr != nil {
239
+ panic (regexpErr )
240
+ }
237
241
submatch := exp .FindStringSubmatch (errorStr )
238
242
message = "Editor support is disabled because the library `" + submatch [1 ] + "` is not installed."
239
243
message += " Use the Library Manager to install it"
@@ -246,8 +250,9 @@ func (handler *InoHandler) handleError(ctx context.Context, err error, fqbn stri
246
250
func (handler * InoHandler ) ino2cppTextDocumentIdentifier (doc * lsp.TextDocumentIdentifier ) error {
247
251
if data , ok := handler .data [doc .URI ]; ok {
248
252
doc .URI = data .targetURI
253
+ return nil
249
254
}
250
- return nil
255
+ return unknownURI ( doc . URI )
251
256
}
252
257
253
258
func (handler * InoHandler ) ino2cppTextDocumentItem (ctx context.Context , doc * lsp.TextDocumentItem ) error {
@@ -330,6 +335,16 @@ func (handler *InoHandler) ino2cppRenameParams(params *lsp.RenameParams) error {
330
335
return unknownURI (params .TextDocument .URI )
331
336
}
332
337
338
+ func (handler * InoHandler ) ino2cppDidChangeWatchedFilesParams (params * lsp.DidChangeWatchedFilesParams ) error {
339
+ for index := range params .Changes {
340
+ fileEvent := & params .Changes [index ]
341
+ if data , ok := handler .data [fileEvent .URI ]; ok {
342
+ fileEvent .URI = data .targetURI
343
+ }
344
+ }
345
+ return nil
346
+ }
347
+
333
348
func (handler * InoHandler ) transformClangdResult (method string , uri lsp.DocumentURI , result interface {}) interface {} {
334
349
switch method {
335
350
case "textDocument/completion" :
@@ -532,6 +547,8 @@ func (handler *InoHandler) transformStdioParams(method string, raw *json.RawMess
532
547
}
533
548
534
549
func (handler * InoHandler ) cpp2inoPublishDiagnosticsParams (params * lsp.PublishDiagnosticsParams ) error {
550
+ log .Println ("diagnostics" , * params )
551
+ log .Println ("data" , handler .data )
535
552
if data , ok := handler .data [params .URI ]; ok {
536
553
params .URI = data .sourceURI
537
554
for index := range params .Diagnostics {
@@ -550,19 +567,3 @@ func (handler *InoHandler) showMessage(ctx context.Context, msgType lsp.MessageT
550
567
}
551
568
handler .StdioConn .Notify (ctx , "window/showMessage" , & params )
552
569
}
553
-
554
- func uriToPath (uri lsp.DocumentURI ) string {
555
- url , err := url .Parse (string (uri ))
556
- if err != nil {
557
- return string (uri )
558
- }
559
- return filepath .FromSlash (url .Path )
560
- }
561
-
562
- func pathToURI (path string ) lsp.DocumentURI {
563
- return "file://" + lsp .DocumentURI (filepath .ToSlash (path ))
564
- }
565
-
566
- func unknownURI (uri lsp.DocumentURI ) error {
567
- return errors .New ("Document is not available: " + string (uri ))
568
- }
0 commit comments