feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -28,11 +28,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef TEST_LSP_H
#define TEST_LSP_H
#pragma once
#ifdef TOOLS_ENABLED
#include "modules/modules_enabled.gen.h" // For jsonrpc.
#ifdef MODULE_JSONRPC_ENABLED
#include "tests/test_macros.h"
#include "../language_server/gdscript_extend_parser.h"
@ -52,15 +55,15 @@
#include "thirdparty/doctest/doctest.h"
template <>
struct doctest::StringMaker<lsp::Position> {
static doctest::String convert(const lsp::Position &p_val) {
struct doctest::StringMaker<LSP::Position> {
static doctest::String convert(const LSP::Position &p_val) {
return p_val.to_string().utf8().get_data();
}
};
template <>
struct doctest::StringMaker<lsp::Range> {
static doctest::String convert(const lsp::Range &p_val) {
struct doctest::StringMaker<LSP::Range> {
static doctest::String convert(const LSP::Range &p_val) {
return p_val.to_string().utf8().get_data();
}
};
@ -102,32 +105,32 @@ GDScriptLanguageProtocol *initialize(const String &p_root) {
return proto;
}
lsp::Position pos(const int p_line, const int p_character) {
lsp::Position p;
LSP::Position pos(const int p_line, const int p_character) {
LSP::Position p;
p.line = p_line;
p.character = p_character;
return p;
}
lsp::Range range(const lsp::Position p_start, const lsp::Position p_end) {
lsp::Range r;
LSP::Range range(const LSP::Position p_start, const LSP::Position p_end) {
LSP::Range r;
r.start = p_start;
r.end = p_end;
return r;
}
lsp::TextDocumentPositionParams pos_in(const lsp::DocumentUri &p_uri, const lsp::Position p_pos) {
lsp::TextDocumentPositionParams params;
LSP::TextDocumentPositionParams pos_in(const LSP::DocumentUri &p_uri, const LSP::Position p_pos) {
LSP::TextDocumentPositionParams params;
params.textDocument.uri = p_uri;
params.position = p_pos;
return params;
}
const lsp::DocumentSymbol *test_resolve_symbol_at(const String &p_uri, const lsp::Position p_pos, const String &p_expected_uri, const String &p_expected_name, const lsp::Range &p_expected_range) {
const LSP::DocumentSymbol *test_resolve_symbol_at(const String &p_uri, const LSP::Position p_pos, const String &p_expected_uri, const String &p_expected_name, const LSP::Range &p_expected_range) {
Ref<GDScriptWorkspace> workspace = GDScriptLanguageProtocol::get_singleton()->get_workspace();
lsp::TextDocumentPositionParams params = pos_in(p_uri, p_pos);
const lsp::DocumentSymbol *symbol = workspace->resolve_symbol(params);
LSP::TextDocumentPositionParams params = pos_in(p_uri, p_pos);
const LSP::DocumentSymbol *symbol = workspace->resolve_symbol(params);
CHECK(symbol);
if (symbol) {
@ -140,7 +143,7 @@ const lsp::DocumentSymbol *test_resolve_symbol_at(const String &p_uri, const lsp
}
struct InlineTestData {
lsp::Range range;
LSP::Range range;
String text;
String name;
String ref;
@ -257,7 +260,7 @@ void test_resolve_symbol(const String &p_uri, const InlineTestData &p_test_data,
REQUIRE_MESSAGE(target, vformat("No target for ref '%s'", p_test_data.ref));
Ref<GDScriptWorkspace> workspace = GDScriptLanguageProtocol::get_singleton()->get_workspace();
lsp::Position pos = p_test_data.range.start;
LSP::Position pos = p_test_data.range.start;
SUBCASE("start of identifier") {
pos.character = p_test_data.range.start.character;
@ -308,17 +311,17 @@ void assert_no_errors_in(const String &p_path) {
REQUIRE_MESSAGE(err == OK, vformat("Errors while analyzing '%s'", p_path));
}
inline lsp::Position lsp_pos(int line, int character) {
lsp::Position p;
inline LSP::Position lsp_pos(int line, int character) {
LSP::Position p;
p.line = line;
p.character = character;
return p;
}
void test_position_roundtrip(lsp::Position p_lsp, GodotPosition p_gd, const PackedStringArray &p_lines) {
void test_position_roundtrip(LSP::Position p_lsp, GodotPosition p_gd, const PackedStringArray &p_lines) {
GodotPosition actual_gd = GodotPosition::from_lsp(p_lsp, p_lines);
CHECK_EQ(p_gd, actual_gd);
lsp::Position actual_lsp = p_gd.to_lsp(p_lines);
LSP::Position actual_lsp = p_gd.to_lsp(p_lines);
CHECK_EQ(p_lsp, actual_lsp);
}
@ -343,25 +346,25 @@ func f():
PackedStringArray lines = code.split("\n");
SUBCASE("line after end") {
lsp::Position lsp = lsp_pos(7, 0);
LSP::Position lsp = lsp_pos(7, 0);
GodotPosition gd(8, 1);
test_position_roundtrip(lsp, gd, lines);
}
SUBCASE("first char in first line") {
lsp::Position lsp = lsp_pos(0, 0);
LSP::Position lsp = lsp_pos(0, 0);
GodotPosition gd(1, 1);
test_position_roundtrip(lsp, gd, lines);
}
SUBCASE("with tabs") {
// On `v` in `value` in `var value := ...`.
lsp::Position lsp = lsp_pos(5, 6);
LSP::Position lsp = lsp_pos(5, 6);
GodotPosition gd(6, 13);
test_position_roundtrip(lsp, gd, lines);
}
SUBCASE("doesn't fail with column outside of character length") {
lsp::Position lsp = lsp_pos(2, 100);
LSP::Position lsp = lsp_pos(2, 100);
GodotPosition::from_lsp(lsp, lines);
GodotPosition gd(3, 100);
@ -369,7 +372,7 @@ func f():
}
SUBCASE("doesn't fail with line outside of line length") {
lsp::Position lsp = lsp_pos(200, 100);
LSP::Position lsp = lsp_pos(200, 100);
GodotPosition::from_lsp(lsp, lines);
GodotPosition gd(300, 100);
@ -378,26 +381,26 @@ func f():
SUBCASE("special case: zero column for root class") {
GodotPosition gd(1, 0);
lsp::Position expected = lsp_pos(0, 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(0, 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
SUBCASE("special case: zero line and column for root class") {
GodotPosition gd(0, 0);
lsp::Position expected = lsp_pos(0, 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(0, 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
SUBCASE("special case: negative line for root class") {
GodotPosition gd(-1, 0);
lsp::Position expected = lsp_pos(0, 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(0, 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
SUBCASE("special case: lines.length() + 1 for root class") {
GodotPosition gd(lines.size() + 1, 0);
lsp::Position expected = lsp_pos(lines.size(), 0);
lsp::Position actual = gd.to_lsp(lines);
LSP::Position expected = lsp_pos(lines.size(), 0);
LSP::Position actual = gd.to_lsp(lines);
CHECK_EQ(actual, expected);
}
}
@ -489,15 +492,21 @@ func f():
REQUIRE(proto);
SUBCASE("selectionRange of root class must be inside range") {
String path = "res://lsp/first_line_comment.gd";
assert_no_errors_in(path);
GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_local_script(path);
ExtendGDScriptParser *parser = GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_results[path];
REQUIRE(parser);
lsp::DocumentSymbol cls = parser->get_symbols();
LocalVector<String> paths = {
"res://lsp/first_line_comment.gd", // Comment on first line
"res://lsp/first_line_class_name.gd", // class_name (and thus selection range) before extends
};
REQUIRE(((cls.range.start.line == cls.selectionRange.start.line && cls.range.start.character <= cls.selectionRange.start.character) || (cls.range.start.line < cls.selectionRange.start.line)));
REQUIRE(((cls.range.end.line == cls.selectionRange.end.line && cls.range.end.character >= cls.selectionRange.end.character) || (cls.range.end.line > cls.selectionRange.end.line)));
for (const String &path : paths) {
assert_no_errors_in(path);
GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_local_script(path);
ExtendGDScriptParser *parser = GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_results[path];
REQUIRE(parser);
LSP::DocumentSymbol cls = parser->get_symbols();
REQUIRE(((cls.range.start.line == cls.selectionRange.start.line && cls.range.start.character <= cls.selectionRange.start.character) || (cls.range.start.line < cls.selectionRange.start.line)));
REQUIRE(((cls.range.end.line == cls.selectionRange.end.line && cls.range.end.character >= cls.selectionRange.end.character) || (cls.range.end.line > cls.selectionRange.end.line)));
}
}
memdelete(proto);
@ -507,6 +516,6 @@ func f():
} // namespace GDScriptTests
#endif // TOOLS_ENABLED
#endif // MODULE_JSONRPC_ENABLED
#endif // TEST_LSP_H
#endif // TOOLS_ENABLED