pyQode uses a client-server architecture for running heavy tasks such as code analysis (lint), code completion,...
We use a worker based json messaging server using the TCP/IP transport.
We build our own, very simple protocol where each message is made up of two parts:
- a header: simply contains the length of the payload
- a payload: a json formatted string, the content of the message.
There are two type of json object: a request and a response.
For a request, the object will contains the following fields:
- ‘request_id’: uuid generated client side
- ‘worker’: fully qualified name to the worker callable (class or function), e.g. ‘pyqode.core.backend.workers.echo_worker’
- ‘data’: data specific to the chose worker.
E.g:
{
'request_id': 'a97285af-cc88-48a4-ac69-7459b9c7fa66',
'worker': 'pyqode.core.backend.workers.echo_worker',
'data': ['some code', 0]
}
E.g:
{
'request_id': 'a97285af-cc88-48a4-ac69-7459b9c7fa66',
'results': ['some code', 0]
}
The server script must be written by the user. Don’t worry, it’s very simple. All you have to do is to create and run a JsonTcpServer instance.
We choose to let you write the main script to let you easily configure it.
Some workers will requires some tweaking (for the completion worker, you will want to add custom completion providers, you might also want to modify sys.path,...). It also makes the packaging process more consistent, your script will be packaged on linux using setup.py and will be frozen on windows using cx_Freeze.
Here is the most simple and basic example of a server script:
Warning
The user can choose the python interpreter that will run the server. That means that classes and functions that run on the server side ( workers) should fully support python2 syntax and that pyqode.core should be installed on the target interpreter sys path!!! (even for a virtual env). An alternative is to keep pyqode.core package (and all dependencies in a zip archive that you mount on the sys path in your server script.
Note
print statements on the server side will be logged as debug messages on the client side. To have your messages logged as error message just print to sys.stderr.
Bases: builtins.object
This is the worker associated with the code completion mode.
The worker does not actually do anything smart, the real work of collecting code completions is accomplished by the completion providers (see the pyqode.core.backend.workers.CodeCompletionWorker.Provider interface) listed in pyqode.core.backend.workers.CompletionWorker.providers.
Completion providers must be installed on the CodeCompletionWorker at the beginning of the main server script, e.g.:
from pyqode.core.backend import CodeCompletionWorker
CodeCompletionWorker.providers.insert(0, MyProvider())
Bases: builtins.object
This class describes the expected interface for code completion providers.
You can inherit from this class but this is not required as long as you implement a complete method which returns the list of completions and have the expected signature:
def complete(self, code, line, column, path, encoding, prefix):
pass
Returns a list of completions.
A completion is dictionary with the following keys:
- ‘name’: name of the completion, this the text displayed and inserted when the user select a completion in the list
- ‘icon’: an optional icon file name
- ‘tooltip’: an optional tooltip string
Parameters: |
|
---|---|
Returns: | A list of completion dicts as described above. |
Return type: | list |
The list of code completion provider to run on each completion request.
Bases: builtins.object
Provides completions based on the document words
Provides completions based on the document words.
Parameters: |
|
---|
Splits a text in a meaningful list of words based on a list of word separators (define in pyqode.core.settings)
Parameters: |
|
---|---|
Returns: | A set of words found in the document (excluding punctuations, numbers, ...) |
Bases: socketserver.ThreadingTCPServer
A server socket based on a json messaging system.
Configures and return the default argument parser. You should use this parser as a base if you want to add custom arguments.
The default parser only has one argument, the tcp port used to start the server socket. (CodeEdit picks up a free port and use it to run the server and connect its client socket)
Returns: | The default server argument parser. |
---|