Ejemplo n.º 1
0
 def __init__(self, resp_proc):
     _logger.info('starting fsac server...')
     self.fsac = FsacClient(server.start(), resp_proc)
     self.compilers_path = None
     self.project_file = None
     self.fsac.send_request(CompilerLocationRequest())
     response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE,
                                     self.on_compiler_path_available)
Ejemplo n.º 2
0
 def __init__(self, resp_proc):
     _logger.info("starting fsac server...")
     self.fsac = FsacClient(server.start(), resp_proc)
     self.compilers_path = None
     self.project_file = None
     self.fsac.send_request(CompilerLocationRequest())
     response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE, self.on_compiler_path_available)
Ejemplo n.º 3
0
    def __init__(self, resp_proc):
        _logger.info('Starting F# language services...')

        self.fsac = FsacClient(server.start(), resp_proc)

        self.compilers_path = None
        self.project_file = None

        self._errors = []
        self.errors_panel = FSharpErrorsPanel()

        self.fsac.send_request(CompilerLocationRequest())
        # todo: register as decorator instead?
        response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE,
                                        self.on_compiler_path_available)

        response_processor.add_listener(ON_ERRORS_AVAILABLE,
                                        self.on_errors_available)

        self._write_lock = threading.Lock()
Ejemplo n.º 4
0
class Editor(object):
    """Global editor state.
    """

    def __init__(self, resp_proc):
        _logger.info("starting fsac server...")
        self.fsac = FsacClient(server.start(), resp_proc)
        self.compilers_path = None
        self.project_file = None
        self.fsac.send_request(CompilerLocationRequest())
        response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE, self.on_compiler_path_available)

    def on_compiler_path_available(self, data):
        self.compilers_path = data["response"].compilers_path

    @property
    def compiler_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, "fsc.exe")

    @property
    def interpreter_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, "fsi.exe")

    def refresh(self, fs_file):
        assert isinstance(fs_file, FSharpFile), "wrong argument: %s" % fs_file
        # todo: run in alternate thread

        if not self.project_file:
            self.project_file = FSharpProjectFile.from_path(fs_file.path)
            self.set_project()
            return

        if not self.project_file.governs(fs_file.path):
            new_project_file = FSharpProjectFile.from_path(fs_file.path)
            self.project_file = new_project_file
            self.set_project()
            return

    def set_project(self):
        self.fsac.send_request(ProjectRequest(self.project_file.path))

    def parse_file(self, fs_file, content):
        self.fsac.send_request(ParseRequest(fs_file.path, content))

    def parse_view(self, view):
        # todo: what about unsaved files?
        fs_file = FSharpFile(view)
        if not fs_file.is_fsharp_file:
            return
        self.refresh(fs_file)
        # todo: very inneficient
        if fs_file.is_code:
            content = view.substr(sublime.Region(0, view.size()))
            self.parse_file(fs_file, content)
Ejemplo n.º 5
0
class Editor(object):
    """Global editor state.
    """
    def __init__(self, resp_proc):
        _logger.info('starting fsac server...')
        self.fsac = FsacClient(server.start(), resp_proc)
        self.compilers_path = None
        self.project_file = None
        self.fsac.send_request(CompilerLocationRequest())
        response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE,
                                        self.on_compiler_path_available)

    def on_compiler_path_available(self, data):
        self.compilers_path = data['response'].compilers_path

    @property
    def compiler_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, 'fsc.exe')

    @property
    def interpreter_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, 'fsi.exe')

    def refresh(self, fs_file):
        assert isinstance(fs_file, FSharpFile), 'wrong argument: %s' % fs_file
        # todo: run in alternate thread

        if not self.project_file:
            self.project_file = FSharpProjectFile.from_path(fs_file.path)
            self.set_project()
            return

        if not self.project_file.governs(fs_file.path):
            new_project_file = FSharpProjectFile.from_path(fs_file.path)
            self.project_file = new_project_file
            self.set_project()
            return

    def set_project(self):
        self.fsac.send_request(ProjectRequest(self.project_file.path))

    def parse_file(self, fs_file, content):
        self.fsac.send_request(ParseRequest(fs_file.path, content))

    def parse_view(self, view):
        # todo: what about unsaved files?
        fs_file = FSharpFile(view)
        if not fs_file.is_fsharp_file:
            return
        self.refresh(fs_file)
        # todo: very inneficient
        if fs_file.is_code:
            content = view.substr(sublime.Region(0, view.size()))
            self.parse_file(fs_file, content)
    def __init__(self, resp_proc):
        _logger.info ('Starting F# language services...')

        self.fsac = FsacClient(server.start(), resp_proc)

        self.compilers_path = None
        self.project_file = None

        self._errors = []

        self.fsac.send_request(CompilerLocationRequest())
        # todo: register as decorator instead?
        response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE,
                                        self.on_compiler_path_available)

        response_processor.add_listener(ON_ERRORS_AVAILABLE,
                                        self.on_errors_available)

        self._write_lock = threading.Lock()
Ejemplo n.º 7
0
class Editor(object):
    """Global editor state.
    """
    def __init__(self, resp_proc):
        _logger.info ('starting fsac server...')
        self.fsac = FsacClient(server.start(), resp_proc)
        self.compilers_path = None
        self.project_file = None
        self.fsac.send_request (CompilerLocationRequest())

    @property
    def compiler_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, 'fsc.exe')

    @property
    def interpreter_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, 'fsi.exe')

    def refresh(self, fs_file):
        assert isinstance(fs_file, FSharpFile), 'wrong argument: %s' % fs_file
        # todo: run in alternate thread
        if not self.project_file:
            self.project_file = FSharpProjectFile.from_path(fs_file.path)
            return
        if not self.project_file.governs(fs_file.path):
            new_project_file = FSharpProjectFile.from_path(fs_file.path)
            self.project_file = new_project_file
        self.set_project()

    def set_project(self):
        self.fsac.send_request(ProjectRequest(self.project_file.path))

    def parse_file(self, fs_file, content):
        self.fsac.send_request(ParseRequest(fs_file.path, content))
Ejemplo n.º 8
0
 def __init__(self, resp_proc):
     _logger.info ('starting fsac server...')
     self.fsac = FsacClient(server.start(), resp_proc)
     self.compilers_path = None
     self.project_file = None
     self.fsac.send_request (CompilerLocationRequest())
class Editor(object):
    """Global editor state.
    """
    def __init__(self, resp_proc):
        _logger.info ('Starting F# language services...')

        self.fsac = FsacClient(server.start(), resp_proc)

        self.compilers_path = None
        self.project_file = None

        self._errors = []

        self.fsac.send_request(CompilerLocationRequest())
        # todo: register as decorator instead?
        response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE,
                                        self.on_compiler_path_available)

        response_processor.add_listener(ON_ERRORS_AVAILABLE,
                                        self.on_errors_available)

        self._write_lock = threading.Lock()

    def on_compiler_path_available(self, data):
        self.compilers_path = data['response'].compilers_path

    def on_errors_available(self, data):
        self.errors = data['response']['Data']

    @property
    def errors(self):
        with self._write_lock:
            return self._errors

    @errors.setter
    def errors(self, value):
        assert isinstance(value, list), 'bad call'
        with self._write_lock:
            self._errors = value

    @property
    def compiler_path(self):
        if self.compilers_path is None:
            return
        return os.path.join(self.compilers_path, 'fsc.exe')

    @property
    def interpreter_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, 'fsi.exe')

    def update_project_data(self, fs_file):
        assert isinstance(fs_file, FileInfo), 'wrong argument: %s' % fs_file
        # todo: run in alternate thread

        # fsautocomplete.exe doesn't link F# script files to any .fsproj file,
        # so bail out.
        if fs_file.is_fsharp_script_file:
            return

        if not self.project_file or not self.project_file.governs(fs_file.path):
            self.project_file = FSharpProjectFile.from_path(fs_file.path)

            if not self.project_file:
                _logger.info('could not find a .fsproj file for %s' % fs_file)
                return

            # fsautocomplete.exe takes care of managing .fsproj files, so we
            # can add as many as we need.
            self.set_project()

    def set_project(self):
        self.fsac.send_request(ProjectRequest(self.project_file.path))

    def parse_file(self, fs_file, content):
        self.fsac.send_request(ParseRequest(fs_file.path, content))

    def parse_view(self, view, force=False):
        """
        Sends a parse request to fsac.

        @view
          The view whose content should be parsed.

        @force
          If `True`, the @view will be parsed even if it's clean.
        """

        if not (view.is_dirty() or force):
            return

        # FIXME: In ST, I think a file may have a .file_name() and still not
        # exist on disk because it's been unlinked.
        # ignore unsaved files
        fs_file = FileInfo(view)

        self.update_project_data(fs_file)
        # TODO: very inneficient?
        if fs_file.is_fsharp_code:
            content = view.substr(sublime.Region(0, view.size()))
            self.parse_file(fs_file, content)
Ejemplo n.º 10
0
class Editor(object):
    """Global editor state.
    """
    def __init__(self, resp_proc):
        _logger.info('Starting F# language services...')

        self.fsac = FsacClient(server.start(), resp_proc)

        self.compilers_path = None
        self.project_file = None

        self._errors = []
        self.errors_panel = FSharpErrorsPanel()

        self.fsac.send_request(CompilerLocationRequest())
        # todo: register as decorator instead?
        response_processor.add_listener(ON_COMPILER_PATH_AVAILABLE,
                                        self.on_compiler_path_available)

        response_processor.add_listener(ON_ERRORS_AVAILABLE,
                                        self.on_errors_available)

        self._write_lock = threading.Lock()

    def on_compiler_path_available(self, data):
        self.compilers_path = data['response'].compilers_path

    def on_errors_available(self, data):
        self.errors = data['response']['Data']
        self.errors_panel.update((ErrorInfo(e) for e in self.errors),
                                 sort_key=lambda x: x.start_line)
        self.errors_panel.display()

    @property
    def errors(self):
        with self._write_lock:
            return self._errors

    @errors.setter
    def errors(self, value):
        assert isinstance(value, list), 'bad call'
        with self._write_lock:
            self._errors = value

    @property
    def compiler_path(self):
        if self.compilers_path is None:
            return
        return os.path.join(self.compilers_path, 'fsc.exe')

    @property
    def interpreter_path(self):
        if self.compilers_path is None:
            return None
        return os.path.join(self.compilers_path, 'fsi.exe')

    def update_project_data(self, fs_file):
        assert isinstance(fs_file, FileInfo), 'wrong argument: %s' % fs_file
        # todo: run in alternate thread

        # fsautocomplete.exe doesn't link F# script files to any .fsproj file,
        # so bail out.
        if fs_file.is_fsharp_script_file:
            return

        if not self.project_file or not self.project_file.governs(
                fs_file.path):
            self.project_file = FSharpProjectFile.from_path(fs_file.path)

            if not self.project_file:
                _logger.info('could not find a .fsproj file for %s' % fs_file)
                return

            # fsautocomplete.exe takes care of managing .fsproj files, so we
            # can add as many as we need.
            self.set_project()

    def set_project(self):
        self.fsac.send_request(ProjectRequest(self.project_file.path))

    def parse_file(self, fs_file, content):
        self.fsac.send_request(ParseRequest(fs_file.path, content))

    def parse_view(self, view, force=False):
        """
        Sends a parse request to fsac.

        @view
          The view whose content should be parsed.

        @force
          If `True`, the @view will be parsed even if it's clean.
        """

        if not (view.is_dirty() or force):
            return

        # FIXME: In ST, I think a file may have a .file_name() and still not
        # exist on disk because it's been unlinked.
        # ignore unsaved files
        fs_file = FileInfo(view)

        self.update_project_data(fs_file)
        # TODO: very inneficient?
        if fs_file.is_fsharp_code:
            content = view.substr(sublime.Region(0, view.size()))
            self.parse_file(fs_file, content)