From 9bd9f0537a0e5db8730c581d3ad277e08a9d9cca Mon Sep 17 00:00:00 2001 From: Toine Hartman Date: Thu, 17 Apr 2025 13:51:36 +0200 Subject: [PATCH] Improve handling of ignored modules. --- .../main/rascal/lsp/lang/rascal/lsp/refactor/Rename.rsc | 9 ++++++++- .../rascal/lsp/lang/rascal/tests/rename/Performance.rsc | 7 +++++++ .../rascal/lsp/lang/rascal/tests/rename/TestUtils.rsc | 8 ++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/Rename.rsc b/rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/Rename.rsc index df7e2fcc3..b7aadebf0 100644 --- a/rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/Rename.rsc +++ b/rascal-lsp/src/main/rascal/lsp/lang/rascal/lsp/refactor/Rename.rsc @@ -227,7 +227,14 @@ public Edits rascalRenameSymbol(loc cursorLoc, list[Tree] cursor, str newName, s ms = rascalTModelForNames([mname], ccfg, dummy_compile1); = getTModelForModule(mname, ms); - if (!found) throw "No TModel for module \'\'"; + if (!found) { + if (ms.status[mname]?) { + // If a module is annotated with `@ignoreCompiler`, silently skip it + if (MStatus::ignored() in ms.status[mname]) return tmodel(); + throw "No TModel for module \'\'"; + } + throw "No TModel for module \'\'"; + } return tm; } diff --git a/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/Performance.rsc b/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/Performance.rsc index a54d1a8ce..f5f99b41b 100644 --- a/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/Performance.rsc +++ b/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/Performance.rsc @@ -77,3 +77,10 @@ test bool incrementalTypeCheck() { remove(procLoc); return res; } + +test bool ignoredModule() = testRenameOccurrences({ + byText("Ignored", " + 'import Main; + 'int quz() = foo();", {}, annotations = "@ignoreCompiler{For test purposes.}"), + byText("Main", "int foo() = 8;", {0}) +}); diff --git a/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/TestUtils.rsc b/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/TestUtils.rsc index 9f87d6976..96b471adf 100644 --- a/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/TestUtils.rsc +++ b/rascal-lsp/src/main/rascal/lsp/lang/rascal/tests/rename/TestUtils.rsc @@ -57,7 +57,7 @@ import util::Util; //// Fixtures and utility functions -data TestModule = byText(str name, str body, set[int] nameOccs, str newName = name, set[int] skipCursors = {}) +data TestModule = byText(str name, str body, set[int] nameOccs, str newName = name, set[int] skipCursors = {}, str annotations = "") | byLoc(str name, loc file, set[int] nameOccs, str newName = name, set[int] skipCursors = {}); data RenameException @@ -134,7 +134,7 @@ bool testRenameOccurrences(set[TestModule] modules, str oldName = "foo", str new } pcfg = getTestPathConfig(testDir); - modulesByLocation = {mByLoc | m <- modules, mByLoc := (m is byLoc ? m : byLoc(m.name, storeTestModule(testDir, m.name, m.body), m.nameOccs, newName = m.newName, skipCursors = m.skipCursors))}; + modulesByLocation = {mByLoc | m <- modules, mByLoc := (m is byLoc ? m : byLoc(m.name, storeTestModule(testDir, m.name, m.body, annotations = m.annotations), m.nameOccs, newName = m.newName, skipCursors = m.skipCursors))}; for (m <- modulesByLocation) { try { @@ -391,9 +391,9 @@ private tuple[loc, list[Tree]] findCursor(loc f, str id, int occ) { return ; } -private loc storeTestModule(loc dir, str name, str body) { +private loc storeTestModule(loc dir, str name, str body, str annotations = "") { str moduleStr = " - 'module + ' module ' ";