Skip to content

Commit

Permalink
[LSP] checl rename conflict of named exported symbols. close #717
Browse files Browse the repository at this point in the history
  • Loading branch information
sekiguchi-nagisa committed Dec 4, 2023
1 parent f910a99 commit 702424b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/lsp.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@
| variable (upper variable) | ✔️ | ✔️ | ✔️ | ✔️ |
| variable (global import) | ✔️ | ✔️ | ✔️ | ✔️ |
| variable (inlined import) | ✔️ | ✔️ | ✔️ | ✔️ |
| variable (named import) | ✔️ | ✔️ | ✔️ | |
| variable (named import) | ✔️ | ✔️ | ✔️ | ✔️ |
| variable (positional parameter) | - | - | ❌ (show code) | - |
| variable (if-let) | ✔️ | ✔️ | ✔️ | ✔️ |
| builtin variable | - | - | ✔️ | - |
| builtin constant | - | - | ✔️ (show value) | - |
| function | ✔️ | ✔️ | ✔️ | ✔️ |
| function (global import) | ✔️ | ✔️ | ✔️ | ✔️ |
| function (inlined import) | ✔️ | ✔️ | ✔️ | ✔️ |
| function (named import) | ✔️ | ✔️ | ✔️ | |
| function (named import) | ✔️ | ✔️ | ✔️ | ✔️ |
| user-defined command | ✔️ | ✔️ | ✔️ | ✔️ |
| user-defined command (global import) | ✔️ | ✔️ | ✔️ | ✔️ |
| user-defined command (inlined import) | ✔️ | ✔️️ | ✔️ | ✔️ |
| user-defined command (named import) | ✔️ | ✔️️️ | ✔️️ | |
| user-defined command (named import) | ✔️ | ✔️️️ | ✔️️ | ✔️ |
| builtin command | - | ✔️ | ✔️️ (show help) | - |
| type (builtin) | - | ✔️️️ | ✔️️️ | - |
| type (alias) | ✔️ | ✔️ | ✔️ | ✔️ |
| type (global import) | ✔️ | ✔️ | ✔️ | ✔️ |
| type (inlined import) | ✔️ | ✔️️ | ✔️ | ✔️ |
| type (named import) | ✔️ | ✔️ | ✔️ | |
| type (named import) | ✔️ | ✔️ | ✔️ | ✔️ |
| type (user-defined type) | ✔️ | ✔️ | ✔️ | ✔️ |
| field (tuple) | - | ✔️ (same module only) | ✔️ | - |
| field (user-defined type) | ✔️ | ✔️ | ✔️ ||
Expand Down
62 changes: 62 additions & 0 deletions test/analyzer/rename_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,68 @@ new TTT().size()
"DDD", {1, "(1:5~1:8)"}));
}

TEST_F(RenameTest, namedImported) {
ydsh::TempFileFactory tempFileFactory("ydsh_rename");
auto fileName = tempFileFactory.createTempFile("mod1.ds", R"(
var EEE = 34
{ var WWW : Int? }
eee() {}
typedef TTT : Error
function size() : Int for TTT { return 234; }
function fff() {}
)");

auto content = format(R"(
var DDD = ''
ddd() {}
typedef DDD = Int
{ var CCC = 34; }
source %s as mod
{ var FFF = 34; }
$mod.EEE
mod eee
new mod.TTT().size()
$mod.fff()
)",
fileName.c_str());
ASSERT_NO_FATAL_FAILURE(this->doAnalyze(content.c_str(), 1));

// rename field access via module
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 1, .character = 5}, "CCC",
{{2, "(1:4~1:7)"}, {1, "(7:5~7:8)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 1, .character = 5}, "DDD",
{{2, "(1:4~1:7)"}, {1, "(7:5~7:8)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 1, .character = 5}, "FFF",
{{2, "(1:4~1:7)"}, {1, "(7:5~7:8)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 1, .character = 5}, "mod",
{{2, "(1:4~1:7)"}, {1, "(7:5~7:8)"}}));

// rename sub-command
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 3, .character = 1}, "fff",
{{2, "(3:0~3:3)"}, {1, "(8:4~8:7)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 3, .character = 1}, "ddd",
{{2, "(3:0~3:3)"}, {1, "(8:4~8:7)"}}));

// rename type field access via mod
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 4, .character = 9}, "UUU",
{{2, "(4:8~4:11)"}, {2, "(5:26~5:29)"}, {1, "(9:8~9:11)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 4, .character = 9}, "DDD",
{{2, "(4:8~4:11)"}, {2, "(5:26~5:29)"}, {1, "(9:8~9:11)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 4, .character = 9}, "mod",
{{2, "(4:8~4:11)"}, {2, "(5:26~5:29)"}, {1, "(9:8~9:11)"}}));

ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 5, .character = 9}, "empty",
{{2, "(5:9~5:13)"}, {1, "(9:14~9:18)"}}));

// rename method call (function via module)
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 6, .character = 9}, "ggg",
{{2, "(6:9~6:12)"}, {1, "(10:5~10:8)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 6, .character = 9}, "CCC",
{{2, "(6:9~6:12)"}, {1, "(10:5~10:8)"}}));
ASSERT_NO_FATAL_FAILURE(this->rename(Request{.modId = 2, .line = 6, .character = 9}, "mod",
{{2, "(6:9~6:12)"}, {1, "(10:5~10:8)"}}));
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down

0 comments on commit 702424b

Please sign in to comment.