Theia: [workspace] Ask the user if no workspace dir is given

Created on 5 Oct 2017  路  12Comments  路  Source: eclipse-theia/theia

Currently, when Theia gets started without a workspace dir, we are falling back to current working directory. This is almost ever what you want (maybe during development) and causes real issues with native Theia apps, because it open on root.

Therefore, we should change the behavior such that the workspace root is undefined if not provided and that the frontend will present the user with a dialog to choose a workspace root.

Updated:

These are the basic ideas we would like to achieve within the context of this task. Please note, although this is a cool feature, the current work is being done for #346 due to some performance issues.

  • If the desired workspace root is not given as a program argument:

    • The application does not default to any workspace roots.

    • All those services or contributions that depend on the workspace root will get a promise which will be resolved iff the workspace root is explicitly selected by the user from the UI. This could be either from the Open... menu contribution or from the Select Workspace Root (whatever) button inside the Files navigator. Similar to VSCode. Unless the root is set, we do not show anything in the navigator, we do not have New File, New Folder, Open Terminal, and etc.. main or context menu contributions, keybindings. There is no layout restoration, no preferences. (Yes, that was our initial idea.)

  • Once the user selects the desired workspace root, the promise will get resolved and all the downstream dependencies which were waiting can continue on whatever they want to.
  • We allow root to be undefined on the backend, still, we need some default, because we need to feed the workspace root selector dialog, but that is the only purpose of having a defaultRoot now.
  • When the user selects the workspace root, and there was not set before, we do not want to open a new tab/window but just refresh the current one.

Later:

  • We would like to support recently opened workspaces. This information cannot be stored in the workspace because we do not have a workspace yet. This is a chicken-egg problem. We need to figure this out. (User settings?)
  • We also need to handle such cases gracefully, when the user selects a recently opened workspace but that does not exist anymore.
  • There is another use-case we have to support later, support multiple workspace roots in different windows. With the current code (DefaultWorkspaceServer), after refreshing any window, the workspace root will be the one which was the most recently selected.
  • https://github.com/theia-ide/theia/pull/615#discussion_r143731438

Most helpful comment

It would be all nice to remove --root-dir option and just consider that a first arg to be a path if it is not option, similar what VS code does, e.g. code . to open the current dir.

All 12 comments

We could just open theia and wait for the user to do open dir ?
I'm trying to avoid dialogs...

you can't do anything without a workspace, can you?

It should at least be obvious for the user what to do.
We could once more copy vscode, by adding a button in the navigator instead of the tree:
screen shot 2017-10-05 at 15 01 05

Sounds good.

It would be all nice to remove --root-dir option and just consider that a first arg to be a path if it is not option, similar what VS code does, e.g. code . to open the current dir.

It would be all nice to remove --root-dir option and just consider that a first arg to be a path if it is not option, similar what VS code does, e.g. code . to open the current dir.

I am a bit puzzled, the code is not the VSCode application itself, it is a script which is available from the path and launches the application with the given workspace root. Although I like the simplicity of this feature request, I think it is unrelated to this task. Can we split it up?

code on OS X:

#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

function realpath() { /usr/bin/python -c "import os,sys; print os.path.realpath(sys.argv[1])" "$0"; }
CONTENTS="$(dirname "$(dirname "$(dirname "$(dirname "$(realpath "$0")")")")")"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"

code on Windows:

#!/usr/bin/env bash
#
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.

NAME="Code"
VSCODE_PATH="$(dirname "$(dirname "$(realpath "$0")")")"
ELECTRON="$VSCODE_PATH/$NAME.exe"
if grep -q Microsoft /proc/version; then
        # If running under WSL don't pass cli.js to Electron as environment vars
        # cannot be transferred from WSL to Windows
        # See: https://github.com/Microsoft/BashOnWindows/issues/1363
        #      https://github.com/Microsoft/BashOnWindows/issues/1494
        "$ELECTRON" "$@"
        exit $?
fi
if [ "$(expr substr $(uname -s) 1 9)" == "CYGWIN_NT" ]; then
        CLI=$(cygpath -m "$VSCODE_PATH/resources/app/out/cli.js")
else
        CLI="$VSCODE_PATH/resources/app/out/cli.js"
fi
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

@kittaakos I think @svenefftinge already did it in https://github.com/theia-ide/theia/pull/612

Each service which depends on the workspace root should be able to gracefully handle the case when it is not yet available (undefined). ~Also, the WorkspaceServer should send an event to all listeners when the root has been changed (or set).~

PR: #615.

In your updated comments you forgo the idea to have the default root dir used for application that do not absolutely need a root dir like the terminal for example.. what @akosyakov refers to as tryRoot
I think this could be added now ? At least the base code for it... ?

In your updated comments you forgo the idea to have the default root dir used for application that do not absolutely need a root dir like the terminal for example

We did not plan to support this now, but I will definitely add it to the Later part. Thank you for the reminder!

Note I opened #657 #658 #656
About the issues raised for later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marechal-p picture marechal-p  路  3Comments

jeanlucburot picture jeanlucburot  路  3Comments

cekvenich picture cekvenich  路  3Comments

Beetix picture Beetix  路  3Comments

akosyakov picture akosyakov  路  3Comments