def write_js_views(): from views import TREE_VIEW_CONTAINERS views_ts_file = os.path.join(vscode_js_client_src_dir, "robocorpViews.ts") command_constants = [] for tree_view_container in TREE_VIEW_CONTAINERS: tree_view_container_id = convert_case_to_constant( "tree_view_container_" + tree_view_container.id) command_constants.append('export const %s = "%s"; // %s' % ( tree_view_container_id, tree_view_container.id, tree_view_container.title, )) for tree_view in tree_view_container.tree_views: tree_view_id = convert_case_to_constant("tree_view_" + tree_view.id) command_constants.append( 'export const %s = "%s"; // %s' % (tree_view_id, tree_view.id, tree_view_container.title)) with open(views_ts_file, "w") as stream: stream.write( "// Warning: Don't edit file (autogenerated from python -m dev codegen).\n\n" + "\n".join(command_constants)) print("Written: %s" % (views_ts_file, ))
def __init__( self, name, title, add_to_package_json=True, keybinding="", server_handled=True, icon=None, # https://microsoft.github.io/vscode-codicons/dist/codicon.html enablement=None, hide_from_command_palette=False, constant="", ): """ :param add_to_package_json: If a command should not appear to the user, add_to_package_json should be False. :param server_handled: If True this is a command handled in the server (and not in the client) and thus will be registered as such. :param constant: If given the internal constant used will be this one (used when a command is renamed and we want to keep compatibility). """ self.name = name self.title = title self.add_to_package_json = add_to_package_json self.keybinding = keybinding self.server_handled = server_handled self.icon = icon self.enablement = enablement self.hide_from_command_palette = hide_from_command_palette if not constant: constant = convert_case_to_constant(name) self.constant = constant
def write_py_settings(): settings_py_file = os.path.join(vscode_py_src_dir, "robocorp_code", "settings.py") settings_template = [ """# Warning: Don't edit file (autogenerated from python -m dev codegen). """ ] setting_constant_template = '%s = "%s"' # Create the constants for setting in SETTINGS: # : :type setting: Setting settings_template.append( setting_constant_template % (convert_case_to_constant(setting.name), setting.name)) settings_template.append(""" ALL_ROBOCORP_OPTIONS = frozenset( (""") for setting in SETTINGS: # : :type setting: Setting settings_template.append( f" {convert_case_to_constant(setting.name)},") settings_template.append(""" ) ) """) with open(settings_py_file, "w") as stream: stream.write("\n".join(settings_template)) print("Written: %s" % (settings_py_file, ))
def write_js_settings(): settings_ts_file = os.path.join(vscode_js_client_src_dir, "robocorpSettings.ts") settings_template = [ """// Warning: Don't edit file (autogenerated from python -m dev codegen). import { ConfigurationTarget, workspace } from "vscode"; export function get<T>(key: string): T | undefined { var dot = key.lastIndexOf('.'); var section = key.substring(0, dot); var name = key.substring(dot + 1); return workspace.getConfiguration(section).get(name); } """ ] setting_constant_template = 'export const %s = "%s";' # Create the constants for setting in SETTINGS: # : :type setting: Setting settings_template.append( setting_constant_template % (convert_case_to_constant(setting.name), setting.name)) getter_template = """ export function get%s(): %s { let key = %s; return get<%s>(key); } """ setter_template = """ export async function set%s(value): Promise<void> { let key = %s; let i = key.lastIndexOf('.'); let config = workspace.getConfiguration(key.slice(0, i)); await config.update(key.slice(i + 1), value, ConfigurationTarget.Global); } """ # Create the getters / setters for setting in SETTINGS: js_type = setting.js_type or setting.setting_type if js_type == "array": raise AssertionError("Expected js_type for array.") name = "_".join(setting.name.split(".")[1:]) name = name.title().replace(" ", "").replace("_", "").replace("-", "") settings_template.append( getter_template % (name, js_type, convert_case_to_constant(setting.name), js_type)) settings_template.append( setter_template % (name, convert_case_to_constant(setting.name))) with open(settings_ts_file, "w") as stream: stream.write("\n".join(settings_template)) print("Written: %s" % (settings_ts_file, ))