mirror of
https://github.com/godotengine/godot.git
synced 2025-11-02 06:31:13 +00:00
GDScript LSP: Implement signatureHelp
Enable smart resolve default to true as it is required for script symbol lookup
This commit is contained in:
parent
bdcfc6d633
commit
d35c018a7a
8 changed files with 232 additions and 1 deletions
|
|
@ -252,6 +252,12 @@ Error GDScriptWorkspace::initialize() {
|
|||
bool arg_default_value_started = false;
|
||||
for (int j = 0; j < data.arguments.size(); j++) {
|
||||
const DocData::ArgumentDoc &arg = data.arguments[j];
|
||||
|
||||
lsp::DocumentSymbol symbol_arg;
|
||||
symbol_arg.name = arg.name;
|
||||
symbol_arg.kind = lsp::SymbolKind::Variable;
|
||||
symbol_arg.detail = arg.type;
|
||||
|
||||
if (!arg_default_value_started && !arg.default_value.empty()) {
|
||||
arg_default_value_started = true;
|
||||
}
|
||||
|
|
@ -263,6 +269,8 @@ Error GDScriptWorkspace::initialize() {
|
|||
arg_str += ", ";
|
||||
}
|
||||
params += arg_str;
|
||||
|
||||
symbol.children.push_back(symbol_arg);
|
||||
}
|
||||
if (data.qualifiers.find("vararg") != -1) {
|
||||
params += params.empty() ? "..." : ", ...";
|
||||
|
|
@ -513,6 +521,49 @@ Dictionary GDScriptWorkspace::generate_script_api(const String &p_path) {
|
|||
return api;
|
||||
}
|
||||
|
||||
Error GDScriptWorkspace::resolve_signature(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::SignatureHelp &r_signature) {
|
||||
if (const ExtendGDScriptParser *parser = get_parse_result(get_file_path(p_doc_pos.textDocument.uri))) {
|
||||
|
||||
lsp::TextDocumentPositionParams text_pos;
|
||||
text_pos.textDocument = p_doc_pos.textDocument;
|
||||
|
||||
if (parser->get_left_function_call(p_doc_pos.position, text_pos.position, r_signature.activeParameter) == OK) {
|
||||
|
||||
List<const lsp::DocumentSymbol *> symbols;
|
||||
|
||||
if (const lsp::DocumentSymbol *symbol = resolve_symbol(text_pos)) {
|
||||
symbols.push_back(symbol);
|
||||
} else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) {
|
||||
GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_related_symbols(text_pos, symbols);
|
||||
}
|
||||
|
||||
for (List<const lsp::DocumentSymbol *>::Element *E = symbols.front(); E; E = E->next()) {
|
||||
const lsp::DocumentSymbol *symbol = E->get();
|
||||
if (symbol->kind == lsp::SymbolKind::Method || symbol->kind == lsp::SymbolKind::Function) {
|
||||
|
||||
lsp::SignatureInformation signature_info;
|
||||
signature_info.label = symbol->detail;
|
||||
signature_info.documentation = symbol->render();
|
||||
|
||||
for (int i = 0; i < symbol->children.size(); i++) {
|
||||
const lsp::DocumentSymbol &arg = symbol->children[i];
|
||||
lsp::ParameterInformation arg_info;
|
||||
arg_info.label = arg.name;
|
||||
signature_info.parameters.push_back(arg_info);
|
||||
}
|
||||
r_signature.signatures.push_back(signature_info);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (r_signature.signatures.size()) {
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ERR_METHOD_NOT_FOUND;
|
||||
}
|
||||
|
||||
GDScriptWorkspace::GDScriptWorkspace() {
|
||||
ProjectSettings::get_singleton()->get_resource_path();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue