Skip to content

Commit

Permalink
Merge pull request #27002 from brandonlangley/moose_server_empty_erro…
Browse files Browse the repository at this point in the history
…r_skip_22766

Update MooseServer to not send empty diagnostic messages
  • Loading branch information
dschwen authored Mar 7, 2024
2 parents 4badf49 + 652a700 commit c7df315
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
8 changes: 4 additions & 4 deletions framework/src/base/MooseServer.C
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ MooseServer::parseDocumentForDiagnostics(wasp::DataArray & diagnosticsList)
// walk over caught message line by line adding each as a diagnostic
for (std::string error_line; std::getline(caught_msg, error_line);)
{
// skip over lines that are blank or consist totally of whitespace
if (error_line.find_first_not_of(" \t") == std::string::npos)
continue;

// check if this error line already has the input file path prefix
if (error_line.rfind(parse_file_path + ":", 0) == 0)
{
Expand Down Expand Up @@ -130,6 +126,10 @@ MooseServer::parseDocumentForDiagnostics(wasp::DataArray & diagnosticsList)
}
}

// skip adding diagnostic when message is empty or only whitespace
if (error_line.find_first_not_of(" \t") == std::string::npos)
continue;

// build zero based line and column diagnostic and add to the list
diagnosticsList.push_back(wasp::DataObject());
wasp::DataObject * diagnostic = diagnosticsList.back().to_object();
Expand Down
45 changes: 45 additions & 0 deletions unit/src/MooseServerTest.C
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,51 @@ textedit_new_text:
std::remove("include_variables.i");
}

TEST_F(MooseServerTest, DiagnosticsEmptyMessageSkip)
{
// didchange test parameters - create empty diagnostic which is not added
std::string doc_uri = wasp::lsp::m_uri_prefix + std::string("/test/input/path");
int doc_version = 6;
std::string doc_text_change = R"INPUT(
[Mesh]
type = GeneratedMesh
dim = 1
[]
[Executioner]
type = Steady
[]
[Problem]
solve = false
[]
globalvar = ${fparse undefined}
)INPUT";

// build didchange notification from parameters and handle it with server
wasp::DataObject didchange_notification, diagnostics_notification;
std::stringstream errors;
EXPECT_TRUE(wasp::lsp::buildDidChangeNotification(
didchange_notification, errors, doc_uri, doc_version, -1, -1, -1, -1, -1, doc_text_change));
EXPECT_TRUE(
moose_server->handleDidChangeNotification(didchange_notification, diagnostics_notification));

// dissect diagnostics notification from server and create formatted list
std::string response_uri;
wasp::DataArray diagnostics_array;
std::ostringstream diagnostics_list_actual;
EXPECT_TRUE(wasp::lsp::dissectPublishDiagnosticsNotification(
diagnostics_notification, errors, response_uri, diagnostics_array));
format_diagnostics(diagnostics_array, diagnostics_list_actual);

// check that diagnostics array size and message contents are as expected
std::size_t diagnostics_size_expect = 1;
std::string diagnostics_list_expect = R"INPUT(
line:11 column:2 - no variable 'undefined' found for use in function parser expression
)INPUT";

EXPECT_EQ(diagnostics_size_expect, diagnostics_array.size());
EXPECT_EQ(diagnostics_list_expect, "\n" + diagnostics_list_actual.str());
}

TEST_F(MooseServerTest, DocumentCloseShutdownAndExit)
{
// check moose_server can share connection it will use to read and write
Expand Down

0 comments on commit c7df315

Please sign in to comment.