Skip to content

Commit c8ad100

Browse files
committed
Made proper error for UnknownURI
1 parent 00590aa commit c8ad100

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

ls/ls.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ func (ls *INOLanguageServer) didClose(logger jsonrpc.FunctionLogger, inoDidClose
11061106
delete(ls.trackedIDEDocs, inoIdentifier.URI.AsPath().String())
11071107
} else {
11081108
logger.Logf(" didClose of untracked document: %s", inoIdentifier.URI)
1109-
return nil, unknownURI(inoIdentifier.URI)
1109+
return nil, &UnknownURI{inoIdentifier.URI}
11101110
}
11111111

11121112
// If we are tracking a .ino...
@@ -1161,7 +1161,7 @@ func (ls *INOLanguageServer) didChange(logger jsonrpc.FunctionLogger, inoDidChan
11611161
// Apply the change to the tracked sketch file.
11621162
trackedInoID := inoDoc.URI.AsPath().String()
11631163
if doc, ok := ls.trackedIDEDocs[trackedInoID]; !ok {
1164-
return nil, unknownURI(inoDoc.URI)
1164+
return nil, &UnknownURI{inoDoc.URI}
11651165
} else if updatedDoc, err := textedits.ApplyLSPTextDocumentContentChangeEvent(doc, inoDidChangeParams); err != nil {
11661166
return nil, err
11671167
} else {
@@ -1446,6 +1446,10 @@ func (ls *INOLanguageServer) cpp2inoDocumentSymbols(logger jsonrpc.FunctionLogge
14461446
return inoSymbols
14471447
}
14481448

1449-
func unknownURI(uri lsp.DocumentURI) error {
1450-
return errors.New("Document is not available: " + uri.String())
1449+
type UnknownURI struct {
1450+
URI lsp.DocumentURI
1451+
}
1452+
1453+
func (e *UnknownURI) Error() string {
1454+
return "Document is not available: " + e.URI.String()
14511455
}

ls/ls_ide_to_clang.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func (ls *INOLanguageServer) idePathToIdeURI(logger jsonrpc.FunctionLogger, inoP
1818
logger.Logf(" !!! > %s", p)
1919
}
2020
uri := lsp.NewDocumentURI(inoPath)
21-
return uri, unknownURI(uri)
21+
return uri, &UnknownURI{uri}
2222
}
2323
return doc.URI, nil
2424
}
@@ -42,7 +42,7 @@ func (ls *INOLanguageServer) ide2ClangDocumentURI(logger jsonrpc.FunctionLogger,
4242
inside, err := idePath.IsInsideDir(ls.sketchRoot)
4343
if err != nil {
4444
logger.Logf("ERROR: could not determine if '%s' is inside '%s'", idePath, ls.sketchRoot)
45-
return lsp.NilURI, unknownURI(ideURI)
45+
return lsp.NilURI, &UnknownURI{ideURI}
4646
}
4747
if !inside {
4848
clangURI := ideURI
@@ -79,7 +79,7 @@ func (ls *INOLanguageServer) ide2ClangTextDocumentPositionParams(logger jsonrpc.
7979
clangPosition.Line = cppLine
8080
} else {
8181
logger.Logf("%s -> invalid line requested: %s:%d", ideParams, ideURI, idePosition.Line)
82-
return lsp.TextDocumentPositionParams{}, unknownURI(ideURI)
82+
return lsp.TextDocumentPositionParams{}, &UnknownURI{ideURI}
8383
}
8484
}
8585
clangParams := lsp.TextDocumentPositionParams{

0 commit comments

Comments
 (0)