Skip to content

Commit c51689a

Browse files
committedDec 16, 2020
Added .Ext() method on DocumentURI
1 parent 91d2376 commit c51689a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

‎handler/handler.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func (handler *InoHandler) didOpen(ctx context.Context, params *lsp.DidOpenTextD
509509
handler.docs[doc.URI] = &doc
510510

511511
// If we are tracking a .ino...
512-
if doc.URI.AsPath().Ext() == ".ino" {
512+
if doc.URI.Ext() == ".ino" {
513513
handler.sketchTrackedFilesCount++
514514
log.Printf(" increasing .ino tracked files count: %d", handler.sketchTrackedFilesCount)
515515

@@ -549,7 +549,7 @@ func (handler *InoHandler) didChange(ctx context.Context, req *lsp.DidChangeText
549549

550550
// If changes are applied to a .ino file we increment the global .ino.cpp versioning
551551
// for each increment of the single .ino file.
552-
if doc.URI.AsPath().Ext() == ".ino" {
552+
if doc.URI.Ext() == ".ino" {
553553

554554
cppChanges := []lsp.TextDocumentContentChangeEvent{}
555555
for _, inoChange := range req.ContentChanges {
@@ -853,7 +853,7 @@ func (handler *InoHandler) cpp2inoCodeAction(codeAction *lsp.CodeAction, uri lsp
853853
Diagnostics: codeAction.Diagnostics,
854854
Command: handler.Cpp2InoCommand(codeAction.Command),
855855
}
856-
if uri.AsPath().Ext() == ".ino" {
856+
if uri.Ext() == ".ino" {
857857
for i, diag := range inoCodeAction.Diagnostics {
858858
_, inoCodeAction.Diagnostics[i].Range = handler.sketchMapper.CppToInoRange(diag.Range)
859859
}
@@ -953,7 +953,7 @@ func (handler *InoHandler) cpp2inoTextEdit(edit *lsp.TextEdit, uri lsp.DocumentU
953953
}
954954

955955
func (handler *InoHandler) cpp2inoDocumentSymbols(origSymbols []lsp.DocumentSymbol, origURI lsp.DocumentURI) []lsp.DocumentSymbol {
956-
if origURI.AsPath().Ext() != ".ino" || len(origSymbols) == 0 {
956+
if origURI.Ext() != ".ino" || len(origSymbols) == 0 {
957957
return origSymbols
958958
}
959959

@@ -1072,7 +1072,7 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
10721072
// If we have an "undefined reference" in the .ino code trigger a
10731073
// check for newly created symbols (that in turn may trigger a
10741074
// new arduino-preprocessing of the sketch).
1075-
if msg.URI.AsPath().Ext() == ".ino" {
1075+
if msg.URI.Ext() == ".ino" {
10761076
for _, diag := range msg.Diagnostics {
10771077
if diag.Code == "undeclared_var_use_suggest" {
10781078
handler.buildSketchSymbolsCheck = true

‎lsp/uri.go

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func (uri DocumentURI) String() string {
4343
return string(uri)
4444
}
4545

46+
// Ext returns the extension of the file pointed by the URI
47+
func (uri DocumentURI) Ext() string {
48+
return filepath.Ext(string(uri))
49+
}
50+
4651
// NewDocumentURIFromPath create a DocumentURI from the given Path object
4752
func NewDocumentURIFromPath(path *paths.Path) DocumentURI {
4853
return NewDocumentURI(path.String())

0 commit comments

Comments
 (0)
Please sign in to comment.