GDScript Language Server aspiring to implement the LSP specification as a Module for Godot.
- Following the Compiling Instructions for your platform with tools included to verify you have a working build.
- Add as a submodule to your godot source directory, e.g.:
git submodule add https://github.com/bdunks/gdscript-language-server modules/gdscript-language_server - Rebuild using the compilation steps from step #1
The server will begin listeng to http://localhost:46368 for new clients when the Godot Project Manager or Godot Editor starts (:46368 = G-O-D-O-T).
For compatibility with the vscode-jsonrpc (which is used as the base for both VSCode and Atom-IDE language client implementations), the langauge server expects the client to open its own TCP socket.
The request to :46368 should be a simply json post, telling the language server to create a connection to a specific port:
{
host: '127.0.0.1',
port: {port negotiated by client}
}
The jsonrpc requests/notifications will be processed on these connection(s) while they remain open. Requests to :46368 can only open new connections -- it will not respond to jsonrpc commands.
- GDScript for Atom IDE (ide-gdscript) - Currently under development in parrallel with this language server
| Procedure | Message Type | Status |
|---|---|---|
| initialize | Request | Stub |
| Completion | Request | Stub |
| didOpen | Notification | Stub |
The LSP protocol message structures have been defined within ./lsp/protocal/*, and currently far outstrip the current implementation. To increase coverage of the language server:
Create a Procedure
Note: When {procedure_name} / {ProcedureName} (in brackets) is used below, is meant to refer to the short name of the new procedure being added. {procedure_name} referres to .h / .cpp file names, and {ProcedureName} refers to class names.
The JSON-RPC procedures for Notifications and Requests are created as subclasses to ./lsp/procedures/procedure.
- Add a new class to
./lsp/procedures- Procedure handler's file and class names should match the simplified LSP Notification or Request Name (i.e.,
did_open, nottext_document_did_open) - This is to avoid excessive namespacing of
text_document_andworkspace_when there are no conflicts in the current protocol.
- Procedure handler's file and class names should match the simplified LSP Notification or Request Name (i.e.,
- The class should inherit from
procedure. - Register the class and its
runmethod in the Godot ClassDB, which allows us to use Godot Variant::call("method") functionality in our dispatcher:- In the header file, include
GDCLASS({ProcedureName}, Procedure);directly inside the class declaration - Override the protectected static method
_bind_methods()toClassDB::bind_method(D_METHOD("run", "parameters"), &{ProcedureName}::invoke);
- In the header file, include
Procedure Structure
The Procedure receives and return a Godot Variant Object
- Both the input and return structures can typically be represented as Dictionaries; however, they are defined as Variants for extra flexibility
- The
¶metersare restricted to what is in theparamskey of the inbound RequestMessage or NotificationMessage.- The "jsonrpc" and "id" have will be re-applied automatically to the response
- The "method" is implicit in the procedure being called
- The return structure should be restricted to the structure attached to the 'result' key
Registering new Procedures
- Add two lines to
./language_server_dispatcher.cppto register the procedures- Preprocessor:
#include {procedure_name}.h; - Constructor:
_register_procedure<lsp::{ProcedureName}>(String("{textDocument|workspace}/{ProcedureName}"));
- Preprocessor:
- If necessary, update
./lsp/proceedures/initialize.cppto register additional server capabilities with the client
MIT License. See the license for more details.