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

Update to work with newer VSCode Server folder structure + dual installation fix #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions bash/code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# alias code="/path/to/code.sh"

local_code_executable="$(which code 2>/dev/null)"
if test -n "$local_code_executable"; then
# code is in the PATH, use that binary instead of the code-connect
if [ -n "$local_code_executable" ] && ! ( [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ] ); then
# code is in the PATH and we're not in an SSH session, use that binary instead of the code-connect
$local_code_executable $@
else
# code not locally installed, use code-connect
Expand Down
23 changes: 14 additions & 9 deletions bin/code_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def is_socket_open(path: Path) -> bool:

def sort_by_access_timestamp(paths: Iterable[Path]) -> List[Tuple[float, Path]]:
""" Returns a list of tuples (last_accessed_ts, path) sorted by the former. """
paths = [(p.stat().st_atime, p) for p in paths]
paths = sorted(paths, reverse=True)
return paths
return sorted([(p.stat().st_atime, p) for p in paths], reverse=True)


def next_open_socket(socks: Sequence[Path]) -> Path:
Expand All @@ -68,17 +66,24 @@ def get_code_binary() -> Path:

# Every entry in ~/.vscode-server/bin corresponds to a commit id
# Pick the most recent one
code_repos = sort_by_access_timestamp(Path.home().glob(".vscode-server/bin/*"))
if len(code_repos) == 0:
code_bins = []
for root, dirs, files in os.walk(str(Path.home()) + "/.vscode-server/"):
if "code" in files:
result = sp.run([root+"/code"], stdout=sp.PIPE, stderr=sp.PIPE)
if result.stdout == b'Command is only available in WSL or inside a Visual Studio Code terminal.\n':
code_bins += [Path(root+"/code")]

if len(code_bins) == 0:
fail(
"No installation of VS Code Server detected!",
"No VS Code remote-cli detected!",
"",
"Please connect to this machine through a remote SSH session and try again.",
"Afterwards there should exist a folder under ~/.vscode-server",
"Afterwards there should exist a folder under ~/.vscode-server/cli/servers/",
)

_, code_repo = code_repos[0]
return code_repo / "bin" / "remote-cli" / "code"
_, code_bin = sort_by_access_timestamp(code_bins)[0]

return code_bin


def get_ipc_socket(max_idle_time: int = DEFAULT_MAX_IDLE_TIME) -> Path:
Expand Down