Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
feat: add development mode
Browse files Browse the repository at this point in the history
Set g:pf_dev_server_console to a command used to run something in a new
console (e.g. konsole -e). This is used to view what the server Vim is doing
when debugging or adding new features.
  • Loading branch information
danth committed May 31, 2020
1 parent 153bc87 commit a083493
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
35 changes: 24 additions & 11 deletions python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,30 @@ def open(self):
os.path.join(os.path.dirname(__file__), "..", "serverrc.vim")
)
# Launch the server as described above
self.server_process = subprocess.Popen(
(
"vim",
"--not-a-term",
"--cmd",
f"let g:pf_server_communiation_file='{self.file_path}'",
"-u",
vimrc_path,
),
stdout=subprocess.DEVNULL,
)
if vim.vars.get("pf_dev_server_console"):
self.server_process = subprocess.Popen(
vim.eval("g:pf_dev_server_console").split(" ") + [
"vim",
"--cmd",
f"let g:pf_server_communiation_file='{self.file_path}'",
"--cmd",
"let g:pf_dev_server_console=1",
"-u",
vimrc_path,
],
)
else:
self.server_process = subprocess.Popen(
(
"vim",
"--not-a-term",
"--cmd",
f"let g:pf_server_communiation_file='{self.file_path}'",
"-u",
vimrc_path,
),
stdout=subprocess.DEVNULL,
)

# poll_responses will see this is None and look for the ability to connect
# instead of received messages
Expand Down
7 changes: 7 additions & 0 deletions python/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def message_loop(self):
if not self.client_connection.poll():
self.do_action(data)
except:
self._dev_redraw()
# Send any unexpected exceptions back to the client
# to be displayed for debugging purposes
self.client_connection.send(("ERROR", traceback.format_exc()))
Expand All @@ -72,6 +73,7 @@ def do_action(self, data):
vim.options["columns"] = int(data["size"][0])
vim.options["lines"] = vim.options["cmdheight"] + int(data["size"][1])

self._dev_redraw()
self.pathfind()

def pathfind(self):
Expand All @@ -85,6 +87,11 @@ def pathfind(self):
if not (motions is None or self.client_connection.poll()):
self.client_connection.send(("RESULT", motions))

def _dev_redraw(self):
"""Call redraw if development mode is set."""
if vim.vars.get("pf_dev_server_console"):
vim.command("redraw")


server = Server(vim.vars["pf_server_communiation_file"])
server.run()

0 comments on commit a083493

Please sign in to comment.