mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 00:13:30 +00:00
Implement DocumentLink of GDScript LSP Server
This commit is contained in:
parent
d1a6964d39
commit
6a8303f82f
7 changed files with 99 additions and 4 deletions
|
@ -105,6 +105,40 @@ void ExtendGDScriptParser::update_symbols() {
|
|||
}
|
||||
}
|
||||
|
||||
void ExtendGDScriptParser::update_document_links(const String &p_code) {
|
||||
document_links.clear();
|
||||
|
||||
GDScriptTokenizerText tokenizer;
|
||||
FileAccessRef fs = FileAccess::create(FileAccess::ACCESS_RESOURCES);
|
||||
tokenizer.set_code(p_code);
|
||||
while (true) {
|
||||
if (tokenizer.get_token() == GDScriptTokenizer::TK_EOF) {
|
||||
break;
|
||||
} else if (tokenizer.get_token() == GDScriptTokenizer::TK_CONSTANT) {
|
||||
Variant const_val = tokenizer.get_token_constant();
|
||||
if (const_val.get_type() == Variant::STRING) {
|
||||
String path = const_val;
|
||||
bool exists = fs->file_exists(path);
|
||||
if (!exists) {
|
||||
path = get_path().get_base_dir() + "/" + path;
|
||||
exists = fs->file_exists(path);
|
||||
}
|
||||
if (exists) {
|
||||
String value = const_val;
|
||||
lsp::DocumentLink link;
|
||||
link.target = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_uri(path);
|
||||
link.range.start.line = LINE_NUMBER_TO_INDEX(tokenizer.get_token_line());
|
||||
link.range.end.line = link.range.start.line;
|
||||
link.range.end.character = LINE_NUMBER_TO_INDEX(tokenizer.get_token_column());
|
||||
link.range.start.character = link.range.end.character - value.length();
|
||||
document_links.push_back(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
tokenizer.advance();
|
||||
}
|
||||
}
|
||||
|
||||
void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p_class, lsp::DocumentSymbol &r_symbol) {
|
||||
|
||||
const String uri = get_uri();
|
||||
|
@ -572,6 +606,10 @@ const lsp::DocumentSymbol *ExtendGDScriptParser::get_member_symbol(const String
|
|||
return NULL;
|
||||
}
|
||||
|
||||
const List<lsp::DocumentLink> &ExtendGDScriptParser::get_document_links() const {
|
||||
return document_links;
|
||||
}
|
||||
|
||||
const Array &ExtendGDScriptParser::get_member_completions() {
|
||||
|
||||
if (member_completions.empty()) {
|
||||
|
@ -755,5 +793,6 @@ Error ExtendGDScriptParser::parse(const String &p_code, const String &p_path) {
|
|||
Error err = GDScriptParser::parse(p_code, p_path.get_base_dir(), false, p_path, false, NULL, false);
|
||||
update_diagnostics();
|
||||
update_symbols();
|
||||
update_document_links(p_code);
|
||||
return err;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue