Skip to content

Commit 22c30ff

Browse files
committed
Fix: WSL path translation
Adds WSL path translation for files located in WSL2 filesystem being opened in Sublime Text via \\wsl.localhost\<distro>\ path.
1 parent ebda24a commit 22c30ff

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

modules/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def work_tree_supported(self):
186186
True if not running in WSL mode or path is a local drive
187187
False if the working tree is no local drive in WSL mode.
188188
"""
189-
return not self._git_wsl or self._git_tree and self._git_tree[1] == ':'
189+
return not self._git_wsl or path.is_translatable_to_wsl(self._git_tree)
190190

191191
def translate_path_to_wsl(self, filename):
192192
"""Translate filename to a WSL compatible unix path on demand.

modules/path.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os.path
2+
import re
23

34
try:
45
from nt import _getfinalpathname
@@ -93,6 +94,13 @@ def split_work_tree(file_path):
9394
return (None, None)
9495

9596

97+
def is_translatable_to_wsl(path):
98+
return path and (
99+
path.startswith('\\\\wsl.localhost\\')
100+
or not path.startswith('\\\\')
101+
)
102+
103+
96104
def translate_to_wsl(path):
97105
"""Translate a windows path to unix path for WSL.
98106
@@ -113,7 +121,10 @@ def translate_to_wsl(path):
113121
Raises:
114122
FileNotFoundError: if path is an UNC path.
115123
"""
116-
if path.startswith('\\\\'):
124+
# remove UNC prefix for paths pointing to WSL environment
125+
if path.startswith('\\\\wsl.localhost\\'):
126+
wsl_path = re.sub(r"\\\\wsl\.localhost\\[^\\]*", "", path)
127+
elif path.startswith('\\\\'):
117128
raise FileNotFoundError('UNC paths are not supported by WSL!')
118129
wsl_path = path.replace('\\', '/')
119130
if wsl_path[1:3] == ':/':

0 commit comments

Comments
 (0)