Tue, 26 Sep 2017 19:05:18 +0200
Continued implementing the distributed Code Assist.
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
147
3f8a995f6e49
Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
144
diff
changeset
|
3 | # Copyright (c) 2008 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the autocompletion interface to rope. |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
101
5098ad8960ed
Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
100
diff
changeset
|
10 | from __future__ import unicode_literals |
5098ad8960ed
Fixed issues connecting/disconnecting editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
100
diff
changeset
|
11 | |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | import os |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | import sys |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
15 | from PyQt5.QtCore import pyqtSlot |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
16 | |
197
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
17 | # TODO: eliminate this |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | sys.path.insert(0, os.path.dirname(__file__)) |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
19 | ##if sys.version_info[0] >= 3: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
20 | ## path = os.path.join(os.path.dirname(__file__), 'rope_py3') |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
21 | ##else: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
22 | ## path = os.path.join(os.path.dirname(__file__), 'rope_py2') |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
23 | ## str = unicode # __IGNORE_WARNING__ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
24 | ##sys.path.insert(0, path) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
25 | ## |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
26 | ##import rope.base.libutils |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
27 | ##import rope.contrib.codeassist |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | |
119
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
29 | from QScintilla.Editor import Editor |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
30 | |
193
47d95438c4d8
Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
147
diff
changeset
|
31 | from JsonServer import JsonServer |
47d95438c4d8
Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
147
diff
changeset
|
32 | |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
33 | import Globals |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
34 | import Preferences |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
35 | |
118
d242ba11a04c
Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
106
diff
changeset
|
36 | |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
37 | class CodeAssistServer(JsonServer): |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | Class implementing the autocompletion interface to rope. |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | """ |
119
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
41 | PictureIDs = { |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
42 | "class": "?{0}".format(Editor.ClassID), |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
43 | "instance": "?{0}".format(Editor.ClassID), |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
44 | "function": "?{0}".format(Editor.MethodID), |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
45 | "module": "?{0}".format(Editor.AttributeID), |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
46 | "None": "", |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
47 | } |
a03f2be1997b
Added some eye-candy and made the method to get a list of completions publicly available.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
118
diff
changeset
|
48 | |
118
d242ba11a04c
Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
106
diff
changeset
|
49 | def __init__(self, plugin, parent=None): |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | """ |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | Constructor |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | @param plugin reference to the plugin object |
193
47d95438c4d8
Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
147
diff
changeset
|
54 | @type RefactoringRopePlugin |
47d95438c4d8
Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
147
diff
changeset
|
55 | @param parent parent |
47d95438c4d8
Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
147
diff
changeset
|
56 | @type QObject |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | """ |
197
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
58 | super(CodeAssistServer, self).__init__( |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
59 | "CodeAssistServer", multiplex=True, parent=parent) |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | self.__plugin = plugin |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
62 | self.__ui = parent |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
63 | |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
64 | self.__editorLanguageMapping = {} |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
65 | |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
66 | # Python 2 |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
67 | interpreter = Preferences.getDebugger("PythonInterpreter") |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
68 | self.__startCodeAssistClient(interpreter, "Python2") |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
69 | |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
70 | # Python 3 |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
71 | interpreter = Preferences.getDebugger("Python3Interpreter") |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
72 | self.__startCodeAssistClient(interpreter, "Python3") |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
73 | ## self.__project = rope.base.project.Project(Globals.getConfigDir()) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
74 | ## self.__project.validate(self.__project.root) |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
76 | def __updateEditorLanguageMapping(self): |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
77 | """ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
78 | Private method to update the editor language to connection mapping. |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
79 | """ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
80 | self.__editorLanguageMapping = {} |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
81 | for name in self.connectionNames(): |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
82 | if name == "Python2": |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
83 | self.__editorLanguageMapping.update({ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
84 | "Python": "Python2", |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
85 | "Python2": "Python2", |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
86 | "Pygments|Python": "Python2", |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
87 | }) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
88 | elif name == "Python3": |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
89 | self.__editorLanguageMapping.update({ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
90 | "Python3": "Python3", |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
91 | "Pygments|Python 3": "Python3", |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
92 | }) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
93 | |
197
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
94 | def isSupportedLanguage(self, language): |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
95 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
96 | Public method to check, if the given language is supported. |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
97 | |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
98 | @param language editor programming language to check |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
99 | @type str |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
100 | @return flag indicating the support status |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
101 | @rtype bool |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
102 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
103 | return language in self.__editorLanguageMapping |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
104 | |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
105 | # TODO: port this to the distributed variant |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
106 | def getCompletions(self, editor): |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | """ |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | Public method to calculate the possible completions. |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
110 | @param editor reference to the editor object, that called this method |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
111 | QScintilla.Editor) |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | @return list of proposals (QStringList) |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | """ |
197
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
114 | print("rope: getCompletions") |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
115 | return [] |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
116 | ## filename = editor.getFileName() |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
117 | ## if filename: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
118 | ## resource = rope.base.libutils.path_to_resource( |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
119 | ## self.__project, filename) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
120 | ## else: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
121 | ## resource = None |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
122 | ## line, index = editor.getCursorPosition() |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
123 | ## source = editor.text() |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
124 | ## offset = len("".join(source.splitlines(True)[:line])) + index |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
125 | ## maxfixes = self.__plugin.getPreferences("MaxFixes") |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
126 | ## try: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
127 | ## proposals = rope.contrib.codeassist.code_assist( |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
128 | ## self.__project, source, offset, resource, maxfixes=maxfixes) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
129 | ## proposals = rope.contrib.codeassist.sorted_proposals(proposals) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
130 | ## names = [proposal.name + self.PictureIDs[proposal.type] |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
131 | ## for proposal in proposals] |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
132 | ## return names |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
133 | ## except Exception: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
134 | ## return [] |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
136 | # TODO: port this to the distributed variant |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
137 | def getCallTips(self, pos, editor): |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | """ |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | Public method to calculate calltips. |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | |
118
d242ba11a04c
Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
106
diff
changeset
|
141 | @param pos position in the text for the calltip (integer) |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
142 | @param editor reference to the editor object, that called this method |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
143 | QScintilla.Editor) |
100
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | @return list of possible calltips (list of strings) |
2bfe9e3fad8d
Ported the code completion and calltips support of the eric4 variant of this plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | """ |
197
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
146 | print("rope: getCallTips") |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
147 | return [] |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
148 | ## filename = editor.getFileName() |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
149 | ## if filename: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
150 | ## resource = rope.base.libutils.path_to_resource( |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
151 | ## self.__project, filename) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
152 | ## else: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
153 | ## resource = None |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
154 | ## source = editor.text() |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
155 | ## maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes") |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
156 | ## try: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
157 | ## line, index = editor.lineIndexFromPosition(pos) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
158 | ## offset = len("".join(source.splitlines(True)[:line])) + index |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
159 | ## cts = rope.contrib.codeassist.get_calltip( |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
160 | ## self.__project, source, offset, resource, maxfixes=maxfixes, |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
161 | ## remove_self=True) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
162 | ## if cts is not None: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
163 | ## cts = [cts] |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
164 | ## else: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
165 | ## cts = [] |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
166 | ## except Exception: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
167 | ## cts = [] |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
168 | ## return cts |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
169 | |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
170 | # TODO: port this to the distributed variant |
104
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
171 | def reportChanged(self, filename, oldSource): |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
172 | """ |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
173 | Public slot to report some changed sources. |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
174 | |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
175 | @param filename file name of the changed source (string) |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
176 | @param oldSource source code before the change (string) |
f6049d39f83d
Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
103
diff
changeset
|
177 | """ |
197
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
178 | print("rope: reportChanged") |
195
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
179 | ## try: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
180 | ## rope.base.libutils.report_change( |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
181 | ## self.__project, filename, oldSource) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
182 | ## except RuntimeError: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
183 | ## # this could come from trying to do PyQt4/PyQt5 mixed stuff |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
184 | ## # simply ignore it |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
185 | ## pass |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
186 | |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
187 | ####################################################################### |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
188 | ## Methods below handle the network connection |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
189 | ####################################################################### |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
190 | |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
191 | def __startCodeAssistClient(self, interpreter, idString): |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
192 | """ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
193 | Private method to start the code assist client with the given |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
194 | interpreter. |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
195 | |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
196 | @param interpreter interpreter to be used for the code assist client |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
197 | @type str |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
198 | @param idString id of the client to be started |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
199 | @type str |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
200 | @return flag indicating a successful client start |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
201 | @rtype bool |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
202 | """ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
203 | if interpreter: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
204 | client = os.path.join(os.path.dirname(__file__), |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
205 | "CodeAssistClient.py") |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
206 | ok = self.startClient(interpreter, client, |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
207 | [Globals.getConfigDir()], |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
208 | idString=idString) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
209 | if not ok: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
210 | self.__ui.appendToStderr(self.tr( |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
211 | "'{0}' is not supported because the configured interpreter" |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
212 | " could not be started." |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
213 | ).format(idString)) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
214 | else: |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
215 | self.__ui.appendToStderr(self.tr( |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
216 | "'{0}' is not supported because no suitable interpreter is" |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
217 | " configured." |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
218 | ).format(idString)) |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
219 | |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
220 | @pyqtSlot() |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
221 | def handleNewConnection(self): |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
222 | """ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
223 | Public slot for new incoming connections from a client. |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
224 | """ |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
225 | super(CodeAssistServer, self).handleNewConnection() |
5d614a567be3
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
193
diff
changeset
|
226 | self.__updateEditorLanguageMapping() |
197
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
227 | |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
228 | def activate(self): |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
229 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
230 | Public method to activate the code assist server. |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
231 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
232 | pass |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
233 | |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
234 | def deactivate(self): |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
235 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
236 | Public method to deactivate the code assist server. |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
237 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
238 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
239 | Public method to shut down the code assist server. |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
240 | """ |
7046ac1bcb4b
Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
195
diff
changeset
|
241 | self.stopAllClients() |