updated configs
This commit is contained in:
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env zsh
|
||||
#
|
||||
# getting Godot + External vim working requires a little work...
|
||||
#
|
||||
# so this script shadows godot, and handles the spin-up of everything needed!
|
||||
#
|
||||
# After starting `godot`, connect to the `godot` tmux session (and DON'T close the vim over there)
|
||||
#
|
||||
|
||||
GODOT_EXECUTABLE=/usr/bin/godot
|
||||
TMUX_SESSION=godot
|
||||
|
||||
echo.helper() {
|
||||
notify-send 'godot' "${@:2}"
|
||||
echo "${@}\\033[0m" >&2
|
||||
}
|
||||
|
||||
echo.info() { echo.helper "\\033[1;32m" "INFO : ${@}" >&2; }
|
||||
echo.error() { echo.helper "\\033[1;31m" "ERROR : ${@}" >&2; return 1 }
|
||||
echo.warning() { echo.helper "\\033[1;33m" "WARNING : ${@}" >&2; }
|
||||
|
||||
tmux.has-session () {
|
||||
tmux has-session -t "${TMUX_SESSION}" &>/dev/null
|
||||
}
|
||||
|
||||
tmux.has-session && {
|
||||
echo.error "tmux session '${TMUX_SESSION}' already exists; refusing to start godot"
|
||||
exit 1
|
||||
}
|
||||
|
||||
tmux new-session -d -s "${TMUX_SESSION}" -n vim \
|
||||
'sleep 3; while tmux list-windows -t godot -F "#{window_name}" | grep -q lsp-proxy; do vim; echo "vim closed, restarting..."; sleep 1; done'
|
||||
|
||||
tmux new-window -t "${TMUX_SESSION}" -n lsp-proxy \
|
||||
'while true; do ~/.wryn/config/bin/godot-lsp-proxy.py; echo "proxy died, restarting in 2s..."; sleep 2; done'
|
||||
|
||||
tmux select-window -t "${TMUX_SESSION}:0"
|
||||
|
||||
echo.info "godot editor session running on tmux '${TMUX_SESSION}'; connect with tmux.godot"
|
||||
|
||||
"${GODOT_EXECUTABLE}" "$@"
|
||||
GODOT_STATUS=$?
|
||||
|
||||
# godot relaunches itself when opening a project; so we wait for all godot instances to fully exit
|
||||
sleep 3
|
||||
while pgrep -x godot &>/dev/null; do sleep 3; done
|
||||
|
||||
tmux kill-window -t "${TMUX_SESSION}:lsp-proxy"
|
||||
tmux send-keys -t "${TMUX_SESSION}" Escape ':qa' Enter
|
||||
sleep 3
|
||||
|
||||
tmux.has-session && {
|
||||
echo.warning "tmux session '${TMUX_SESSION}' still exists; please connect, save, and close for next connection"
|
||||
}
|
||||
|
||||
exit ${GODOT_STATUS}
|
||||
Executable
+184
@@ -0,0 +1,184 @@
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# godot-lsp-proxy
|
||||
#
|
||||
# TCP proxy that sits between vim (YCM) and Godot's built-in GDScript
|
||||
# language server, rewriting malformed file URIs on the fly.
|
||||
#
|
||||
# THE PROBLEM
|
||||
#
|
||||
# YCM (ycmd) sends LSP document URIs without any slash in protocol:
|
||||
#
|
||||
# file:/home/user/project/script.gd
|
||||
# ^^^^^
|
||||
# prefix 'file:'
|
||||
#
|
||||
# The LSP spec (RFC 3986) requires two slashes after protocol:
|
||||
#
|
||||
# file:///home/user/project/script.gd
|
||||
# ^^^^^^^
|
||||
# prefix 'file://'
|
||||
#
|
||||
# Most language servers are lenient about this, but Godot 4.5+ is
|
||||
# strict and rejects single-slash URIs with:
|
||||
#
|
||||
# ERROR: LSP: The language server only supports the file protocol
|
||||
#
|
||||
# This causes the LSP handshake to fail and Godot drops the
|
||||
# connection. YCM then reports "godotCompleter not running" and you
|
||||
# get zero autocompletion, jump-to-definition, or diagnostics.
|
||||
#
|
||||
# As of 2025-04, there is no config on either side to fix this:
|
||||
# - YCM has no setting to control URI format
|
||||
# - Godot has no setting to relax URI validation
|
||||
#
|
||||
# THE FIX
|
||||
#
|
||||
# This proxy listens on a local port (default 6015), and for every
|
||||
# LSP message FROM the editor TO Godot, rewrites:
|
||||
#
|
||||
# "file:/home/... -> "file:///home/...
|
||||
#
|
||||
# Messages are parsed as proper LSP (Content-Length header + JSON
|
||||
# body), so the Content-Length is recalculated after rewriting to
|
||||
# keep the protocol valid.
|
||||
#
|
||||
# Messages from Godot back to the editor are passed through
|
||||
# unmodified (Godot sends correct triple-slash URIs).
|
||||
#
|
||||
# USAGE
|
||||
#
|
||||
# godot-lsp-proxy [listen_port] [godot_port]
|
||||
#
|
||||
# defaults: listen on 6015, forward to 6005
|
||||
#
|
||||
# Point YCM at the proxy port (6015) instead of Godot's port (6005)
|
||||
# in your vim config:
|
||||
#
|
||||
# let g:ycm_language_server += [
|
||||
# \ { 'name': 'godot',
|
||||
# \ 'filetypes': ['gdscript'],
|
||||
# \ 'project_root_files': ['project.godot'],
|
||||
# \ 'port': 6015 }
|
||||
# \ ]
|
||||
#
|
||||
# REMOVAL
|
||||
#
|
||||
# When YCM or Godot fixes the URI handling on their end, delete
|
||||
# this script and point YCM back at port 6005 directly.
|
||||
#
|
||||
import socket
|
||||
import threading
|
||||
import re
|
||||
import sys
|
||||
|
||||
LISTEN_PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 6015
|
||||
GODOT_PORT = int(sys.argv[2]) if len(sys.argv) > 2 else 6005
|
||||
|
||||
|
||||
def fix_uri(data: bytes) -> bytes:
|
||||
return re.sub(rb'"file:/([^/])', rb'"file:///\1', data)
|
||||
|
||||
|
||||
def read_message(sock):
|
||||
header = b''
|
||||
while b'\r\n\r\n' not in header:
|
||||
chunk = sock.recv(1)
|
||||
if not chunk:
|
||||
return None
|
||||
header += chunk
|
||||
|
||||
match = re.search(rb'Content-Length: (\d+)', header)
|
||||
if not match:
|
||||
return None
|
||||
length = int(match.group(1))
|
||||
|
||||
body = b''
|
||||
while len(body) < length:
|
||||
chunk = sock.recv(length - len(body))
|
||||
if not chunk:
|
||||
return None
|
||||
body += chunk
|
||||
|
||||
return body
|
||||
|
||||
|
||||
def send_message(sock, body: bytes):
|
||||
header = f'Content-Length: {len(body)}\r\n\r\n'.encode()
|
||||
sock.sendall(header + body)
|
||||
|
||||
|
||||
def relay(src, dst, label='', transform=None):
|
||||
try:
|
||||
while True:
|
||||
body = read_message(src)
|
||||
if body is None:
|
||||
break
|
||||
if transform:
|
||||
body = transform(body)
|
||||
send_message(dst, body)
|
||||
except Exception as e:
|
||||
print(f' [{label}] connection closed ({e})')
|
||||
finally:
|
||||
try:
|
||||
src.close()
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
dst.close()
|
||||
except Exception:
|
||||
pass
|
||||
print(f' [{label}] relay stopped')
|
||||
|
||||
|
||||
def print_banner():
|
||||
print()
|
||||
print(' godot-lsp-proxy')
|
||||
print(' ===============')
|
||||
print()
|
||||
print(' Workaround for YCM sending malformed file URIs to Godot.')
|
||||
print()
|
||||
print(f' vim (YCM) -> :{LISTEN_PORT} [rewrite file: -> file://] -> :{GODOT_PORT} (Godot LSP)')
|
||||
print(f' vim (YCM) <- :{LISTEN_PORT} [passthrough] <- :{GODOT_PORT} (Godot LSP)')
|
||||
print()
|
||||
print(' Waiting for YCM to connect...')
|
||||
print()
|
||||
|
||||
|
||||
def main():
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
server.bind(('127.0.0.1', LISTEN_PORT))
|
||||
server.listen(1)
|
||||
|
||||
print_banner()
|
||||
|
||||
while True:
|
||||
client, addr = server.accept()
|
||||
print(f' YCM connected from {addr[0]}:{addr[1]}')
|
||||
|
||||
try:
|
||||
godot = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
godot.connect(('127.0.0.1', GODOT_PORT))
|
||||
print(f' Connected to Godot LSP on :{GODOT_PORT}')
|
||||
print(' Proxying LSP messages (ctrl-c to stop)')
|
||||
print()
|
||||
except ConnectionRefusedError:
|
||||
print(f' ERROR: Godot LSP not available on :{GODOT_PORT}')
|
||||
print(f' Is Godot running with the project open?')
|
||||
print()
|
||||
client.close()
|
||||
continue
|
||||
|
||||
threading.Thread(
|
||||
target=relay, args=(client, godot, 'ycm->godot', fix_uri),
|
||||
daemon=True,
|
||||
).start()
|
||||
threading.Thread(
|
||||
target=relay, args=(godot, client, 'godot->ycm'),
|
||||
daemon=True,
|
||||
).start()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
+17
-11
@@ -44,24 +44,30 @@ case $1 in
|
||||
local PROGRAM
|
||||
local ARGS=()
|
||||
case $2 in
|
||||
messages ) PROGRAM=slack ARGS+=(-c Slack --has-statusbar-icon) ;;
|
||||
voice ) PROGRAM=google-voice-desktop ;;
|
||||
ytmusic ) PROGRAM=youtube-music-desktop-app ARGS+=(-c '"YouTube Music Desktop App"' --has-statusbar-icon) ;;
|
||||
( messages ) PROGRAM=slack ARGS+=(-c slack --has-statusbar-icon) ;;
|
||||
( voice ) PROGRAM=google-voice-desktop ;;
|
||||
( ytmusic ) PROGRAM=youtube-music-desktop-app ARGS+=(-c '"YouTube Music Desktop App"' --has-statusbar-icon) ;;
|
||||
( signal ) PROGRAM=signal ;;
|
||||
|
||||
1pass ) PROGRAM=1password ARGS+=(-c 1Password) ;;
|
||||
discord ) PROGRAM=discord ARGS+=(--has-statusbar-icon) ;;
|
||||
obs ) PROGRAM=obs ARGS+=(-c '^obs' -n -l --has-statusbar-icon) ;;
|
||||
pavuctrl ) PROGRAM=pavucontrol ARGS+=(-s 0.5 -c '^Pavucontrol') ;;
|
||||
scrcpy ) PROGRAM=scrcpy ARGS+=(-n -l) ;;
|
||||
spotify ) PROGRAM=youtube-music-desktop-app ARGS+=(-c '"YouTube Music Desktop App"' --has-statusbar-icon) ;;
|
||||
( 1pass ) PROGRAM=1password ARGS+=(-c 1Password) ;;
|
||||
( discord ) PROGRAM=fluxer ARGS+=(-c Fluxer) ;;
|
||||
( obs ) PROGRAM=obs ARGS+=(-c '^obs' -n -l --has-statusbar-icon) ;;
|
||||
( pavuctrl ) PROGRAM=pavucontrol ARGS+=(-s 0.5 -c '^Pavucontrol') ;;
|
||||
( scrcpy ) PROGRAM=scrcpy ARGS+=(-n -l) ;;
|
||||
( spotify ) PROGRAM=youtube-music-desktop-app ARGS+=(-c '"YouTube Music Desktop App"' --has-statusbar-icon) ;;
|
||||
|
||||
* ) PROGRAM=$2 ;;
|
||||
( * ) PROGRAM=$2 ;;
|
||||
esac
|
||||
scwrypts i3 launch or show -- $PROGRAM ${ARGS[@]}
|
||||
;;
|
||||
|
||||
( screenshot )
|
||||
command -v flameshot || notify-send "I3 UTILS" "screenshot application 'flameshot' not available"
|
||||
flameshot gui
|
||||
|
||||
# v13 and below
|
||||
#flameshot gui
|
||||
|
||||
# v14 complicated af
|
||||
flameshot screen --edit --number "$(xdotool getmouselocation | sed 's/^.*screen:\([0-9]\+\) .*$/\1/')"
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user