@@ -6,12 +6,10 @@ import (
66 "encoding/json"
77 "io"
88 "log"
9- "net/url"
109 "path/filepath"
1110 "regexp"
1211 "strings"
1312
14- "github.com/pkg/errors"
1513 lsp "github.com/sourcegraph/go-lsp"
1614 "github.com/sourcegraph/jsonrpc2"
1715)
@@ -154,6 +152,9 @@ func (handler *InoHandler) transformClangdParams(ctx context.Context, method str
154152 p := params .(* lsp.RenameParams )
155153 uri = p .TextDocument .URI
156154 err = handler .ino2cppRenameParams (p )
155+ case "workspace/didChangeWatchedFiles" :
156+ p := params .(* lsp.DidChangeWatchedFilesParams )
157+ err = handler .ino2cppDidChangeWatchedFilesParams (p )
157158 }
158159 return
159160}
@@ -233,7 +234,10 @@ func (handler *InoHandler) handleError(ctx context.Context, err error, fqbn stri
233234 message = "Editor support is disabled because the platform `" + fqbn + "` is not installed."
234235 message += " Use the Boards Manager to install it."
235236 } 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+ }
237241 submatch := exp .FindStringSubmatch (errorStr )
238242 message = "Editor support is disabled because the library `" + submatch [1 ] + "` is not installed."
239243 message += " Use the Library Manager to install it"
@@ -246,8 +250,9 @@ func (handler *InoHandler) handleError(ctx context.Context, err error, fqbn stri
246250func (handler * InoHandler ) ino2cppTextDocumentIdentifier (doc * lsp.TextDocumentIdentifier ) error {
247251 if data , ok := handler .data [doc .URI ]; ok {
248252 doc .URI = data .targetURI
253+ return nil
249254 }
250- return nil
255+ return unknownURI ( doc . URI )
251256}
252257
253258func (handler * InoHandler ) ino2cppTextDocumentItem (ctx context.Context , doc * lsp.TextDocumentItem ) error {
@@ -330,6 +335,16 @@ func (handler *InoHandler) ino2cppRenameParams(params *lsp.RenameParams) error {
330335 return unknownURI (params .TextDocument .URI )
331336}
332337
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+
333348func (handler * InoHandler ) transformClangdResult (method string , uri lsp.DocumentURI , result interface {}) interface {} {
334349 switch method {
335350 case "textDocument/completion" :
@@ -532,6 +547,8 @@ func (handler *InoHandler) transformStdioParams(method string, raw *json.RawMess
532547}
533548
534549func (handler * InoHandler ) cpp2inoPublishDiagnosticsParams (params * lsp.PublishDiagnosticsParams ) error {
550+ log .Println ("diagnostics" , * params )
551+ log .Println ("data" , handler .data )
535552 if data , ok := handler .data [params .URI ]; ok {
536553 params .URI = data .sourceURI
537554 for index := range params .Diagnostics {
@@ -550,19 +567,3 @@ func (handler *InoHandler) showMessage(ctx context.Context, msgType lsp.MessageT
550567 }
551568 handler .StdioConn .Notify (ctx , "window/showMessage" , & params )
552569}
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