Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand variables on initializationOptions #709

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions plugin/core/clients.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sublime
import os
import tempfile
from .sessions import create_session, Session

# typing only
Expand Down Expand Up @@ -36,6 +37,26 @@ def get_window_env(window: sublime.Window, config: ClientConfig) -> 'Tuple[List[
return expanded_args, env


def get_expanding_variables(window: sublime.Window) -> dict:
variables = window.extract_variables()
variables.update({
"home": os.path.expanduser('~'),
"temp_dir": tempfile.gettempdir(),
})

return variables


def expand_variables_for_dict(window: sublime.Window, dict_: dict) -> dict:
jfcherng marked this conversation as resolved.
Show resolved Hide resolved
for key, value in dict_.items():
if isinstance(value, dict):
dict_[key] = expand_variables_for_dict(window, value)
elif isinstance(value, str):
dict_[key] = sublime.expand_variables(value, get_expanding_variables(window))

return dict_


def start_window_config(window: sublime.Window,
project_path: str,
config: ClientConfig,
Expand All @@ -44,6 +65,7 @@ def start_window_config(window: sublime.Window,
on_post_exit: 'Callable[[str], None]') -> 'Optional[Session]':
args, env = get_window_env(window, config)
config.binary_args = args
config.init_options = expand_variables_for_dict(window, config.init_options)
return create_session(config=config,
project_path=project_path,
env=env,
Expand Down