Sublime Forum

lookup_symbol_in_index and filename problem in Windows

#1

Hi folks !

I’m the author of the PHPCompanion plugin and I have a strange issue on windows platform.

Basically the problem is that Python can’t open a unix-like filename on Windows. The filename I use is given by the lookup_symbol_in_index method and the error look like :

FileNotFoundError: [Errno 2] No such file or directory: '/C/wamp/www/subdomains/laravel-develop/vendor/laravel/framework/src/Illuminate/Routing/Route.php'

Maybe I need some sort of path conversion but I can’t find any clue on the web. Any ideas ?

0 Likes

#2

Think this would work, but you should probably test it just to make sure. I’m far from a regex expert, so there’s probably a better way to do it. Perhaps someone will post it.

win_path = re.sub(r"/([A-Za-z])/(.+)", r"\1:/\2", nix_path) win_path = re.sub(r"/", r"\\", win_path)

It converts the posted path to C:\wamp\www\subdomains\laravel-develop\vendor\laravel\framework\src\Illuminate\Routing\Route.php

0 Likes

#3

Hi,

I would like to avoid platform specific code. Your solution may work on Window but not on Unix system.

0 Likes

#4

True, but since I’m sure you would want to get your plugin up and running in for windows users also, wouldn’t it be beneficial to have a short term solution like this?

def normalize_to_system_style_path(path)
    if sublime.platform() == "windows":
        path= re.sub(r"/([A-Za-z])/(.+)", r"\1:/\2", path)
        path= re.sub(r"/", r"\\", path)
    return path

Then if/when the API return value gets changed, you can remove this method?

0 Likes

#5

Yeah, you’re right.

Your code works fine, thank for the help :smile:

0 Likes

#6

bump

Is this a bug?

sublime.active_window().lookup_symbol_in_open_files("ClassName")

# on linux:
=> [('/path/to/src/ClassName.php', 'src/ClassName.php', (5, 13))]

# on windows:
=> [('/C/path/to/src/ClassName.php', 'src/ClassName.php', (5, 13))]

/C/path/to/src/ClassName.php' on windows is not a valid absolute path.

Is this a bug or is there a better way to normalise the path.

0 Likes

#7

@gerry: I happen to know about this because it came up in an issue I raised a while back: https://github.com/SublimeTextIssues/Core/issues/1246

As you can see this was fixed in Build 3118.

2 Likes

#8

Thanks. I was using the last beta. I still think there’s an issue. The absolute path looks fixed but the relative one is still broken:

sublime.active_window().lookup_symbol_in_open_files("ClassName")

# on linux:
=> [('/path/to/src/ClassName.php', 'src/ClassName.php', (5, 13))]

# on windows:
=> [('/C/path/to/src/ClassName.php', 'src\ClassName.php', (5, 13))]

I’ll go report it on that issue.

0 Likes