Skip to content

Commit

Permalink
Merge pull request #137 from risingphoenix/master
Browse files Browse the repository at this point in the history
import namespace: correct paths on windows systems
  • Loading branch information
erichard authored Feb 5, 2020
2 parents 85f69d0 + 5ede58f commit 329563a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion php_companion/commands/import_namespace_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ImportNamespaceCommand(sublime_plugin.TextCommand):
def run(self, edit):
projectPath = get_active_project_path()
file_name = self.view.file_name().replace(projectPath, '')
if file_name.startswith('/'):
if file_name.startswith('/') or file_name.startswith('\\'):
file_name = file_name[1:]

# Abort if the file is not PHP
Expand Down
6 changes: 4 additions & 2 deletions php_companion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,19 @@ def get_composer():
def get_namespace(filename):
data = get_composer()
for _replace_with, _path in data['autoload']['psr-4'].items():
_path = normalize_to_system_style_path(_path)
if _path.startswith('./'):
_path = _path[2:]
_path = _path[2:]

if filename.startswith(_path):
namespace = filename.replace(_path, _replace_with)
namespace = re.sub('/', '\\\\', namespace)
return namespace.strip("\\").replace('\\\\', '\\')

for _replace_with, _path in data['autoload-dev']['psr-4'].items():
_path = normalize_to_system_style_path(_path)
if _path.startswith('./'):
_path = _path[2:]
_path = _path[2:]

if filename.startswith(_path):
namespace = filename.replace(_path, _replace_with)
Expand Down

0 comments on commit 329563a

Please sign in to comment.