From 9a0de71aa3051d054dd2bbdc3286b82d32d6d629 Mon Sep 17 00:00:00 2001 From: David <2889367+daveleroy@users.noreply.github.com> Date: Mon, 21 Feb 2022 20:58:24 -0800 Subject: [PATCH] Improved snippet conversions --- modules/adapters_registry.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/adapters_registry.py b/modules/adapters_registry.py index 44659496..018b99a2 100644 --- a/modules/adapters_registry.py +++ b/modules/adapters_registry.py @@ -162,12 +162,25 @@ async def install_menu(log: core.Logger = core.stdio): @staticmethod async def _insert_snippet(window: sublime.Window, snippet: dict[str, Any]): + for (key, value) in snippet.items(): + if isinstance(value, str) and value.startswith('^"') and value.endswith('"'): + snippet[key] = value[2:-1] + content = json.dumps(snippet, indent="\t") content = content.replace('\\\\', '\\') # remove json encoded \ ... - project = window.project_file_name() - if project: + content = content.replace('${workspaceFolder}', '${folder}') + + try: + + project = window.project_file_name() + if not project: + raise core.Error('Expected project file in window') + view = await core.sublime_open_file_async(window, project) region = view.find(r'''"\s*debugger_configurations\s*"\s*:\s*\[''', 0) + if not region: + raise core.Error('Unable to find debugger_configurations') + view.sel().clear() view.sel().add(sublime.Region(region.b, region.b)) view.run_command('insert', { @@ -176,7 +189,7 @@ async def _insert_snippet(window: sublime.Window, snippet: dict[str, Any]): view.run_command('insert_snippet', { 'contents': content + ',' }) - else: + except core.Error as e: sublime.set_clipboard(content) core.display('Unable to insert configuration into sublime-project file: Copied to clipboard instead')