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

Non-Windows support #3

Open
jrr opened this issue Aug 7, 2018 · 11 comments
Open

Non-Windows support #3

jrr opened this issue Aug 7, 2018 · 11 comments

Comments

@jrr
Copy link

jrr commented Aug 7, 2018

This tool only works on Windows. This makes me sad.

I'll try to find time to work on this in the next week or so, if you'd welcome a PR.

@ThatRendle
Copy link
Member

Hi. I just published 1.0.4 which I think will work on Mac and Linux, please give it a try.

@vasily-kirichenko
Copy link

iMac-Vasily:~ vaskir$ rider
This tool only works on Windows. If this makes you sad, please open an issue at https://github.com/RendleLabs/dotnet-rider-cli

Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '/Users/vaskir/.local/share/JetBrains/Toolbox/apps/Rider'.
   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path)
   at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)
   at RiderLauncher.ToolboxRiderFinder.GetActiveExecutables()+MoveNext() in C:\Labs\rider\dotnet-rider-cli\src\RiderLauncher\ToolboxRiderFinder.cs:line 28
   at System.Linq.OrderedEnumerable`1.TryGetFirst(Boolean& found)
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at RiderLauncher.ToolboxRiderFinder.TryGetLatestActiveExecutable(String& path) in C:\Labs\rider\dotnet-rider-cli\src\RiderLauncher\ToolboxRiderFinder.cs:line 18
   at RiderLauncher.Program.Main(String[] args) in C:\Labs\rider\dotnet-rider-cli\src\RiderLauncher\Program.cs:line 19
Abort trap: 6

@ThatRendle
Copy link
Member

Argh. Looks like my attempt at identifying the operating system was wrong, and also my failure to remove the Windows-only check in Program.cs.

Programming is hard.

Just published 1.0.5 which definitely fixes one of those bugs, and hopefully fixes the other, although I can't test it because I don't have anything but Windows boxes to play with.

@vasily-kirichenko
Copy link

Sorry, man

iMac-Vasily:~ vaskir$ dotnet tool update -g dotnet-rider-cli
Tool 'dotnet-rider-cli' was successfully updated from version '1.0.4' to version '1.0.5'.
iMac-Vasily:~ vaskir$ rider
Couldn't find Rider install location. If this makes you sad, please open an issue at https://github.com/RendleLabs/dotnet-rider-cli
iMac-Vasily:~ vaskir$ 
iMac-Vasily:JetBrains Toolbox vaskir$ pwd 
/Users/vaskir/Applications/JetBrains Toolbox
iMac-Vasily:JetBrains Toolbox vaskir$ ls -h -l
total 0
drwxr-xr-x@ 3 vaskir  staff    96B Aug 10 23:05 Rider.app

@jrr
Copy link
Author

jrr commented Aug 11, 2018

So, I just noticed "Tools -> Create Command-Line Launcher..." built right in to Rider, which I think is good enough for my needs. Out of curiosity, what led you to create this tool? @markrendle

@vasily-kirichenko
Copy link

@jrr Rider does not have that menu item on Windows :)

@ThatRendle
Copy link
Member

@jrr Yeah, it's not available in Windows, which is why this was originally a Windows-only tool. But a few people asked for it to be x-plat.

@ThatRendle
Copy link
Member

@vasily-kirichenko I don't suppose you'd consider cloning this repo and step-debugging on your Linux box for me? 😊

@vasily-kirichenko
Copy link

:) You mean, my Mac box :) Let me try.

@vasily-kirichenko
Copy link

/Users/vaskir/Library/Application Support/JetBrains/Toolbox/.settings.json does exist, but it does not contain install_location:

{
  "autostart": true,
  "jba": {
    "email": "xxx@gmail.com",
    "fullName": "me",
    "login": "mylogin"
  },
  "privacy_policy": {
    "eua_accepted_version": "1.1"
  },
  "proxy": {},
  "statistics": {
    "allow": true
  },
  "ui": {
    "hotkey": ""
  },
  "update": {
    "filter": {
      "quality_filter": {
        "order_value": 10000
      }
    },
    "install_automatically": true
  }
}

@vasily-kirichenko
Copy link

Rider's "Create command-line launcher" generates the following Python script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket
import struct
import sys
import os
import time

# see com.intellij.idea.SocketLock for the server side of this interface

RUN_PATH = u'/Users/vaskir/Library/Application Support/JetBrains/Toolbox/apps/Rider/ch-0/182.4174.40/Rider EAP.app'
CONFIG_PATH = u'/Users/vaskir/Library/Preferences/Rider2018.2'
SYSTEM_PATH = u'/Users/vaskir/Library/Caches/Rider2018.2'


def print_usage(cmd):
    print(('Usage:\n' +
           '  {0} -h | -? | --help\n' +
           '  {0} [project_dir]\n' +
           '  {0} [-l|--line line] [project_dir|--temp-project] file[:line]\n' +
           '  {0} diff <left> <right>\n' +
           '  {0} merge <local> <remote> [base] <merged>').format(cmd))


def process_args(argv):
    args = []

    skip_next = False
    for i, arg in enumerate(argv[1:]):
        if arg == '-h' or arg == '-?' or arg == '--help':
            print_usage(argv[0])
            exit(0)
        elif i == 0 and (arg == 'diff' or arg == 'merge' or arg == '--temp-project'):
            args.append(arg)
        elif arg == '-l' or arg == '--line':
            args.append(arg)
            skip_next = True
        elif skip_next:
            args.append(arg)
            skip_next = False
        else:
            path = arg
            if ':' in arg:
                file_path, line_number = arg.rsplit(':', 1)
                if line_number.isdigit():
                    args.append('-l')
                    args.append(line_number)
                    path = file_path
            args.append(os.path.abspath(path))

    return args


def try_activate_instance(args):
    port_path = os.path.join(CONFIG_PATH, 'port')
    token_path = os.path.join(SYSTEM_PATH, 'token')
    if not (os.path.exists(port_path) and os.path.exists(token_path)):
        return False

    try:
        with open(port_path) as pf:
            port = int(pf.read())
        with open(token_path) as tf:
            token = tf.read()
    except (ValueError):
        return False

    s = socket.socket()
    s.settimeout(0.3)
    try:
        s.connect(('127.0.0.1', port))
    except (socket.error, IOError):
        return False

    found = False
    while True:
        try:
            path_len = struct.unpack('>h', s.recv(2))[0]
            path = s.recv(path_len).decode('utf-8')
            if os.path.abspath(path) == os.path.abspath(CONFIG_PATH):
                found = True
                break
        except (socket.error, IOError):
            return False

    if found:
        cmd = 'activate ' + token + '\0' + os.getcwd() + '\0' + '\0'.join(args)
        if sys.version_info.major >= 3: cmd = cmd.encode('utf-8')
        encoded = struct.pack('>h', len(cmd)) + cmd
        s.send(encoded)
        time.sleep(0.5)  # don't close the socket immediately
        return True

    return False


def start_new_instance(args):
    if sys.platform == 'darwin':
        if len(args) > 0:
            args.insert(0, '--args')
        os.execvp('/usr/bin/open', ['-a', RUN_PATH] + args)
    else:
        bin_file = os.path.split(RUN_PATH)[1]
        os.execv(RUN_PATH, [bin_file] + args)


ide_args = process_args(sys.argv)
if not try_activate_instance(ide_args):
    start_new_instance(ide_args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants