Skip to content

Commit

Permalink
Improved snippet conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleroy committed Feb 22, 2022
1 parent b4211f5 commit 9a0de71
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions modules/adapters_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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')

Expand Down

0 comments on commit 9a0de71

Please sign in to comment.