Skip to content

Commit d07b2ab

Browse files
committed
use lsp helper in sourceMapper
1 parent 23b6d9c commit d07b2ab

File tree

1 file changed

+2
-31
lines changed

1 file changed

+2
-31
lines changed

Diff for: handler/sourcemapper/ino.go

+2-31
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ package sourcemapper
33
import (
44
"bufio"
55
"io"
6-
"net/url"
7-
"path/filepath"
8-
"regexp"
9-
"runtime"
106
"strconv"
117
"strings"
128

@@ -35,14 +31,12 @@ type InoLine struct {
3531

3632
// InoToCppLine converts a source (.ino) line into a target (.cpp) line
3733
func (s *InoMapper) InoToCppLine(sourceURI lsp.DocumentURI, line int) int {
38-
file := uriToPath(sourceURI)
39-
return s.toCpp[InoLine{file, line}]
34+
return s.toCpp[InoLine{sourceURI.Unbox(), line}]
4035
}
4136

4237
// InoToCppLineOk converts a source (.ino) line into a target (.cpp) line
4338
func (s *InoMapper) InoToCppLineOk(sourceURI lsp.DocumentURI, line int) (int, bool) {
44-
file := uriToPath(sourceURI)
45-
res, ok := s.toCpp[InoLine{file, line}]
39+
res, ok := s.toCpp[InoLine{sourceURI.Unbox(), line}]
4640
return res, ok
4741
}
4842

@@ -193,26 +187,3 @@ func copyMappings(sourceLineMap, targetLineMap, newMappings map[int]int) {
193187
}
194188
}
195189
}
196-
197-
var expDriveID = regexp.MustCompile("[a-zA-Z]:")
198-
199-
func uriToPath(uri lsp.DocumentURI) string {
200-
urlObj, err := url.Parse(string(uri))
201-
if err != nil {
202-
return string(uri)
203-
}
204-
path := ""
205-
segments := strings.Split(urlObj.Path, "/")
206-
for _, segment := range segments {
207-
decoded, err := url.PathUnescape(segment)
208-
if err != nil {
209-
decoded = segment
210-
}
211-
if runtime.GOOS == "windows" && expDriveID.MatchString(decoded) {
212-
path += strings.ToUpper(decoded)
213-
} else if len(decoded) > 0 {
214-
path += string(filepath.Separator) + decoded
215-
}
216-
}
217-
return path
218-
}

0 commit comments

Comments
 (0)