RefactoringRope/CodeAssistServer.py

Wed, 27 Sep 2017 18:25:08 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 27 Sep 2017 18:25:08 +0200
branch
server_client_variant
changeset 198
898d8b4187de
parent 197
7046ac1bcb4b
child 199
ae2ad82725b0
permissions
-rw-r--r--

IMplemented the distributed code assist completions method.

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
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
15 from PyQt5.QtCore import pyqtSlot, QCoreApplication, QTimer
195
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__))
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
19
193
47d95438c4d8 Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 147
diff changeset
20 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
21
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
22 import Globals
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
23 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
24
118
d242ba11a04c Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 106
diff changeset
25
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
26 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
27 """
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 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
29 """
118
d242ba11a04c Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 106
diff changeset
30 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
31 """
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
32 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
33
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
34 @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
35 @type RefactoringRopePlugin
47d95438c4d8 Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 147
diff changeset
36 @param parent parent
47d95438c4d8 Started to change the CodeAssist class to support distributed operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 147
diff changeset
37 @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
38 """
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
39 super(CodeAssistServer, self).__init__(
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
40 "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
41
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
42 self.__plugin = plugin
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
43 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
44
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
45 self.__editorLanguageMapping = {}
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
46
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
47 # attributes to store the resuls of the client side
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
48 self.__completions = None
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
49 self.__calltips = None
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
50
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
51 self.__methodMapping = {
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
52 "CompletionsResult": self.__processCompletionsResult,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
53 }
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
54
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
55 # Python 2
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
56 interpreter = Preferences.getDebugger("PythonInterpreter")
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
57 self.__startCodeAssistClient(interpreter, "Python2")
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
58
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
59 # Python 3
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
60 interpreter = Preferences.getDebugger("Python3Interpreter")
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
61 self.__startCodeAssistClient(interpreter, "Python3")
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
62
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
63 def __updateEditorLanguageMapping(self):
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
64 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
65 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
66 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
67 self.__editorLanguageMapping = {}
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
68 for name in self.connectionNames():
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
69 if name == "Python2":
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
70 self.__editorLanguageMapping.update({
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
71 "Python": "Python2",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
72 "Python2": "Python2",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
73 "Pygments|Python": "Python2",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
74 })
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
75 elif name == "Python3":
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
76 self.__editorLanguageMapping.update({
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
77 "Python3": "Python3",
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
78 "Pygments|Python 3": "Python3",
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
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
81 def isSupportedLanguage(self, language):
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
82 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
83 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
84
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
85 @param language editor programming language to check
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
86 @type str
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
87 @return flag indicating the support status
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
88 @rtype bool
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
89 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
90 return language in self.__editorLanguageMapping
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
91
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
92 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
93 """
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
94 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
95
104
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
96 @param editor reference to the editor object, that called this method
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
97 @type QScintilla.Editor
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
98 @return list of proposals
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
99 @rtype list of str
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
100 """
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
101 # reset the completions buffer
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
102 self.__completions = None
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
103
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
104 language = editor.getLanguage()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
105 if language not in self.__editorLanguageMapping:
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
106 return []
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
107 idString = self.__editorLanguageMapping[language]
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
108
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
109 filename = editor.getFileName()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
110 line, index = editor.getCursorPosition()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
111 source = editor.text()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
112 offset = len("".join(source.splitlines(True)[:line])) + index
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
113 maxfixes = self.__plugin.getPreferences("MaxFixes")
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
114
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
115 self.sendJson("getCompletions", {
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
116 "FileName": filename,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
117 "Source": source,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
118 "Offset": offset,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
119 "MaxFixes": maxfixes,
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
120 }, idString=idString)
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
121
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
122 # emulate the synchronous behaviour
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
123 timer = QTimer()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
124 timer.setSingleShot(True)
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
125 timer.start(5000) # 5s timeout
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
126 while self.__completions is None and timer.isActive():
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
127 QCoreApplication.processEvents()
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
128
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
129 return [] if self.__completions is None else self.__completions
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
130
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
131 def __processCompletionsResult(self, result):
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
132 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
133 Private method to process the completions sent by the client.
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
134
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
135 @param result dictionary containg the result sent by the client
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
136 @type dict
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
137 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
138 if "Error" in result:
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
139 self.__completions = []
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
140 else:
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
141 self.__completions = result["Completions"]
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
142
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
143 # 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
144 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
145 """
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
146 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
147
118
d242ba11a04c Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 106
diff changeset
148 @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
149 @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
150 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
151 @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
152 """
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
153 print("rope: getCallTips")
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
154 return []
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
155 ## filename = editor.getFileName()
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
156 ## if filename:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
157 ## resource = rope.base.libutils.path_to_resource(
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
158 ## self.__project, filename)
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
159 ## else:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
160 ## resource = None
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
161 ## source = editor.text()
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
162 ## maxfixes = self.__plugin.getPreferences("CalltipsMaxFixes")
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
163 ## try:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
164 ## line, index = editor.lineIndexFromPosition(pos)
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
165 ## 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
166 ## cts = rope.contrib.codeassist.get_calltip(
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
167 ## self.__project, source, offset, resource, maxfixes=maxfixes,
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
168 ## remove_self=True)
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
169 ## if cts is not None:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
170 ## cts = [cts]
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
171 ## else:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
172 ## cts = []
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
173 ## except Exception:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
174 ## cts = []
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
175 ## 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
176
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
177 # 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
178 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
179 """
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
180 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
181
f6049d39f83d Made the code completion work in case no project is open.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 103
diff changeset
182 @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
183 @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
184 """
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
185 print("code assist: reportChanged")
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
186 ## try:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
187 ## rope.base.libutils.report_change(
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
188 ## self.__project, filename, oldSource)
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
189 ## except RuntimeError:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
190 ## # 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
191 ## # simply ignore it
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
192 ## pass
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
193
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
194 #######################################################################
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
195 ## Methods below handle the network connection
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
196 #######################################################################
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
197
198
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
198 def handleCall(self, method, params):
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
199 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
200 Public method to handle a method call from the client.
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
201
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
202 Note: This is an empty implementation that must be overridden in
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
203 derived classes.
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
204
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
205 @param method requested method name
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
206 @type str
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
207 @param params dictionary with method specific parameters
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
208 @type dict
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
209 """
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
210 self.__methodMapping[method](params)
898d8b4187de IMplemented the distributed code assist completions method.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
211
195
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
212 def __startCodeAssistClient(self, interpreter, idString):
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
213 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
214 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
215 interpreter.
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
216
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
217 @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
218 @type str
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
219 @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
220 @type str
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
221 @return flag indicating a successful client start
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
222 @rtype bool
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
223 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
224 if interpreter:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
225 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
226 "CodeAssistClient.py")
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
227 ok = self.startClient(interpreter, client,
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
228 [Globals.getConfigDir()],
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
229 idString=idString)
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
230 if not ok:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
231 self.__ui.appendToStderr(self.tr(
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
232 "'{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
233 " could not be started."
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
234 ).format(idString))
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
235 else:
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
236 self.__ui.appendToStderr(self.tr(
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
237 "'{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
238 " configured."
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
239 ).format(idString))
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
240
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
241 @pyqtSlot()
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
242 def handleNewConnection(self):
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
243 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
244 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
245 """
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
246 super(CodeAssistServer, self).handleNewConnection()
5d614a567be3 Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 193
diff changeset
247 self.__updateEditorLanguageMapping()
197
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
248
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
249 def activate(self):
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
250 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
251 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
252 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
253 pass
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
254
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
255 def deactivate(self):
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
256 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
257 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
258 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
259 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
260 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
261 """
7046ac1bcb4b Continued implementing the distributed Code Assist.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 195
diff changeset
262 self.stopAllClients()

eric ide

mercurial