mirror of
https://github.com/godotengine/godot.git
synced 2025-10-24 02:13:36 +00:00
Implement LSP didSave notify and rename request
This commit is contained in:
parent
de3168ffa3
commit
802bb9c01f
5 changed files with 167 additions and 2 deletions
|
|
@ -40,10 +40,12 @@
|
|||
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("didSave"), &GDScriptTextDocument::didSave);
|
||||
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);
|
||||
ClassDB::bind_method(D_METHOD("rename"), &GDScriptTextDocument::rename);
|
||||
ClassDB::bind_method(D_METHOD("foldingRange"), &GDScriptTextDocument::foldingRange);
|
||||
ClassDB::bind_method(D_METHOD("codeLens"), &GDScriptTextDocument::codeLens);
|
||||
ClassDB::bind_method(D_METHOD("documentLink"), &GDScriptTextDocument::documentLink);
|
||||
|
|
@ -72,6 +74,14 @@ void GDScriptTextDocument::didChange(const Variant &p_param) {
|
|||
sync_script_content(doc.uri, doc.text);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::didSave(const Variant &p_param) {
|
||||
lsp::TextDocumentItem doc = load_document_item(p_param);
|
||||
Dictionary dict = p_param;
|
||||
String text = dict["text"];
|
||||
|
||||
sync_script_content(doc.uri, text);
|
||||
}
|
||||
|
||||
lsp::TextDocumentItem GDScriptTextDocument::load_document_item(const Variant &p_param) {
|
||||
lsp::TextDocumentItem doc;
|
||||
Dictionary params = p_param;
|
||||
|
|
@ -209,6 +219,14 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) {
|
|||
return arr;
|
||||
}
|
||||
|
||||
Dictionary GDScriptTextDocument::rename(const Dictionary &p_params) {
|
||||
lsp::TextDocumentPositionParams params;
|
||||
params.load(p_params);
|
||||
String new_name = p_params["newName"];
|
||||
|
||||
return GDScriptLanguageProtocol::get_singleton()->get_workspace()->rename(params, new_name);
|
||||
}
|
||||
|
||||
Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) {
|
||||
lsp::CompletionItem item;
|
||||
item.load(p_params);
|
||||
|
|
@ -399,7 +417,11 @@ GDScriptTextDocument::~GDScriptTextDocument() {
|
|||
void GDScriptTextDocument::sync_script_content(const String &p_path, const String &p_content) {
|
||||
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(p_path);
|
||||
GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_script(path, p_content);
|
||||
|
||||
EditorFileSystem::get_singleton()->update_file(path);
|
||||
Ref<GDScript> script = ResourceLoader::load(path);
|
||||
script->load_source_code(path);
|
||||
script->reload(true);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::show_native_symbol_in_editor(const String &p_symbol_id) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue