@@ -9,10 +9,7 @@ import (
99 "github.com/styrainc/regal/internal/lsp/clients"
1010)
1111
12- var (
13- drivePattern = regexp .MustCompile (`^([A-Za-z]):` )
14- drivePatternMaybeEncoded = regexp .MustCompile (`^([A-Za-z])(%3[aA]|:)` )
15- )
12+ var drivePattern = regexp .MustCompile (`^\/?([A-Za-z]):` )
1613
1714// FromPath converts a file path to a URI for a given client.
1815// Since clients expect URIs to be in a specific format, this function
@@ -55,28 +52,20 @@ func FromPath(client clients.Identifier, path string) string {
5552// Some clients represent URIs differently, and so this function exists to convert
5653// client URIs into a standard file paths.
5754func ToPath (client clients.Identifier , uri string ) string {
58- // if the uri appears to be a URI with a file prefix, then remove the prefix
55+ // if it looks like uri was a file URI, then there might be encoded characters in the path
5956 path , hadPrefix := strings .CutPrefix (uri , "file://" )
6057 if hadPrefix {
61- // if it looks like a URI, then try and decode it
62- if decodedPath , err := url .QueryUnescape (path ); err == nil {
58+ // if it looks like a URI, then try and decode the path
59+ decodedPath , err := url .QueryUnescape (path )
60+ if err == nil {
6361 path = decodedPath
6462 }
6563 }
6664
67- if client == clients .IdentifierVSCode {
65+ // handling case for windows when the drive letter is set
66+ if client == clients .IdentifierVSCode &&
67+ drivePattern .MatchString (path ) {
6868 path = strings .TrimPrefix (path , "/" )
69- // handling case for windows when the drive letter is set
70-
71- // TODO; never set?
72- var driveLetter string
73-
74- if matches := drivePatternMaybeEncoded .FindStringSubmatch (path ); len (matches ) > 1 {
75- path = strings .TrimPrefix (path , matches [0 ])
76- path = matches [1 ] + ":" + strings .TrimPrefix (path , driveLetter )
77- } else {
78- path = "/" + path
79- }
8069 }
8170
8271 // Convert path to use system separators
0 commit comments