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

feat: Add editor specific commands to go menu #277

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions biscuit/core/components/editors/texteditor/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def config_bindings(self):
self.bind("<<Selection>>", self.on_selection)
self.bind("<Control-KeyPress>", lambda _: self.set_ctrl_key(True))
self.bind("<Control-KeyRelease>", lambda _: self.set_ctrl_key(False))
self.bind("<Control-Button-1>", self.request_goto_definition)
self.bind("<Control-Button-1>", self.request_definition)
self.bind("<Control-period>", lambda _: self.base.language_server_manager.request_completions(self))

def key_release_events(self, event: tk.Event):
Expand Down Expand Up @@ -542,14 +542,14 @@ def set_ctrl_key(self, flag):
def clear_goto_marks(self):
self.tag_remove("hyperlink", 1.0, tk.END)

def request_goto_definition(self, e: tk.Event):
if not self.lsp or not self.last_hovered:
def request_definition(self, from_menu=False, *_):
if not from_menu and (not self.lsp or not self.last_hovered):
return

self.base.language_server_manager.request_goto_definition(self)

def request_references(self, e: tk.Event):
if not self.lsp or not self.last_hovered:
def request_references(self, from_menu=False, *_):
if not from_menu and (not self.lsp or not self.last_hovered):
return

self.base.language_server_manager.request_references(self)
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/floating/palette/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def show_items(self, items: list[PaletteItem]) -> None:

self.reset_selection()

def show(self, prefix: str, default: str=None) -> None:
def show(self, prefix: str=None, default: str=None) -> None:
"""Shows the palette with the passed prefix"""
self.update_idletasks()

Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/floating/palette/searchbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def clear(self) -> None:
def focus(self) -> None:
self.search_bar.focus()

def add_prefix(self, prefix: str) -> None:
def add_prefix(self, prefix: str=None) -> None:
self.prefix = prefix
self.text_variable.set(prefix + " " if prefix else "")
self.search_bar.icursor(tk.END)
Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/lsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, base: App):

self.langservers: dict[str, str] = {}
# built-in support for python-lsp-server
self.langservers["python"] = "pylsp"
self.langservers["Python"] = "pylsp"

self.existing: dict[str, LangServerClient] = {}
self.latest: LangServerClient = None
Expand Down
26 changes: 21 additions & 5 deletions biscuit/core/components/lsp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,34 +140,50 @@ def request_go_to_definition(self, tab: Text) -> None:
if tab.path is None or self.client.state != lsp.ClientState.NORMAL:
return

# very bad hack to ignore mouse and use cursor position
tab.focus_set()
pos = tab.get_mouse_pos()
if pos == '1.0':
pos = tab.get_cursor_pos()

request_id = self.client.definition(
lsp.TextDocumentPosition(
textDocument=lsp.TextDocumentIdentifier(uri=Path(tab.path).as_uri()),
position=encode_position(tab.get_mouse_pos()),
position=encode_position(pos),
)
)
self._gotodef_requests[request_id] = (tab, tab.get_mouse_pos())
self._gotodef_requests[request_id] = (tab, pos)

def request_references(self, tab: Text) -> None:
if tab.path is None or self.client.state != lsp.ClientState.NORMAL:
return

tab.focus_set()
pos = tab.get_mouse_pos()
if pos == '1.0':
pos = tab.get_cursor_pos()

request_id = self.client.references(
lsp.TextDocumentPosition(
textDocument=lsp.TextDocumentIdentifier(uri=Path(tab.path).as_uri()),
position=encode_position(tab.get_cursor_pos()),
position=encode_position(pos),
)
)
self._ref_requests.append((tab, tab.get_mouse_pos()))
self._ref_requests.append((tab, pos))

def request_rename(self, tab: Text, new_name: str) -> None:
if tab.path is None or self.client.state != lsp.ClientState.NORMAL:
return

tab.focus_set()
pos = tab.get_mouse_pos()
if pos == '1.0':
pos = tab.get_cursor_pos()

request_id = self.client.rename(
lsp.TextDocumentPosition(
textDocument=lsp.TextDocumentIdentifier(uri=Path(tab.path).as_uri()),
position=encode_position(tab.get_cursor_pos()),
position=encode_position(pos),
),
new_name=new_name,
)
Expand Down
15 changes: 14 additions & 1 deletion biscuit/core/layout/menubar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def add_menus(self) -> None:
self.add_edit_menu()
self.add_selection_menu()
self.add_view_menu()
self.add_go_menu()
self.add_help_menu()

def add_file_menu(self) -> None:
Expand Down Expand Up @@ -163,7 +164,7 @@ def add_view_menu(self) -> None:
events = self.events

self.view_menu = self.add_menu("View")
self.view_menu.add_item("Command Palette...", lambda: self.base.palette.show(">"))
self.view_menu.add_item("Command Palette...", events.show_command_palette)
self.view_menu.add_item("Explorer", events.show_explorer)
self.view_menu.add_item("Outline", events.show_outline)
self.view_menu.add_item("Search", events.show_search)
Expand All @@ -172,6 +173,18 @@ def add_view_menu(self) -> None:
self.view_menu.add_separator()
self.view_menu.add_item("Terminal", events.show_terminal)
self.view_menu.add_item("Log", events.show_logs)

def add_go_menu(self) -> None:
events = self.events

self.view_menu = self.add_menu("Go")
self.view_menu.add_item("Go to File...", events.show_file_search_palette)
self.view_menu.add_separator()
self.view_menu.add_item("Go to Symbol in Editor", events.show_symbol_palette)
self.view_menu.add_item("Go to Definition", events.go_to_definition)
self.view_menu.add_item("Go to References", events.find_references)
self.view_menu.add_separator()
self.view_menu.add_item("Go to Line/Column...", events.show_goto_palette)

def add_help_menu(self) -> None:
events = self.events
Expand Down
17 changes: 16 additions & 1 deletion biscuit/core/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ def duplicate_selection(self, *_) -> None:
if editor := self.base.editorsmanager.active_editor:
if editor.content and editor.content.editable:
editor.content.text.event_duplicate_selection()

def go_to_definition(self, *_) -> None:
if editor := self.base.editorsmanager.active_editor:
if editor.content and editor.content.editable:
editor.content.text.request_definition(from_menu=True)

def find_references(self, *_) -> None:
if editor := self.base.editorsmanager.active_editor:
if editor.content and editor.content.editable:
editor.content.text.request_references(from_menu=True)

def rename_symbol(self, *_) -> None:
if editor := self.base.editorsmanager.active_editor:
if editor.content and editor.content.editable:
editor.content.text.request_rename()

def show_explorer(self, *_) -> None:
self.base.sidebar.show_explorer()
Expand Down Expand Up @@ -272,7 +287,7 @@ def show_run_config_palette(self, command) -> None:
self.base.palette.show('runconf:', command)

def show_file_search_palette(self, *_) -> None:
self.base.palette.show("")
self.base.palette.show()

def documentation(self, *_) -> None:
web.open("https://billyeatcookies.github.io/biscuit/")
Expand Down
Loading