Skip to content

Commit

Permalink
Some general cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleroy committed Mar 10, 2024
1 parent 89e84ed commit 805614b
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 92 deletions.
12 changes: 6 additions & 6 deletions modules/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,20 @@ def write(self, text: str, color: str | None, ensure_new_line=False, ignore_inde
self.color = color

def write_variable(self, variable: dap.Variable, at: int, last: bool = True):
html = f'''
html = '''
<style>
html {{
html {
background-color: var(--background);
}}
a {{
}
a {
color: color(var(--foreground) alpha(0.25));
text-decoration: none;
padding-left: 0.0rem;
padding-right: 0.0rem;
}}
}
</style>
<body id="debugger">
<a href="">{ui.html_escape(f'❯')}</a>
<a href=""></a>
</body>
'''

Expand Down
17 changes: 3 additions & 14 deletions modules/core/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def cancel(self):
self.callback = None
self.args = None

class SublimeEventLoop (asyncio.AbstractEventLoop):
class SublimeEventLoop (asyncio.BaseEventLoop):
def is_running(self):
return True

Expand All @@ -120,6 +120,8 @@ def create_future(self):
# Method scheduling a coroutine object: create a task.
def create_task(self, coro): #type: ignore
task = asyncio.tasks.Task(coro, loop=self)
task._log_destroy_pending = False #type: ignore

if task._source_traceback: #type: ignore
del task._source_traceback[-1] #type: ignore
return task
Expand All @@ -130,19 +132,6 @@ def call_soon_threadsafe(self, callback, *args): #type: ignore
sublime.set_timeout(handle, 0)
return handle

def call_exception_handler(self, context):
from .log import exception
from .error import Error

try:
if 'exception' in context:
raise context['exception']
else:
raise Error(context['message'])

except Exception as e:
exception()

# Debug flag management.
def get_debug(self):
return False
Expand Down
15 changes: 3 additions & 12 deletions modules/core/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations
from typing import Any, Awaitable, Callable, Coroutine, Generator, Generic, Iterable, Protocol, TypeVar, overload
from .typing_extensions import TypeVarTuple, Unpack, ParamSpec
from typing import Any, Callable, Protocol, TypeVar

from .log import error

import sublime
import concurrent


D = TypeVar("D", bound="Disposeable")
Expand Down Expand Up @@ -41,15 +41,6 @@ def dispose_add(self, *items: Disposeable|list[Disposeable]):
else:
self._dispose.append(item)

if not self._dispose:
self._dispose = []

if isinstance(item, list):
for i in item:
self._dispose.append(i)
else:
self._dispose.append(item)



def remove_and_dispose(list: list[D], filter: Callable[[D], bool]):
Expand Down
4 changes: 3 additions & 1 deletion modules/core/typing_extensions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Any, TypeVar, Generic

try:
from typing_extensions import Unpack, TypeVarTuple, ParamSpec, TypeAlias
from typing_extensions import Unpack, TypeVarTuple, ParamSpec, TypeAlias, Concatenate

except ImportError as e:

class _GetAttr(type):
Expand All @@ -16,5 +17,6 @@ class _Generic(metaclass=_GetAttr):
globals()['ParamSpec'] = TypeVar
globals()['TypeAlias'] = TypeVar

globals()['Concatenate'] = _Generic
globals()['Unpack'] = _Generic
globals()['Generic'] = _Generic
1 change: 0 additions & 1 deletion modules/dap/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def __init__(self, session: Session, name: str, value: str|None, variablesRefere

@staticmethod
def from_variable(session: Session, containerVariablesReference: int, variable: dap.Variable):

return Variable(
session,
variable.name,
Expand Down
16 changes: 9 additions & 7 deletions modules/disassemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ def __init__(self, window: sublime.Window, debugger: dap.Debugger):
self.view.assign_syntax(core.package_path_relative('contributes/Syntax/Disassembly.sublime-syntax'))

settings = self.view.settings()
settings.set('debugger', True)
settings.set('debugger.view', True)
settings.set('debugger.view.disassemble', True)

settings.set('gutter', False)
settings.set('rulers', [])
settings.set('word_wrap', False)
settings.update({
'debugger': True,
'debugger.view': True,
'debugger.view.disassemble': True,

'gutter': False,
'rulers': [],
'word_wrap': False,
})

self.debugger = debugger

Expand Down
1 change: 1 addition & 0 deletions modules/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def clear(self):

def dispose(self):
self.clear()
self.window = None

def view_for_session(self, session: dap.Session|None):
if view := self.views.get(session):
Expand Down
4 changes: 2 additions & 2 deletions modules/source_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def clear_generated_view(self):

async def navigate_to_source(self, source: dap.SourceLocation, move_cursor: bool = False) -> sublime.View:
# Check if adapter want to provide content
if self.debugger.session:
adapter_content = await self.debugger.session.adapter_configuration.on_navigate_to_source(source)
if session := self.debugger.session:
adapter_content = await session.adapter_configuration.on_navigate_to_source(source)
else:
adapter_content = None

Expand Down
2 changes: 1 addition & 1 deletion modules/ui/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def disable(self):
class InputText(sublime_plugin.TextInputHandler):
id = 0

def __init__(self, run: Callable[[str], None] | InputList | InputText, placeholder: str|None = None, initial: str|None = None, enable_when_active: InputEnable|None = None):
def __init__(self, run: Callable[[str], Any] | InputList | InputText, placeholder: str|None = None, initial: str|None = None, enable_when_active: InputEnable|None = None):
super().__init__()
self._placeholder = placeholder
self._initial = initial
Expand Down
104 changes: 56 additions & 48 deletions modules/views/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,82 +47,90 @@ def __init__(self, debugger: Debugger, variable: dap.Variable, state = VariableV
self.set_expanded()

@core.run
async def edit_variable(self) -> None:
if not self.variable.containerVariablesReference:
raise core.Error('Not able to set value of this item')

containerVariablesReference = self.variable.containerVariablesReference
session = self.variable.session
info = None
name = self.variable.name
expression = self.variable.name
async def copy_value(self):
value = self.variable.value or ''
session = self.variable.session
evaluateName = self.variable.evaluateName

if session.capabilities.supportsDataBreakpoints:
info = await session.data_breakpoint_info(containerVariablesReference, name)

async def on_edit_variable_async(value: str):
if evaluateName:
try:
response = await session.set_variable(containerVariablesReference, name, value)
self.variable.value = response.value
self.variable.variablesReference = response.variablesReference
self.variable.fetched = None
self.dirty()
except core.Error as e:
# Attempt to match vscode behavior
# If the adapter supports clipboard use it otherwise send the none standard 'variables' context
context = 'clipboard' if session.capabilities.supportsClipboardContext else 'variables'
v = await self.variable.session.evaluate_expression(evaluateName, context)
sublime.set_clipboard(v.result)
return

except dap.Error as e:
core.exception()
core.display(e)

def on_edit_variable(value: str):
core.run(on_edit_variable_async(value))
sublime.set_clipboard(value)

def copy_expr(self):
expression = self.variable.name
sublime.set_clipboard(expression)

def add_watch(self):
expression = self.variable.name
self.variable.session.watch.add(expression)

@core.run
async def on_edit_variable(self, value: str):
try:
if not self.variable.containerVariablesReference:
raise core.Error('Not able to set value of this item')

@core.run
async def copy_value():
session = self.variable.session
if evaluateName:
try:
# Attempt to match vscode behavior
# If the adapter supports clipboard use it otherwise send the none standard 'variables' context
context = 'clipboard' if session.capabilities.supportsClipboardContext else 'variables'
v = await self.variable.session.evaluate_expression(evaluateName, context)
sublime.set_clipboard(v.result)
return
containerVariablesReference = self.variable.containerVariablesReference
name = self.variable.name

except dap.Error as e:
core.exception()
response = await session.set_variable(containerVariablesReference, name, value)
self.variable.value = response.value
self.variable.variablesReference = response.variablesReference
self.variable.fetched = None
self.dirty()
except core.Error as e:
core.exception()
core.display(e)

sublime.set_clipboard(value)
@core.run
async def edit_variable(self) -> None:
if not self.variable.containerVariablesReference:
raise core.Error('Not able to set value of this item')

def copy_expr():
sublime.set_clipboard(expression)
containerVariablesReference = self.variable.containerVariablesReference
session = self.variable.session
info = None
name = self.variable.name
value = self.variable.value or ''

def add_watch():
session.watch.add(expression)
if session.capabilities.supportsDataBreakpoints:
info = await session.data_breakpoint_info(containerVariablesReference, name)

items = [
ui.InputListItem(
ui.InputText(
on_edit_variable,
self.on_edit_variable,
'editing a variable',
),
'Edit Variable',
'Set Value',
),
ui.InputListItem(
copy_expr,
'Copy Expression',
self.copy_value,
'Copy Value\t Click again to select',
),
ui.InputListItem(
copy_value,
'Copy Value\t Click again to select',
self.copy_expr,
'Copy as Expression',
),
ui.InputListItem(
add_watch,
'Add Variable To Watch',
self.add_watch,
'Add To Watch',
),
]

if self.edit_variable_menu:
copy_value()
self.copy_value()
self.edit_variable_menu.cancel()
return

Expand Down

0 comments on commit 805614b

Please sign in to comment.