Theia: A way to tell if my extension is running in Theia (not VS Code)

Created on 17 Jun 2019  路  9Comments  路  Source: eclipse-theia/theia

Hi, is there a way to programmatically determine if my VS Code extension is running in Theia as opposed to in VS Code?

Currently I am checking an env var which is present in our Theia environment, but will not be present in _all_ Theia environments, so I'd like to know if I can improve this.

plug-in system question

All 9 comments

yes env.appName is a good way to do checks.

BTW I'm curious why you may want to know in which environment you are

We have a VS Code extension which we want to also run in theia, but there are a number of behaviour differences between the two use-cases, plus some features that we are making available in one environment but not the other.

In addition, there are still some gaps in the theia API which compile but don't work - I have some 'wizards' which I use vscode.window.createQuickPick for, but that doesn't work at all in Theia because the onDidAccept callback is never invoked. So in the Theia case I have to use the 'dumb' quickpick window.showQuickPick (https://github.com/theia-ide/theia/issues/5059). Ditto for InputBox (https://github.com/theia-ide/theia/issues/5109). Those are the two I've had to work-around so far.

I haven't pushed this code yet or i'd to link it, this is my extension

ok thanks @tetchel for the explanation.
you may create specific sub-issues for each VS Code API that is not working as you expect so they can be tackled first. The two issues you referenced are more global improvements and it's better to fix first what developers are using.

I won't have a chance to create proper bugs for those two in the next little while, but basically they were:
1) If window.createQuickPick is used, the onDidAccept callback is never invoked
2) TypeError window.createInputBox is not a function

@tetchel Could it be closed? There are separate issues already?

I'd still like to see appName set in the environment - Here's what I see in process.env now:

{
        npm_package_dependencies__theia_process: '^0.9.0',
        npm_package_dependencies__theia_keymaps: '^0.9.0',
        npm_package_dependencies__theia_java: '^0.9.0',
        TERM_PROGRAM: 'iTerm.app',
        npm_package_theia_frontend_config_preferences_files_enableTrash: 'false',
        NODE: '/Users/tim/.nvm/versions/node/v10.15.2/bin/node',
        npm_package_scripts_test_non_headless: 'wdio wdio-non-headless.conf.js',
        INIT_CWD: '/Users/tim/programs/clones/theia/examples/browser',
        NVM_CD_FLAGS: '',
        npm_config_version_git_tag: 'true',
        SHELL: '/bin/bash',
        TERM: 'xterm-256color',
        npm_package_dependencies__theia_callhierarchy: '^0.9.0',
        TMPDIR: '/var/folders/7m/17bccvdd1zq3b2lvwqv2cknr0000gn/T/',
        Apple_PubSub_Socket_Render: '/private/tmp/com.apple.launchd.ZTPYzgrY4W/Render',
        npm_package_dependencies__theia_metrics: '^0.9.0',
        npm_config_init_license: 'MIT',
        TERM_PROGRAM_VERSION: '3.2.9',
        npm_package_dependencies__theia_search_in_workspace: '^0.9.0',
        npm_package_dependencies__theia_typehierarchy: '^0.9.0',
        npm_package_dependencies__theia_editor_preview: '^0.9.0',
        TERM_SESSION_ID: 'w2t0p0:C00E2669-50F3-4C84-A9D3-727BF09757C6',
        npm_package_private: 'true',
        npm_config_registry: 'https://registry.yarnpkg.com',
        npm_package_dependencies__theia_languages: '^0.9.0',
        npm_package_dependencies__theia_debug_nodejs: '^0.9.0',
        USER: 'tim',
        NVM_DIR: '/Users/tim/.nvm',
        npm_package_dependencies__theia_task: '^0.9.0',
        npm_config_python: '/usr/bin/python',
        npm_package_scripts_coverage_remap: 'remap-istanbul -i coverage/coverage.json -o coverage/coverage-final.json --exclude \'frontend/index.js\' && rimraf coverage/coverage.json',
        npm_package_license: 'EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0',
        npm_package_scripts_coverage_report_html: 'istanbul report --root coverage --format html',
        npm_package_dependencies__theia_plugin_ext: '^0.9.0',
        npm_package_dependencies__theia_file_search: '^0.9.0',
        npm_package_scripts_coverage_report_lcov: 'istanbul report --root coverage --format lcov',
        npm_package_dependencies__theia_plugin_ext_vscode: '^0.9.0',
        npm_package_dependencies__theia_textmate_grammars: '^0.9.0',
        SSH_AUTH_SOCK: '/private/tmp/com.apple.launchd.RwNEPFoLVj/Listeners',
        __CF_USER_TEXT_ENCODING: '0x1F5:0x0:0x52',
        npm_execpath: '/usr/local/Cellar/yarn/1.15.2/libexec/bin/yarn.js',
        npm_package_scripts_coverage: 'yarn coverage:compile && yarn test && yarn coverage:remap && yarn coverage:report:lcov && yarn coverage:report:html',
        npm_package_dependencies__theia_python: '^0.9.0',
        npm_package_dependencies__theia_merge_conflicts: '^0.9.0',
        npm_package_dependencies__theia_core: '^0.9.0',
        PATH: '/var/folders/7m/17bccvdd1zq3b2lvwqv2cknr0000gn/T/yarn--1565192248138-0.9631774622279781:/Users/tim/programs/clones/theia/examples/browser/node_modules/.bin:/Users/tim/.config/yarn/link/node_modules/.bin:/Users/tim/programs/clones/theia/node_modules/.bin:/Users/tim/.nvm/versions/node/v10.15.2/libexec/lib/node_modules/npm/bin/node-gyp-bin:/Users/tim/.nvm/versions/node/v10.15.2/lib/node_modules/npm/bin/node-gyp-bin:/Users/tim/.nvm/versions/node/v10.15.2/bin/node_modules/npm/bin/node-gyp-bin:/Users/tim/.nvm/versions/node/v10.15.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Applications/Wireshark.app/Contents/MacOS:~/bin:/opt/apache-maven-3.5.4/bin:~/programs/microclimate/docker/file-watcher/idc/:/Users/tim/.microclimate:/Users/tim/.kube/plugins:~/bin:/opt/apache-maven-3.5.4/bin:~/programs/microclimate/docker/file-watcher/idc/:/Users/tim/.microclimate:/Users/tim/.kube/plugins',
        npm_config_argv: '{"remain":[],"cooked":["run","start"],"original":["start"]}',
        npm_package_dependencies__theia_navigator: '^0.9.0',
        npm_package_dependencies__theia_console: '^0.9.0',
        npm_package_dependencies__theia_userstorage: '^0.9.0',
        _: '/Users/tim/programs/clones/theia/examples/browser/node_modules/.bin/theia',
        npm_package_dependencies__theia_typescript: '^0.9.0',
        npm_package_dependencies__theia_outline_view: '^0.9.0',
        PWD: '/Users/tim/programs/clones/theia/examples/browser',
        JAVA_HOME: '/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home',
        npm_package_scripts_start_debug: 'yarn start --log-level=debug',
        npm_package_dependencies__theia_git: '^0.9.0',
        EDITOR: '/usr/bin/vim',
        npm_lifecycle_event: 'start',
        npm_package_dependencies__theia_plugin_dev: '^0.9.0',
        npm_package_dependencies__theia_filesystem: '^0.9.0',
        LANG: 'en_CA.UTF-8',
        npm_package_name: '@theia/example-browser',
        ITERM_PROFILE: 'Default',
        npm_package_dependencies__theia_editor: '^0.9.0',
        npm_package_dependencies__theia_cpp: '^0.9.0',
        npm_config_unsafe_disable_integrity_migration: 'true',
        npm_package_scripts_start: 'theia start --plugins=local-dir:../../plugins',
        npm_package_scripts_build: 'theiaext compile && theia build --mode development',
        npm_package_dependencies__theia_preview: '^0.9.0',
        npm_package_dependencies__theia_java_debug: '^0.9.0',
        npm_config_version_commit_hooks: 'true',
        XPC_FLAGS: '0x0',
        npm_config_bin_links: 'true',
        npm_package_dependencies__theia_terminal: '^0.9.0',
        npm_package_theia_frontend_config_applicationName: 'Theia Browser Example',
        XPC_SERVICE_NAME: '0',
        npm_package_scripts_watch: 'concurrently -n compile,bundle "theiaext watch --preserveWatchOutput" "theia build --watch --mode development"',
        npm_package_dependencies__theia_monaco: '^0.9.0',
        npm_package_version: '0.9.0',
        npm_package_dependencies__theia_preferences: '^0.9.0',
        COLORFGBG: '15;0',
        HOME: '/Users/tim',
        SHLVL: '2',
        npm_package_dependencies__theia_output: '^0.9.0',
        npm_package_scripts_test: 'wdio wdio.conf.js',
        npm_package_dependencies__theia_messages: '^0.9.0',
        YAOURT_COLORS: 'nb=1:pkg=1:ver=1;32:lver=1;45:installed=1;42:grp=1;34:od=1;41;5:votes=1;44:dsc=0:other=1;35',
        npm_config_save_prefix: '^',
        npm_config_strict_ssl: 'true',
        npm_package_dependencies__theia_getting_started: '^0.9.0',
        npm_config_version_git_message: 'v%s',
        NPM_CONFIG_PYTHON: '/usr/bin/python',
        SELENIUM_BROWSER: 'chrome',
        npm_package_dependencies__theia_scm: '^0.9.0',
        ITERM_SESSION_ID: 'w2t0p0:C00E2669-50F3-4C84-A9D3-727BF09757C6',
        npm_package_dependencies__theia_mini_browser: '^0.9.0',
        LOGNAME: 'tim',
        YARN_WRAP_OUTPUT: 'false',
        npm_package_dependencies__theia_debug: '^0.9.0',
        PREFIX: '/usr/local',
        npm_lifecycle_script: 'theia start --plugins=local-dir:../../plugins',
        npm_package_devDependencies__theia_cli: '^0.9.0',
        npm_package_dependencies__theia_workspace: '^0.9.0',
        npm_package_dependencies__theia_tslint: '^0.9.0',
        NVM_BIN: '/Users/tim/.nvm/versions/node/v10.15.2/bin',
        GOPATH: '/Users/tim/programs/go',
        npm_package_dependencies__theia_markers: '^0.9.0',
        npm_package_dependencies__theia_json: '^0.9.0',
        npm_config_version_git_sign: '',
        npm_config_ignore_scripts: '',
        npm_config_user_agent: 'yarn/1.15.2 npm/? node/v10.15.2 darwin x64',
        npm_package_scripts_coverage_compile: 'yarn build --config coverage-webpack.config.js',
        npm_package_scripts_prepare: 'yarn run clean && yarn build',
        npm_package_dependencies__theia_variable_resolver: '^0.9.0',
        npm_config_init_version: '1.0.0',
        npm_config_ignore_optional: '',
        npm_package_scripts_clean: 'theia clean && rimraf errorShots',
        COLORTERM: 'truecolor',
        npm_node_execpath: '/Users/tim/.nvm/versions/node/v10.15.2/bin/node',
        npm_package_dependencies__theia_editorconfig: '^0.9.0',
        npm_config_version_tag_prefix: 'v',
        VSCODE_NLS_CONFIG: '{"locale":"en","availableLanguages":{}}',
        VSCODE_PID: '78209',
        LOCAL_GIT_DIRECTORY: '/usr/local',
        GIT_EXEC_PATH: '/usr/local/Cellar/git/2.20.1/libexec/git-core',
        THEIA_PARENT_PID: '78209'
    }

I thought you will use vscode.env.appName. Does it work?

Oh, that totally worked. I didn't even know that API existed. Thanks!

Was this page helpful?
0 / 5 - 0 ratings