mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Add custom api textDocument/nativeSymbol
to allow inspect native symbols from LSP clients
This commit is contained in:
parent
39813939fc
commit
e199488bc7
6 changed files with 58 additions and 5 deletions
|
@ -39,6 +39,7 @@
|
|||
void GDScriptTextDocument::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("didOpen"), &GDScriptTextDocument::didOpen);
|
||||
ClassDB::bind_method(D_METHOD("didChange"), &GDScriptTextDocument::didChange);
|
||||
ClassDB::bind_method(D_METHOD("nativeSymbol"), &GDScriptTextDocument::nativeSymbol);
|
||||
ClassDB::bind_method(D_METHOD("documentSymbol"), &GDScriptTextDocument::documentSymbol);
|
||||
ClassDB::bind_method(D_METHOD("completion"), &GDScriptTextDocument::completion);
|
||||
ClassDB::bind_method(D_METHOD("resolve"), &GDScriptTextDocument::resolve);
|
||||
|
@ -75,6 +76,11 @@ lsp::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_
|
|||
return doc;
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::notify_client_show_symbol(const lsp::DocumentSymbol *symbol) {
|
||||
ERR_FAIL_NULL(symbol);
|
||||
GDScriptLanguageProtocol::get_singleton()->notify_client("gdscript/show_native_symbol", symbol->to_json(true));
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::initialize() {
|
||||
|
||||
if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
|
||||
|
@ -102,6 +108,21 @@ void GDScriptTextDocument::initialize() {
|
|||
}
|
||||
}
|
||||
|
||||
Variant GDScriptTextDocument::nativeSymbol(const Dictionary &p_params) {
|
||||
|
||||
Variant ret;
|
||||
|
||||
lsp::NativeSymbolInspectParams params;
|
||||
params.load(p_params);
|
||||
|
||||
if (const lsp::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_native_symbol(params)) {
|
||||
ret = symbol->to_json(true);
|
||||
notify_client_show_symbol(symbol);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Array GDScriptTextDocument::documentSymbol(const Dictionary &p_params) {
|
||||
Dictionary params = p_params["textDocument"];
|
||||
String uri = params["uri"];
|
||||
|
@ -362,7 +383,7 @@ Array GDScriptTextDocument::definition(const Dictionary &p_params) {
|
|||
}
|
||||
call_deferred("show_native_symbol_in_editor", id);
|
||||
} else {
|
||||
GDScriptLanguageProtocol::get_singleton()->notify_client("gdscript/show_native_symbol", symbol->to_json(true));
|
||||
notify_client_show_symbol(symbol);
|
||||
}
|
||||
}
|
||||
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue