예제 #1
0
    def run(self):
        view = self.window.active_view()
        if not view:
            return

        if not view.file_name():
            return

        path = find_pubspec(view.file_name())
        if not path:
            return
        path = os.path.dirname(path)


        cmd = ["dartanalyzer", view.file_name()]
        if sublime.platform() == 'windows':
            cmd = ["dartanalyzer.bat", view.file_name()]
        elif sublime.platform() == 'osx':
            cmd = ["/bin/bash", "--login", "-c",
                   "dartanalyzer \"{}\"".format(view.file_name())]

        self.window.run_command('exec', {
            "cmd": cmd,
            "file_regex": "^(?:\\[(?:error|warning|hint)\\].*?)\\((.*?\\.dart), line (\\d*), col (\\d*)\\)$",
            "working_dir": path,
            })
예제 #2
0
    def run(self):
        view = self.window.active_view()
        if not view:
            return

        if not view.file_name():
            return

        path = find_pubspec(view.file_name())
        if not path:
            return
        path = os.path.dirname(path)

        cmd = ["docgen", "--no-include-sdk", "--serve", path]
        if sublime.platform() == 'windows':
            cmd = ["docgen.bat", "--no-include-sdk", "--serve", path]
        elif sublime.platform() == 'osx':
            cmd = [
                "/bin/bash", "--login", "-c",
                "docgen --no-include-sdk --serve " + path
            ]

        self.window.run_command('exec', {
            "cmd": cmd,
            "working_dir": path,
        })
예제 #3
0
    def run(self, file_name=None, action='primary', kill_only=False):
        '''
        @action
          One of: primary, secondary

        @kill_only
          Whether we should simply kill any running processes.
        '''
        assert kill_only or (file_name and not kill_only), 'wrong call'

        # First, clean up any existing prosesses.
        if DartRunFileCommand.is_server_running:
            self.execute(kill=True)
            self.pub_serve.stop()
            DartRunFileCommand.is_server_running = False
            if self.panel:
                self.panel.write('[pub serve stopped]\n')

        self.stop_server_observatory()

        if kill_only:
            self.window.run_command("dart_exec", {"kill": True})
            DartRunFileCommand.is_script_running = False
            return

        try:
            working_dir = os.path.dirname(find_pubspec(file_name))
        except:
            try:
                if not working_dir:
                    working_dir = os.path.dirname(file_name)
            except:
                _logger.debug('cannot run an unsaved file')
                return

        dart_view = DartFile.from_path(file_name)

        if dart_view.is_server_app:
            self.run_server_app(file_name, working_dir, action)
            return

        if dart_view.is_web_app:
            self.run_web_app(dart_view, working_dir, action)
            return

        # At this point, we are looking at a file that either:
        #   - is not a .dart or .html file
        #   - is outside of a pub package
        # As a last restort, run the file as a script, but only if the user
        # requested a 'secondary' action.
        if action != 'secondary' or not dart_view.is_dart_file:
            print("Dart: Cannot determine best action for {}".format(
                dart_view.path))
            _logger.debug("cannot determine best run action for %s",
                          dart_view.path)
            return

        self.run_server_app(file_name, working_dir, action)
예제 #4
0
    def run(self):
        view = self.window.active_view()
        if not view:
            return

        if not view.file_name():
            return

        path = find_pubspec(view.file_name())
        if not path:
            return
        path = os.path.dirname(path)

        cmd = ["docgen", "--no-include-sdk", "--serve", path]
        if sublime.platform() == 'windows':
            cmd = ["docgen.bat", "--no-include-sdk", "--serve", path]
        elif sublime.platform() == 'osx':
            cmd = ["/bin/bash", "--login", "-c",
                    "docgen --no-include-sdk --serve " + path]

        self.window.run_command('exec', {
            "cmd": cmd,
            "working_dir": path,
            })
예제 #5
0
    def run(self, file_name=None, action='primary', kill_only=False):
        '''
        @action
          One of: primary, secondary

        @kill_only
          Whether we should simply kill any running processes.
        '''
        assert kill_only or (file_name and not kill_only), 'wrong call'

        # First, clean up any existing prosesses.
        if DartRunFileCommand.is_server_running:
            self.execute(kill=True)
            self.pub_serve.stop()
            DartRunFileCommand.is_server_running = False
            if self.panel:
                self.panel.write('[pub serve stopped]\n')

        self.stop_server_observatory()

        if kill_only:
            self.window.run_command("dart_exec", {
                "kill": True
                })
            DartRunFileCommand.is_script_running = False
            return

        try:
            working_dir = os.path.dirname(find_pubspec(file_name))
        except:
            try:
                if not working_dir:
                    working_dir = os.path.dirname(file_name)
            except:
                _logger.debug('cannot run an unsaved file')
                return

        dart_view = DartFile.from_path(file_name)

        if dart_view.is_server_app:
            self.run_server_app(file_name, working_dir, action)
            return

        if dart_view.is_web_app:
            self.run_web_app(dart_view, working_dir, action)
            return

        # At this point, we are looking at a file that either:
        #   - is not a .dart or .html file
        #   - is outside of a pub package
        # As a last restort, run the file as a script, but only if the user
        # requested a 'secondary' action.
        if action != 'secondary' or not dart_view.is_dart_file:
            print("Dart: Cannot determine best action for {}".format(
                  dart_view.path
                  ))
            _logger.debug("cannot determine best run action for %s",
                          dart_view.path)
            return

        self.run_server_app(file_name, working_dir, action)
예제 #6
0
    def run(self, file_name=None, action='primary', kill_only=False):
        '''
        @action
          One of: [primary, secondary]

        @kill_only
          If `True`, simply kill any running processes we've started.
        '''
        assert kill_only or file_name, 'wrong call'

        self._cleanup()

        if kill_only:
            self._kill()
            return

        working_dir = None
        try:
            working_dir = os.path.dirname(find_pubspec(file_name))
        except (TypeError, AttributeError):
            try:
                if not working_dir:
                    working_dir = os.path.dirname(file_name)
            except TypeError as e:
                _logger.debug('cannot run an unsaved file')
                _logger.debug(e)
                return
            except Exception as e:
                _logger.error('programmer error: this exception needs to be handled')
                _logger.error(e)
                return
        except Exception as e:
            _logger.error('programmer error: this exception needs to be handled')
            _logger.error(e)
            return

        dart_view = DartFile.from_path(file_name)

        if dart_view.is_server_app:
            self.run_server_app(file_name, working_dir, action)
            return

        if dart_view.is_web_app:
            self.run_web_app(dart_view, working_dir, action)
            return

        # TODO: improve detection of runnable file (for example, don't attempt
        # to run a part of a library).
        # At this point, we are looking at a file that either:
        #   - is not a .dart or .html file
        #   - is outside of a pub package
        # As a last resort, try to run the file as a script.
        if action != 'primary' or not dart_view.is_dart_file:
            print("Dart: Cannot determine best action for {}".format(
                  dart_view.path
                  ))
            _logger.debug("cannot determine best run action for %s",
                          dart_view.path)
            return

        self.run_server_app(file_name, working_dir, action)