Skip to content

Commit

Permalink
#6031: Allow removal of unsaved declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Aug 7, 2022
1 parent 35f911c commit 6288cb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion radiantcore/decl/DeclarationManager.cpp
Expand Up @@ -328,7 +328,10 @@ void DeclarationManager::removeDeclarationFromFile(const IDeclaration::Ptr& decl
{
const auto& syntax = decl->getBlockSyntax();

if (!syntax.fileInfo.name.empty() && !syntax.fileInfo.getIsPhysicalFile())
// Nothing to do if the decl hasn't been saved
if (syntax.fileInfo.name.empty()) return;

if (!syntax.fileInfo.getIsPhysicalFile())
{
throw std::logic_error("Only declarations stored in physical files can be removed.");
}
Expand Down
11 changes: 7 additions & 4 deletions test/DeclManager.cpp
Expand Up @@ -712,14 +712,17 @@ TEST_F(DeclManagerTest, RemoveDeclaration)
GlobalDeclarationManager().registerDeclType("testdecl", std::make_shared<TestDeclarationCreator>());
GlobalDeclarationManager().registerDeclFolder(decl::Type::TestDecl, TEST_DECL_FOLDER, ".decl");

expectDeclIsPresent(decl::Type::TestDecl, "decl/precedence_test/1");
expectDeclIsPresent(decl::Type::TestDecl, "decl/removal/1");

// Keep a local reference to the decl around to see what happens with its contents after removal
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/precedence_test/1");
auto decl = GlobalDeclarationManager().findDeclaration(decl::Type::TestDecl, "decl/removal/1");

// Create a backup copy of the decl file we're going to manipulate
BackupCopy backup(_context.getTestProjectPath() + decl->getDeclFilePath());

GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/precedence_test/1");
GlobalDeclarationManager().removeDeclaration(decl::Type::TestDecl, "decl/removal/1");

expectDeclIsNotPresent(decl::Type::TestDecl, "decl/precedence_test/1");
expectDeclIsNotPresent(decl::Type::TestDecl, "decl/removal/1");

// The held reference should be cleared
EXPECT_TRUE(decl->getBlockSyntax().name.empty());
Expand Down

0 comments on commit 6288cb6

Please sign in to comment.