Пример #1
0
    def on_navigate(self, href):
        """Abandon this node and insert a new expanded one"""
        error = jsval = None

        try:
            ws_handler.run_async_op('inspectGetterValue', {
                'spaceId': self.repl.inspection_space_id,
                'parentId': self.parent_id,
                'prop': self.prop
            })
            jsval = yield
        except GetterThrewError as e:
            error = e

        [reg] = self.view.query_phantom(self.phid)
        self.view.erase_phantom_by_id(self.phid)
        self.phid = None
        
        with self.repl.region_editing_off_then_reestablished():
            self.view.erase(edit_for[self.view], reg)
            cur = StructuredCursor(reg.a, self.view, depth=self.depth)
            if jsval is not None:
                insert_js_value(cur, jsval)
            else:
                cur.insert("throw new {}({})".format(
                    error.exc_class_name,
                    json.dumps(error.exc_message)
                ))
Пример #2
0
    def run(self):
        text = self.view.substr(self.repl.edit_region)
        stripped_text = text.rstrip()
        if stripped_text != text:
            self.repl.replace_edit_region_contents(stripped_text)
            text = stripped_text

        try:
            ws_handler.run_async_op('replEval', {
                'spaceId': self.repl.inspection_space_id,
                'mid': self.repl.cur_module_id,
                'code': text
            })
            jsval = yield 
            error = None
        except BackendError as e:
            error = e

        cur = StructuredCursor(self.repl.edit_region.b, self.view)
        with read_only_set_to(self.view, False):
            if error:
                cur.insert('\n! ')
                cur.insert(error.message)
            else:
                cur.insert('\n< ')
                insert_js_value(cur, jsval)
            cur.insert('\n\n')
            self.repl.insert_prompt(cur)

        set_selection(self.view, to=cur.pos, show=True)
Пример #3
0
    def run(self):
        folders = self.window.folders()
        if len(folders) != 1:
            sublime.status_message(
                "Must have exactly 1 folder open to determine project root")
            return

        [root] = folders

        try:
            proj_data = read_project_file_at(root)
        except Exception as e:
            sublime.error_message("Could not read project file: {}".format(e))
            raise

        proj = Project(id=proj_data['projectId'],
                       name=proj_data['projectName'],
                       path=root)

        ws_handler.run_async_op(
            'loadProject', {
                'projectPath': root,
                'project': proj_data,
                'sources': {
                    module['id']: proj.module_contents(module['name'])
                    for module in proj_data['modules']
                }
            })
        yield

        fe_projects.append(proj)
        setting.project_id[self.window] = proj.id

        sublime.status_message("Project \"{}\" loaded!".format(proj.name))
Пример #4
0
def fe_to_be():
    for proj in fe_projects:
        if proj.id == config.livejs_project_id:
            continue

        proj_data = proj.read_project_data()
        ws_handler.run_async_op(
            'loadProject', {
                'projectPath': proj.path,
                'project': proj_data,
                'sources': {
                    module['id']: proj.module_contents(module['name'])
                    for module in proj_data['modules']
                }
            })
        yield
Пример #5
0
    def _expand(self):
        """Abandon this node and insert a new expanded one"""
        assert not self.is_expanded

        ws_handler.run_async_op('inspectObjectById', {
            'spaceId': self.repl.inspection_space_id,
            'id': self.id
        })
        jsval = yield 
        
        [reg] = self.view.query_phantom(self.phid)
        self._erase_phantom()

        with self.repl.region_editing_off_then_reestablished():
            self.view.erase(edit_for[self.view], reg)
            cur = StructuredCursor(reg.a, self.view, depth=self.depth)
            insert_js_value(cur, jsval)
Пример #6
0
def on_backend_connected():
    assign_window_for_livejs_project()

    ws_handler.run_async_op('getProjects', {})
    be_projects = yield

    if len(be_projects) == 1:
        # BE has no loaded projects besides livejs itself
        if len(fe_projects) == 1:
            # FE has no projects either
            pass
        else:
            # FE --> BE
            yield from fe_to_be()
    else:
        # BE has loaded projects. In this case no matter what we have here on the FE side,
        # we should substitute it with the BE data.
        be_to_fe(be_projects)
Пример #7
0
    def run(self, module_name):
        proj = project_for_window(self.window)
        module_path = proj.module_filepath(module_name)

        if os.path.exists(module_path):
            sublime.error_message(
                "File \"{}\" already exists".format(module_path))
            return

        module_contents = file_contents(
            os.path.join(config.be_root, config.new_module_template))

        module_id = gen_uid()
        ws_handler.run_async_op(
            'loadModule', {
                'projectId': proj.id,
                'moduleId': module_id,
                'name': module_name,
                'source': module_contents,
                'untracked': []
            })
        yield

        proj_file_view = open_filepath(self.window, proj.project_file_path)

        @on_load(proj_file_view)
        @edits_view(proj_file_view)
        def modify_project_file():
            R = json_root_in(proj_file_view)
            R['modules'].append(
                OrderedDict([('id', module_id), ('name', module_name),
                             ('untracked', [])]))
            saver.request_save(proj_file_view)

        with open(module_path, 'w') as file:
            file.write(module_contents)
Пример #8
0
 def delete_inspection_space(self):
     ws_handler.run_async_op('deleteInspectionSpace',
                             {'spaceId': self.inspection_space_id})
     yield