Skip to content

Commit

Permalink
fix: Sequence symbol location is incorrect when discovered in the loo…
Browse files Browse the repository at this point in the history
…kahead mode
  • Loading branch information
slavek-kucera authored Dec 7, 2022
1 parent 1c8fb3e commit 20dda28
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Enhance language server response times
- Missing references and hover text in model statements
- Do not display messages related to Bridge for Git configuration unless it is actively utilized
- Sequence symbol location is incorrect when discovered in the lookahead mode

#### Changed
- Macro label is the preferred go to definition target unless the request is made from the label itself
Expand Down
4 changes: 2 additions & 2 deletions parser_library/src/context/hlasm_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,14 @@ processing_stack_t hlasm_context::processing_stack()
return result;
}

processing_frame hlasm_context::processing_stack_top()
processing_frame hlasm_context::processing_stack_top(bool consider_macros)
{
// this is an inverted version of the loop from processing_stack()
// terminating after finding the first (originally last) element

assert(!source_stack_.empty());

if (source_stack_.size() == 1 && scope_stack_.size() > 1)
if (consider_macros && source_stack_.size() == 1 && scope_stack_.size() > 1)
{
const auto& last_macro = scope_stack_.back().this_macro;

Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/context/hlasm_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class hlasm_context

// gets stack of locations of all currently processed files
processing_stack_t processing_stack();
processing_frame processing_stack_top();
processing_frame processing_stack_top(bool consider_macros = true);
processing_stack_details_t processing_stack_details();
location current_statement_location() const;
// gets macro nest
Expand Down
4 changes: 2 additions & 2 deletions parser_library/src/processing/processing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,10 @@ void processing_manager::register_sequence_symbol(context::id_index target, rang
std::unique_ptr<context::opencode_sequence_symbol> processing_manager::create_opencode_sequence_symbol(
context::id_index name, range symbol_range)
{
auto loc = hlasm_ctx_.processing_stack_top().get_location();
auto loc = hlasm_ctx_.processing_stack_top(false).get_location();
loc.pos = symbol_range.start;

auto&& [statement_position, snapshot] = hlasm_ctx_.get_begin_snapshot(attr_lookahead_active());
auto&& [statement_position, snapshot] = hlasm_ctx_.get_begin_snapshot(lookahead_active());

return std::make_unique<context::opencode_sequence_symbol>(
name, std::move(loc), statement_position, std::move(snapshot));
Expand Down
55 changes: 55 additions & 0 deletions parser_library/test/processing/lookahead_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,3 +1238,58 @@ TEST DS CL(X)

EXPECT_TRUE(matches_message_codes(a.diags(), { "W013", "W013" }));
}

TEST(lookahead, seq_symbol_location)
{
mock_parse_lib_provider libs {
std::pair<std::string, std::string>("COPY1", R"(
AGO .INHERE1
.INHERE1 ANOP
)"),
std::pair<std::string, std::string>("COPY2", R"(
AIF (L'X EQ 1).INHERE2
.INHERE2 ANOP
)"),
std::pair<std::string, std::string>("MAC", R"( MACRO
MAC
AIF (L'Y EQ 1).INMACRO
.INMACRO ANOP
MEND
)"),
};

std::string input = R"(
COPY COPY1
COPY COPY2
AIF (1 EQ 0).OUTHERE1
.OUTHERE1 ANOP ,
X DS C
MAC
AIF (1 EQ 0).OUTHERE2
.OUTHERE2 ANOP ,
Y DS C
)";

const hlasm_plugin::utils::resource::resource_location copy1("COPY1"), copy2("COPY2"), mac("MAC"), opencode("OPEN");

analyzer a(input, analyzer_options(opencode, &libs));
a.analyze();
a.collect_diags();

EXPECT_TRUE(a.diags().empty());

auto inhere1 = a.context().lsp_ctx->definition(copy1, { 1, 16 });
auto inhere2 = a.context().lsp_ctx->definition(copy2, { 1, 30 });
auto inmacro = a.context().lsp_ctx->definition(mac, { 2, 30 });
auto outhere1 = a.context().lsp_ctx->definition(opencode, { 4, 30 });
auto outhere2 = a.context().lsp_ctx->definition(opencode, { 8, 30 });

EXPECT_EQ(inhere1, location(position(2, 0), copy1));
EXPECT_EQ(inhere2, location(position(3, 0), copy2));
EXPECT_EQ(inmacro, location(position(4, 0), mac));
EXPECT_EQ(outhere1, location(position(5, 0), opencode));
EXPECT_EQ(outhere2, location(position(9, 0), opencode));
}

0 comments on commit 20dda28

Please sign in to comment.