Skip to content

Commit

Permalink
find_definition -> definition, get_code_surrounding -> code for LLDB …
Browse files Browse the repository at this point in the history
…only
  • Loading branch information
nicovank committed Mar 11, 2024
1 parent 260233e commit f9ca99e
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/chatdbg/chatdbg_lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,16 @@ def _function_lldb(
result.AppendMessage(_capture_onecmd(debugger, command))


@lldb.command("get_code_surrounding")
def _function_get_code_surrounding(
@lldb.command("code")
def _function_code(
debugger: lldb.SBDebugger,
command: str,
result: lldb.SBCommandReturnObject,
internal_dict: dict,
) -> None:
parts = command.split(":")
if len(parts) != 2:
result.AppendWarning("Usage: get_code_surrounding <filename>:<lineno>")
result.AppendWarning("Usage: code <filename>:<lineno>")
return
filename, lineno = parts[0], int(parts[1])
(lines, first) = llm_utils.read_lines(filename, lineno - 7, lineno + 3)
Expand All @@ -431,28 +431,26 @@ def _function_get_code_surrounding(
_clangd = clangd_lsp_integration.clangd()


@lldb.command("find_definition")
def _function_find_definition(
@lldb.command("definition")
def _function_definition(
debugger: lldb.SBDebugger,
command: str,
result: lldb.SBCommandReturnObject,
internal_dict: dict,
) -> None:
if not clangd_lsp_integration.is_available():
result.AppendWarning("`clangd` is not available.")
result.AppendWarning(
"The `find_definition` function will not be made available."
)
result.AppendWarning("The `definition` function will not be made available.")
return
last_space_index = command.rfind(" ")
if last_space_index == -1:
result.AppendWarning("Usage: find_definition <filename>:<lineno> <symbol>")
result.AppendWarning("Usage: definition <filename>:<lineno> <symbol>")
return
filename_lineno = command[:last_space_index]
symbol = command[last_space_index + 1 :]
parts = filename_lineno.split(":")
if len(parts) != 2:
result.AppendWarning("Usage: find_definition <filename>:<lineno> <symbol>")
result.AppendWarning("Usage: definition <filename>:<lineno> <symbol>")
return
filename, lineno = parts[0], int(parts[1])

Expand Down Expand Up @@ -528,7 +526,7 @@ def get_code_surrounding(filename: str, lineno: int) -> str:
}
"""
result = lldb.SBCommandReturnObject()
_function_get_code_surrounding(debugger, f"{filename}:{lineno}", result, {})
_function_code(debugger, f"{filename}:{lineno}", result, {})
return result.GetOutput()

assistant = LiteAssistant(
Expand Down Expand Up @@ -572,9 +570,7 @@ def find_definition(filename: str, lineno: int, symbol: str) -> str:
}
"""
result = lldb.SBCommandReturnObject()
_function_get_code_surrounding(
debugger, f"{filename}:{lineno} {symbol}", result, {}
)
_function_definition(debugger, f"{filename}:{lineno} {symbol}", result, {})
return result.GetOutput()

assistant.add_function(find_definition)
Expand Down

0 comments on commit f9ca99e

Please sign in to comment.