1. Ronny Pfannschmidt
  2. pida-patches

Source

pida-patches / language-methodname-unification

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# 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)