Commits

Ronny Pfannschmidt committed b68f2f8

finish the 2 language patches

Comments (0)

Files changed (3)

language-methodname-unification

-# HG changeset patch
-# Parent 46d3610f25eed3b59c69aedb93daccc53337161b
-unify the various language item generator method names to run
-
-diff --git a/pida-plugins/ctags/ctags.py b/pida-plugins/ctags/ctags.py
---- a/pida-plugins/ctags/ctags.py
-+++ b/pida-plugins/ctags/ctags.py
-@@ -145,7 +145,7 @@ class CtagsOutliner(Outliner):
-     plugin = "ctags"
-     description = _("A very fast but only shallow outliner")
- 
--    def get_outline(self):
-+    def run(self):
-         if not self.document.filename:
-             return
-         try:
-diff --git a/pida-plugins/ctags/test_ctags.py b/pida-plugins/ctags/test_ctags.py
---- a/pida-plugins/ctags/test_ctags.py
-+++ b/pida-plugins/ctags/test_ctags.py
-@@ -33,7 +33,7 @@ class TestCtags(unittest.TestCase):
-     def test_parser(self):
-         self.doc = Document(None, os.path.join(TESTDIR, 'test.py'))
-         self.outliner = CtagsOutliner(None, document=self.doc)
--        lst = list(self.outliner.get_outline())
-+        lst = list(self.outliner.run())
-         outer = None
-         inner = None
-         for x in lst:
-diff --git a/pida-plugins/gtags/gtags.py b/pida-plugins/gtags/gtags.py
---- a/pida-plugins/gtags/gtags.py
-+++ b/pida-plugins/gtags/gtags.py
-@@ -193,7 +193,7 @@ class GtagsCompleter(Completer):
-     plugin = "gtags"
-     description = _("a per project global completer list")
- 
--    def get_completions(self, base, buffer_, offset):
-+    def run(self, base, buffer_, offset):
-         """
-         Gets a list of completitions.
-         
-diff --git a/pida-plugins/python/python.py b/pida-plugins/python/python.py
---- a/pida-plugins/python/python.py
-+++ b/pida-plugins/python/python.py
-@@ -136,7 +136,7 @@ class PythonOutliner(Outliner):
-         'property', 'attribute', 'supermethod',
-         )
- 
--    def get_outline(self):
-+    def run(self):
-         from rope.base.exceptions import RopeError
-         try:
-             mp = ModuleParser(self.document.filename,
-@@ -232,7 +232,7 @@ class PythonValidator(Validator):
-     plugin = "python"
-     description = _("A not very precise, non configurable validator, but fast")
- 
--    def get_validations(self):
-+    def run(self):
-         code_string = self.document.content
-         filename = self.document.filename
-         try:
-@@ -283,7 +283,7 @@ class PythonCompleter(Completer):
-     plugin = "python"
-     description = _("Creates very exact suggestions at reasonable speed")
- 
--    def get_completions(self, base, buffer, offset):
-+    def run(self, base, buffer, offset):
- 
-         from rope.contrib.codeassist import code_assist, sorted_proposals
-         from rope.base.exceptions import RopeError
-@@ -318,7 +318,7 @@ class PythonDefiner(Definer):
-     plugin = "python"
-     description = _("Shows a good definition of a function")
- 
--    def get_definition(self, buffer, offset):
-+    def run(self, buffer, offset):
-         mp = ModuleParser(self.document.filename,
-                           project=self.document.project)
-         buffer = buffer + ('\n' * 20)
-diff --git a/pida-plugins/python_lint/python_lint.py b/pida-plugins/python_lint/python_lint.py
---- a/pida-plugins/python_lint/python_lint.py
-+++ b/pida-plugins/python_lint/python_lint.py
-@@ -249,7 +249,7 @@ class PylintValidator(Validator):
-         self.reporter = PidaReporter(self)
-         Validator.__init__(self, *args, **kwargs)
- 
--    def get_validations(self):
-+    def run(self):
-         if self.document.filename:
-             pylintrc = None
-             if self.document.project:
-diff --git a/pida-plugins/rst/rst.py b/pida-plugins/rst/rst.py
---- a/pida-plugins/rst/rst.py
-+++ b/pida-plugins/rst/rst.py
-@@ -250,7 +250,7 @@ class RSTOutliner(Outliner):
- 
-     section_types = ('section', 'paragraph')
- 
--    def get_outline(self):
-+    def run(self):
-         self.doc_items = RSTTokenList()
-         self.rstplugin = RSTPlugin(self.svc)
-         self.doctree = self.rstplugin.parse_rst(self.document)
-@@ -315,7 +315,7 @@ class RSTValidator(Validator):
- 
-     kind = VALIDATOR_KIND.SYNTAX
- 
--    def get_validations(self):
-+    def run(self):
-         self.rstplugin = RSTPlugin(self.svc)
-         self.doctree = self.rstplugin.parse_rst(self.document)
-         if self.doctree:
-diff --git a/pida/core/languages.py b/pida/core/languages.py
---- a/pida/core/languages.py
-+++ b/pida/core/languages.py
-@@ -8,6 +8,8 @@ Language Support Superclasses
- """
- from functools import partial
- from weakref import WeakKeyDictionary
-+import abc
-+
- import gobject
- 
- from pida.core.document import Document
-@@ -47,7 +49,7 @@ class BaseDocumentHandler(object):
-     """
-     Base class for all language plugins
-     """
--
-+    __metaclass__ = abc.ABCMeta
-     #__metaclass__ = LanguageMetaclass
-     priority = LANG_PRIO.DEFAULT
-     name = "NAME MISSING"
-@@ -104,6 +106,14 @@ class BaseDocumentHandler(object):
-         """Returns the priority this plugin will have for this document"""
-         return cls.priority
- 
-+    @abc.abstractmethod
-+    def run(self, document=None, offset=None):
-+        """
-+        run this handler, iterate over its items
-+        may optionally take document/offset
-+        """
-+        pass
-+
- class BaseCachedDocumentHandler(BaseDocumentHandler):
-     """
-     Default cache implementation for Languge Plugins.
-@@ -111,6 +121,12 @@ class BaseCachedDocumentHandler(BaseDocu
-     The cache is valid until the file is changed on disk
-     """
- 
-+    def run_cached(self):
-+        """
-+        Returns a cached iterator of this handler
-+        """
-+        return self._default_cache(self.run)
-+
-     def _default_cache(self, fnc):
-         """
-         Default implementation of outline cache.
-@@ -149,62 +165,21 @@ class Outliner(BaseCachedDocumentHandler
- 
-     filter_type = ()
- 
--    def get_outline_cached(self):
--        """
--        Returns a cached iterator of OutlineItems
--        """
--        return self._default_cache(self.get_outline)
--
--    def get_outline(self):
--        """
--        Returns a fresh computed iterator of OutlineItems
--        """
--        raise NotImplementedError('Outliner must define get_outline')
--
- 
- class Validator(BaseCachedDocumentHandler):
--
--
--    def get_validations_cached(self):
--        """
--        Returns a cached iterator of ValidatorItems
--        """
--        return self._default_cache(self.get_validations)
--
--    def get_validations(self):
--        """
--        Returns a fresh computed iterator of ValidatorItems
--        """
--        raise NotImplementedError('Validator must define get_validations')
-+    pass
- 
- class Definer(BaseDocumentHandler):
-     """
-     The definer class is used to allow the user to the definition of a
-     word.
-     """
--    def get_definition(self, buffer, offset):
--        """
--        Returns the Definition class pointing to document defining the word
--        searched for. The Definier has to find out which word the offset is on.
--
--        @buffer - the text to search in
--        @offset - nth char in the document point is on
--        """
--        raise NotImplementedError('Definer must define get_definition')
- 
- class Documentator(BaseDocumentHandler):
-     """
-     Documentation receiver returns a Documentation object
-     """
- 
--    def get_documentation(self, buffer, offset):
--        """
--        Returns the Documentation object for a offset of an file.
--
--        @buffer - the text to search in
--        @offset - nth char in the document point is on
--        """
--        raise NotImplementedError('Documentator must define get_definition')
- 
- class LanguageInfo(object):
-     """
-@@ -384,6 +359,10 @@ class GeneratorProxy(BaseProxy):
-             else:
-                 raise
- 
-+def run(x, *k, **kw):
-+    return x.run(*k, **kw)
-+
-+
- class ExternalMeta(type):
-     """
-     MetaClass for Extern classes. registers the functions for beeing extern
-@@ -406,10 +385,7 @@ class ExternalMeta(type):
-             if not type_ in dct or not dct[type_]:
-                 continue
-             cls.register(type_, dct[type_])
--            for mfunc in funcs:
--                # we register the function as a callable external
--                cls.register(mfunc, getattr(dct[type_], mfunc), proxytype=GeneratorProxy)
--
-+        cls.register('run', run, proxytype=GeneratorProxy)
- 
- class External(SyncManager):
-     """
-@@ -439,24 +415,12 @@ class External(SyncManager):
-     completer = None
- 
-     @staticmethod
--    def get_validations(instance):
--        for i in instance.get_validations():
-+    def run(instance):
-+        for i in instance.run():
-             yield i
- 
--    @staticmethod
--    def get_outline(instance):
--        for i in instance.get_outline():
--            yield i
- 
--    @staticmethod
--    def get_definition(instance, buffer, offset):
--        for i in instance.get_definition(buffer, offset):
--            yield i
- 
--    @staticmethod
--    def get_documentation(instance, buffer, offset):
--        for i in instance.get_documentation(buffer, offset):
--            yield i
- 
- class ExternalDocument(Document):
-     """
-@@ -521,40 +485,29 @@ class ExternalProxy(object):
-         """
-         return self._uuid
- 
-+    def run(self, *k, **kw):
-+        return self.svc.jobserver.run(self)
-+
-+
- class ExternalValidatorProxy(ExternalProxy, Validator):
-     """Proxies to the jobmanager and therefor to the external process"""
--    def get_validations(self):
--        for result in self.svc.jobserver.get_validations(self):
--            yield result
-+    mytype = 'validator'
- 
- class ExternalOutlinerProxy(ExternalProxy, Outliner):
-     """Proxies to the jobmanager and therefor to the external process"""
--    def get_outline(self):
--        for result in self.svc.jobserver.get_outline(self):
--            yield result
-+    mytype = 'outliner'
- 
- class ExternalDefinerProxy(ExternalProxy, Definer):
-     """Proxies to the jobmanager and therefor to the external process"""
--    def get_definition(self, buffer, offset):
--        rv = self.svc.jobserver.get_definition(self, buffer, offset)
--        for result in rv:
--            yield result
-+    mytype = 'definer'
- 
- class ExternalDocumentatorProxy(ExternalProxy, Documentator):
-     """Proxies to the jobmanager and therefor to the external process"""
--    def get_documentation(self, buffer, offset):
--        rv = self.svc.jobserver.get_documentation(self, buffer,
--                                                               offset)
--        for result in rv:
--            yield result
-+    mytype = 'documenter'
- 
- class ExternalCompleterProxy(ExternalProxy, Completer):
-     """Proxies to the jobmanager and therefor to the external process"""
--    def get_completions(self, base, buffer_, offset):
--        rv = self.svc.jobserver.get_completions(self, base,
--                                                          buffer_, offset)
--        for result in rv:
--            yield result
-+    mytype = 'completer'
- 
- class Merger(BaseDocumentHandler):
-     """
-@@ -585,12 +538,12 @@ class Merger(BaseDocumentHandler):
- 
- 
- class MergeCompleter(Completer, Merger):
--    def get_completions(self, base, buffer_, offset):
-+    def run(self, base, buffer_, offset):
-         if not self.instances:
-             self.create_instances()
-         results = set()
-         for prov in self.instances:
--            for res in prov.get_completions(base, buffer_, offset):
-+            for res in prov.run(base, buffer_, offset):
-                 if res in results:
-                     continue
-                 results.add(res)
-@@ -641,7 +594,7 @@ class JobServer(Log):
-             self._processes.append(np)
-         return self._processes[0]
- 
--    def get_instance(self, proxy, type_):
-+    def get_instance(self, proxy):
-         """
-         Returns the manager and the real instance of language plugin type of
-         the proxy.
-@@ -655,47 +608,17 @@ class JobServer(Log):
-         instances = self._instances[manager]
-         if id(proxy.document) not in instances:
-             instances[id(proxy.document)] = manager.dict()
--        if type_ not in instances[id(proxy.document)]:
-+        if proxy.mytype not in instances[id(proxy.document)]:
-             #no = getattr(manager, type_)(manager)(None, proxy.document)
--            instances[id(proxy.document)][type_] = getattr(manager, type_)(None, proxy.get_external_document())
--        return manager, instances[id(proxy.document)][type_]
-+            instances[id(proxy.document)][proxy.mytype] = getattr(manager, proxy.mytype)(None, proxy.get_external_document())
-+        return manager, instances[id(proxy.document)][proxy.mytype]
- 
-     @safe_remote
--    def get_validations(self, proxy):
-+    def run(self, proxy):
-         """Forwards to the external process"""
--        manager, instance = self.get_instance(proxy, 'validator')
--        for i in manager.get_validations(instance):
--            yield i
-+        manager, instance = self.get_instance(proxy)
-+        return manager.run(instance)
- 
--    @safe_remote
--    def get_outline(self, proxy):
--        """Forwards to the external process"""
--        manager, instance = self.get_instance(proxy, 'outliner')
--        for i in manager.get_outline(instance):
--            yield i
--
--    @safe_remote
--    def get_definition(self, proxy, buffer, offset):
--        """Forwards to the external process"""
--        manager, instance = self.get_instance(proxy, 'definer')
--        for i in manager.get_definition(instance, buffer, offset):
--            yield i
--
--    @safe_remote
--    def get_documentation(self, proxy, buffer, offset):
--        """Forwards to the external process"""
--        manager, instance = self.get_instance(proxy, 'documentator')
--        for i in manager.get_documentation(instance, buffer,
--                                                        offset):
--            yield i
--
--    @safe_remote
--    def get_completions(self, proxy, base, buffer, offset):
--        """Forwards to the external process"""
--        manager, instance = self.get_instance(proxy, 'completer')
--        for i in manager.get_completions(instance, base, buffer,
--                                                        offset):
--            yield i
- 
-     def stop(self):
-         self.stopped = True
-diff --git a/pida/editors/mooedit/mooedit.py b/pida/editors/mooedit/mooedit.py
---- a/pida/editors/mooedit/mooedit.py
-+++ b/pida/editors/mooedit/mooedit.py
-@@ -594,7 +594,7 @@ class PidaMooInput(object):
-         # we run the language completer first and the we add our own results
-         # to the completer list
-         if cmpl:
--            for i in cmpl.get_completions(self.svc.get_current_word(), 
-+            for i in cmpl.run(self.svc.get_current_word(), 
-                         unicode(self.editor.get_text()), start):
-                 try:
-                     if i not in ignore:
-diff --git a/pida/services/language/disabled.py b/pida/services/language/disabled.py
---- a/pida/services/language/disabled.py
-+++ b/pida/services/language/disabled.py
-@@ -40,7 +40,7 @@ class NoopOutliner(NoopBase, Outliner):
-     """
-     Noop outliner
-     """
--    def get_outline(self):
-+    def run(self):
-         return []
- 
- 
-@@ -50,14 +50,14 @@ class NoopValidator(NoopBase, Validator)
-     """
-     name = _("Disabled")
- 
--    def get_validations(self):
-+    def run(self):
-         return []
- 
- class NoopDefiner(NoopBase, Definer):
-     """
-     Noop definer
-     """
--    def get_definition(self, buffer, offset):
-+    def run(self, buffer, offset):
-         """
-         returns None
-         """
-@@ -68,7 +68,7 @@ class NoopDocumentator(NoopBase, Documen
-     Documentation receiver returns a Documentation object
-     """
- 
--    def get_documentation(self, buffer, offset):
-+    def run(self, buffer, offset):
-         """
-         return None
-         """
-@@ -77,7 +77,7 @@ class NoopDocumentator(NoopBase, Documen
- 
- class NoopCompleter(NoopBase, Completer):
- 
--    def get_completions(self, base, buffer_, offset):
-+    def run(self, base, buffer_, offset):
-         """
-         Gets a list of completitions.
-         
-diff --git a/pida/services/language/language.py b/pida/services/language/language.py
---- a/pida/services/language/language.py
-+++ b/pida/services/language/language.py
-@@ -571,7 +571,7 @@ class LanguageDbusConfig(DbusConfig):
-         doc = self.svc.boss.cmd('buffer', 'get_current')
-         completer = self.svc.get_completer(doc)
-         if completer is not None:
--            return list(completer.get_completions(base, buffer, offset))
-+            return list(completer.run(base, buffer, offset))
-         else:
-             return []
- 
-@@ -646,7 +646,7 @@ class Language(LanguageService):
-             title=_('Goto Definition'),
-             data=_('No support for this type found'), timeout=2000)
-             return
--        res = definer.get_definition(doc.content,
-+        res = definer.run(doc.content,
-                                      self.boss.editor.get_cursor_position())
- 
-         if isinstance(res, Definition):
-diff --git a/pida/services/language/views.py b/pida/services/language/views.py
---- a/pida/services/language/views.py
-+++ b/pida/services/language/views.py
-@@ -272,7 +272,7 @@ class ValidatorView(PidaView):
-             else:
-                 prio = PRIO_DEFAULT
- 
--            task = GeneratorTask(validator.get_validations_cached, 
-+            task = GeneratorTask(validator.run_cached, 
-                                  radd,
-                                  complete_callback=rcomp,
-                                  priority=prio)
-@@ -446,7 +446,7 @@ class BrowserView(PidaView):
-             else:
-                 prio = PRIO_DEFAULT
- 
--            task = GeneratorTask(outliner.get_outline_cached, 
-+            task = GeneratorTask(outliner.run_cached, 
-                                  radd,
-                                  complete_callback=rcomp,
-                                  priority=prio)

proxy-unification

-# HG changeset patch
-# Parent 795d0059ca8f72f49995a488991efdcd05bcc325
-unify the language external proxy generation
-
-diff --git a/pida/core/languages.py b/pida/core/languages.py
---- a/pida/core/languages.py
-+++ b/pida/core/languages.py
-@@ -456,7 +456,7 @@ class ExternalDocument(Document):
-         pass
-     project = property(_get_project, _set_project)
- 
--class ExternalProxy(object):
-+class ExternalProxy(BaseCachedDocumentHandler):
-     """
-     Base Class for all proxy objects.
-     """
-@@ -488,27 +488,6 @@ class ExternalProxy(object):
-     def run(self, *k, **kw):
-         return self.svc.jobserver.run(self)
- 
--
--class ExternalValidatorProxy(ExternalProxy, Validator):
--    """Proxies to the jobmanager and therefor to the external process"""
--    mytype = 'validator'
--
--class ExternalOutlinerProxy(ExternalProxy, Outliner):
--    """Proxies to the jobmanager and therefor to the external process"""
--    mytype = 'outliner'
--
--class ExternalDefinerProxy(ExternalProxy, Definer):
--    """Proxies to the jobmanager and therefor to the external process"""
--    mytype = 'definer'
--
--class ExternalDocumentatorProxy(ExternalProxy, Documentator):
--    """Proxies to the jobmanager and therefor to the external process"""
--    mytype = 'documenter'
--
--class ExternalCompleterProxy(ExternalProxy, Completer):
--    """Proxies to the jobmanager and therefor to the external process"""
--    mytype = 'completer'
--
- class Merger(BaseDocumentHandler):
-     """
-     Merges different sources of providers into one stream
-@@ -657,30 +636,28 @@ class LanguageService(Service):
-         if self.external is not None and multiprocessing:
-             # if we have multiprocessing support we exchange the
-             # language factories to the proxy objects
--            def newproxy(old, factory):
--                if old is None:
--                    return factory
--                class NewProxy(factory):
--                    pass
--                NewProxy._uuid = old.uuid()
--                NewProxy.priority = old.priority
--                NewProxy.name = old.name
--                NewProxy.plugin = old.plugin
--                NewProxy.description = old.description
-+            def newproxy(old, mytype_):
-+                class NewProxy(ExternalProxy):
-+                    mytype = mytype_
-+                    _uuid = old.uuid()
-+                    priority = old.priority
-+                    name = old.name
-+                    plugin = old.plugin
-+                    description = old.description
-+                    __name__ = 'External%sProxy' % mytype.capitalize()
-+                    try:
-+                        filter_type = old.filter_type
-+                    except AttributeError:
-+                        pass
-                 return NewProxy
- 
--            if self.external.validator:
--                self.validator_factory = newproxy(self.validator_factory, ExternalValidatorProxy)
--            if self.external.outliner:
--                ofac = self.outliner_factory
--                self.outliner_factory = newproxy(self.outliner_factory, ExternalOutlinerProxy)
--                self.outliner_factory.filter_type = ofac.filter_type
--            if self.external.documentator:
--                self.documentator_factory = newproxy(self.documentator_factory, ExternalDocumentatorProxy)
--            if self.external.definer:
--                self.definer_factory = newproxy(self.definer_factory, ExternalDefinerProxy)
--            if self.external.completer:
--                self.completer_factory = newproxy(self.completer_factory, ExternalCompleterProxy)
-+            for name in 'validator outliner documentator definer completer'.split():
-+                if getattr(self.external, name):
-+                    attr = name + '_factory'
-+                    old = getattr(self, attr)
-+                    proxy = newproxy(old, name)
-+                    setattr(self, attr, proxy)
-+
- 
-         super(LanguageService, self).__init__(boss)
-         self.boss = boss
-language-methodname-unification
-proxy-unification
 core-pdbus-pyxml-introspect #+dbus
 pida-remote-cleanup
 non-optional-core-pdbus #+dbus #-stable