Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Xdebug.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,30 @@

// Determine which URL to launch in the default web browser
// when starting/stopping a session.
// 1. use a local web server
// 'url' is the web server's domain name
// 'website_root' is the web server's absolute local root path
// 'url' is is binded to 'website_root'
//
// 2. use a remote web server
// 'url' must be set to debugged file's remote full url.
// 'website_root' must be set to empty.
//
// Example:
// 1. use a local web server
// If 'loc.dev' is binded to '/var/www/htdocs/', then set as follow.
// "url": "http://loc.dev",
// "website_root" : "/var/www/htdocs/",
//
// If you are debugging file '/var/www/htdocs/www1/db.php', it will open
// 'http://loc.dev/www1/db.php?XDEBUG_SESSION_START=$ide_key' in the Browser
// using 'Xdebug: Start Debugging (Launch Browser)' command
//
// 2. use a remote web server
// "url": "http://loc.dev/www1/db.php",
// "website_root" : "",
"url": "",
"website_root" : "",

// An IDE key is used to identify with debugger engine
// when Sublime Text will start or stop a debugging session.
Expand Down Expand Up @@ -132,4 +155,4 @@
// between debugger engine and Sublime Text.
// Log can be found at Packages/User/Xdebug.log
"debug": false
}
}
52 changes: 10 additions & 42 deletions xdebug/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

KEY_PATH_MAPPING = "path_mapping"
KEY_URL = "url"
KEY_WEBSITE_ROOT = "website_root"
KEY_IDE_KEY = "ide_key"
KEY_PORT = "port"
KEY_SUPER_GLOBALS = "super_globals"
Expand Down Expand Up @@ -55,17 +56,9 @@
REGION_SCOPE_CURRENT = 'string.quoted.settings'

# Window layout for debugging output
LAYOUT_DEBUG = {
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 0.7, 1.0],
"cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]
}
LAYOUT_DEBUG = {"cols": [0.0, 0.5, 1.0], "rows": [0.0, 0.7, 1.0], "cells": [[0, 0, 2, 1], [0, 1, 1, 2], [1, 1, 2, 2]]}
# Default single layout (similar to Alt+Shift+1)
LAYOUT_NORMAL = {
"cols": [0.0, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1]]
}
LAYOUT_NORMAL = {"cols": [0.0, 1.0], "rows": [0.0, 1.0], "cells": [[0, 0, 1, 1]]}

RESTORE_LAYOUT = None
RESTORE_INDEX = None
Expand All @@ -88,35 +81,10 @@
CONFIG_PROJECT = None
CONFIG_PACKAGE = None
CONFIG_KEYS = [
KEY_PATH_MAPPING,
KEY_URL,
KEY_IDE_KEY,
KEY_PORT,
KEY_SUPER_GLOBALS,
KEY_MAX_CHILDREN,
KEY_MAX_DATA,
KEY_MAX_DEPTH,
KEY_BREAK_ON_START,
KEY_BREAK_ON_EXCEPTION,
KEY_CLOSE_ON_STOP,
KEY_HIDE_PASSWORD,
KEY_PRETTY_OUTPUT,
KEY_LAUNCH_BROWSER,
KEY_BROWSER_NO_EXECUTE,
KEY_DISABLE_LAYOUT,
KEY_DEBUG_LAYOUT,
KEY_BREAKPOINT_GROUP,
KEY_BREAKPOINT_INDEX,
KEY_CONTEXT_GROUP,
KEY_CONTEXT_INDEX,
KEY_STACK_GROUP,
KEY_STACK_INDEX,
KEY_WATCH_GROUP,
KEY_WATCH_INDEX,
KEY_BREAKPOINT_CURRENT,
KEY_BREAKPOINT_DISABLED,
KEY_BREAKPOINT_ENABLED,
KEY_CURRENT_LINE,
KEY_PYTHON_PATH,
KEY_DEBUG
]
KEY_PATH_MAPPING, KEY_URL, KEY_IDE_KEY, KEY_PORT, KEY_SUPER_GLOBALS, KEY_MAX_CHILDREN, KEY_MAX_DATA, KEY_MAX_DEPTH,
KEY_BREAK_ON_START, KEY_BREAK_ON_EXCEPTION, KEY_CLOSE_ON_STOP, KEY_HIDE_PASSWORD, KEY_PRETTY_OUTPUT,
KEY_LAUNCH_BROWSER, KEY_BROWSER_NO_EXECUTE, KEY_DISABLE_LAYOUT, KEY_DEBUG_LAYOUT, KEY_BREAKPOINT_GROUP,
KEY_BREAKPOINT_INDEX, KEY_CONTEXT_GROUP, KEY_CONTEXT_INDEX, KEY_STACK_GROUP, KEY_STACK_INDEX, KEY_WATCH_GROUP,
KEY_WATCH_INDEX, KEY_BREAKPOINT_CURRENT, KEY_BREAKPOINT_DISABLED, KEY_BREAKPOINT_ENABLED, KEY_CURRENT_LINE,
KEY_PYTHON_PATH, KEY_DEBUG
]
48 changes: 41 additions & 7 deletions xdebug/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def get_real_path(uri, server=False):

TODO: Fix mapping for root (/) and drive letters (P:/)
"""
# A flag used to fix mapping for root (/) and drive letters (P:/)
flag = '/#FLG'

if uri is None:
return uri

Expand All @@ -45,12 +48,12 @@ def get_real_path(uri, server=False):
try:
# scheme:///path/file => scheme, /path/file
# scheme:///C:/path/file => scheme, C:/path/file
transport, filename = uri.split(':///', 1)
transport, filename = uri.split(':///', 1)
except:
filename = uri

# Normalize path for comparison and remove duplicate/trailing slashes
uri = os.path.normpath(filename)
uri = flag + os.path.normpath(filename)

# Pattern for checking if uri is a windows path
drive_pattern = re.compile(r'^[a-zA-Z]:[\\/]')
Expand All @@ -69,24 +72,25 @@ def get_real_path(uri, server=False):
if server:
# Map local path to server path
if local_path in uri:
uri = uri.replace(local_path, server_path)
uri = uri.replace(flag + local_path, server_path)
break
else:
# Map server path to local path
if server_path in uri:
uri = uri.replace(server_path, local_path)
uri = uri.replace(flag + server_path, local_path)
break
else:
sublime.set_timeout(lambda: sublime.status_message("Xdebug: No path mapping defined, returning given path."), 100)

uri = os.path.normpath(uri)

# Replace slashes
if not drive_pattern.match(uri):
uri = uri.replace("\\", "/")

# Append scheme
if server:
return H.url_encode("file://" + uri)

return uri


Expand Down Expand Up @@ -180,9 +184,39 @@ def get_region_icon(icon):
info("Invalid icon name. (" + icon + ")")
return

def get_server_url():
"""
Get server url

def launch_browser():
Keyword arguments:
None

"""
# Local path of the file being debuged
filename = sublime.active_window().active_view().file_name()
filename = '#flg-' + filename.replace("\\", "/")

# Get server url
url = get_value(S.KEY_URL)
if url is None:
url = 'http://localhost'
url = url.rstrip('/')

website_root = get_value(S.KEY_WEBSITE_ROOT)
print('Debug1: website_root = %s' % website_root)
if website_root:
website_root = '#flg-' + os.path.normpath(website_root).replace("\\", "/").rstrip('/')
if website_root in filename:
url = filename.replace(website_root, url)
print('Debug1: filename = %s' % filename)
print('Debug1: website_root2 = %s' % website_root)
print('Debug1: url = %s' % url)

return url


def launch_browser():
url = get_server_url()
if not url:
sublime.set_timeout(lambda: sublime.status_message('Xdebug: No URL defined in (project) settings file.'), 100)
return
Expand Down Expand Up @@ -282,4 +316,4 @@ def save_breakpoint_data():
def save_watch_data():
data_path = os.path.join(sublime.packages_path(), 'User', S.FILE_WATCH_DATA)
with open(data_path, 'wb') as data:
data.write(H.data_write(json.dumps(S.WATCH)))
data.write(H.data_write(json.dumps(S.WATCH)))