Skip to content

Commit

Permalink
fix: Inconsistent completion list with implicitly defined private CSECT
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Dec 8, 2023
1 parent d9f17df commit ae23b97
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## ****Unreleased****

#### Fixed
- Inconsistent completion list with implicitly defined private CSECT

## [1.11.1](https://github.com/eclipse-che4z/che-che4z-lsp-for-hlasm/compare/1.11.0...1.11.1) (2023-12-04)

## [1.11.0](https://github.com/eclipse-che4z/che-che4z-lsp-for-hlasm/compare/1.10.0...1.11.0) (2023-12-01)
Expand Down
6 changes: 5 additions & 1 deletion parser_library/src/lsp/lsp_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,12 @@ completion_list_source lsp_context::completion(const utils::resource::resource_l
{
auto instr = file_info->find_closest_instruction(pos);
const auto is_using = instr && instr->name == context::id_index("USING");
auto [section, usings] = file_info->find_reachable_sections(pos);

auto reachable_sections = gather_reachable_sections(*m_hlasm_ctx, file_info->find_reachable_sections(pos));
if (!section) // use private section if exists
section = m_hlasm_ctx->ord_ctx.get_section(context::id_index());

auto reachable_sections = gather_reachable_sections(*m_hlasm_ctx, { section, usings });

auto reachable_symbols = compute_reachable_symbol_set(reachable_sections, m_hlasm_ctx->ord_ctx, is_using);

Expand Down
27 changes: 27 additions & 0 deletions parser_library/test/lsp/lsp_completion_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,30 @@ C CSECT
EXPECT_THAT(item.documentation, HasSubstr("Absolute Symbol"));
EXPECT_EQ(item.insert_text, "DL");
}

TEST(lsp_completion, private_csect)
{
using namespace ::testing;

const std::string input = R"(
LLLLL DS A
LABEL DS A
)";
analyzer a(input);
a.analyze();
auto loc = a.context().hlasm_ctx->opencode_location();

auto l1 = a.context().lsp_ctx->completion(loc, position(1, 0), 0, completion_trigger_kind::invoked);
auto l2 = a.context().lsp_ctx->completion(loc, position(2, 0), 0, completion_trigger_kind::invoked);

ASSERT_EQ(l1.index(), l2.index());

using T = std::pair<const macro_definition*, std::vector<std::pair<const symbol*, id_index>>>;
ASSERT_TRUE(std::holds_alternative<T>(l1));

const auto& t1 = std::get<T>(l1);
const auto& t2 = std::get<T>(l2);

EXPECT_EQ(t1.first, t2.first);
EXPECT_THAT(t1.second, UnorderedElementsAreArray(t2.second));
}

0 comments on commit ae23b97

Please sign in to comment.