diff --git a/parser_library/src/lsp/completion_list_source.h b/parser_library/src/lsp/completion_list_source.h index 9868fd1cb..2c3fbe4b8 100644 --- a/parser_library/src/lsp/completion_list_source.h +++ b/parser_library/src/lsp/completion_list_source.h @@ -41,7 +41,7 @@ struct completion_list_instructions { std::string_view completed_text; size_t completed_text_start_column; - const std::unordered_map, std::shared_ptr>* macros; + const std::unordered_map>* macros; const lsp_context* lsp_ctx; std::vector additional_instructions; diff --git a/parser_library/src/lsp/lsp_context.cpp b/parser_library/src/lsp/lsp_context.cpp index 6fed849c4..dddb6f3ca 100644 --- a/parser_library/src/lsp/lsp_context.cpp +++ b/parser_library/src/lsp/lsp_context.cpp @@ -534,7 +534,8 @@ void lsp_context::add_macro(macro_info_ptr macro_i, text_data_view text_data) if (macro_i->external) add_file(file_info(macro_i->macro_definition, std::move(text_data))); - m_macros[macro_i->macro_definition] = macro_i; + auto [_, inserted] = m_macros.try_emplace(macro_i->macro_definition.get(), std::move(macro_i)); + assert(inserted); } void lsp_context::add_opencode( @@ -569,7 +570,7 @@ macro_info_ptr lsp_context::get_macro_info(context::id_index macro_name, context if (auto it = m_hlasm_ctx->find_macro(macro_name, gen); !it) return nullptr; else - return m_macros.at(*it); + return m_macros.at(it->get()); } const file_info* lsp_context::get_file_info(const utils::resource::resource_location& file_loc) const @@ -772,7 +773,7 @@ completion_list_source lsp_context::completion(const utils::resource::resource_l auto reachable_symbols = compute_reachable_symbol_set(reachable_sections, m_hlasm_ctx->ord_ctx, is_using); - return std::pair(instr ? instr->opcode.get() : nullptr, std::move(reachable_symbols)); + return std::pair(instr ? instr->opcode : nullptr, std::move(reachable_symbols)); } } @@ -1057,7 +1058,7 @@ std::string lsp_context::find_hover(const symbol_occurrence& occ, { if (std::holds_alternative(op->opcode_detail)) return prefix_using( - hover_for_macro(*m_macros.at(std::get(op->opcode_detail)))); + hover_for_macro(*m_macros.at(std::get(op->opcode_detail).get()))); else return prefix_using(hover_for_instruction(op->opcode)); } diff --git a/parser_library/src/lsp/lsp_context.h b/parser_library/src/lsp/lsp_context.h index 72700af79..ce5953b53 100644 --- a/parser_library/src/lsp/lsp_context.h +++ b/parser_library/src/lsp/lsp_context.h @@ -44,7 +44,7 @@ class lsp_context final opencode_info_ptr m_opencode; std::unordered_map m_files; - std::unordered_map m_macros; + std::unordered_map m_macros; std::shared_ptr m_hlasm_ctx; @@ -91,7 +91,7 @@ class lsp_context final const context::hlasm_context& get_related_hlasm_context() const { return *m_hlasm_ctx; } - const std::unordered_map& macros() const { return m_macros; }; + const std::unordered_map& macros() const { return m_macros; }; std::vector get_opencode_branch_info() const; diff --git a/parser_library/src/lsp/symbol_occurrence.h b/parser_library/src/lsp/symbol_occurrence.h index 2ec2e491e..634de4cab 100644 --- a/parser_library/src/lsp/symbol_occurrence.h +++ b/parser_library/src/lsp/symbol_occurrence.h @@ -41,7 +41,7 @@ struct symbol_occurrence range occurrence_range; // in case of INSTR kind, holds potential macro opcode - context::macro_def_ptr opcode = nullptr; + const context::macro_definition* opcode = nullptr; symbol_occurrence(occurrence_kind kind, context::id_index name, const range& occurrence_range, bool evaluated_model) : kind(kind) @@ -50,11 +50,11 @@ struct symbol_occurrence , occurrence_range(occurrence_range) {} - symbol_occurrence(context::id_index name, context::macro_def_ptr opcode, const range& occurrence_range) + symbol_occurrence(context::id_index name, const context::macro_definition* opcode, const range& occurrence_range) : kind(occurrence_kind::INSTR) , name(name) , occurrence_range(occurrence_range) - , opcode(std::move(opcode)) + , opcode(opcode) {} // returns true, if this occurrence kind depends on a scope diff --git a/parser_library/src/processing/statement_analyzers/lsp_analyzer.cpp b/parser_library/src/processing/statement_analyzers/lsp_analyzer.cpp index a66e34bd8..d5114100b 100644 --- a/parser_library/src/processing/statement_analyzers/lsp_analyzer.cpp +++ b/parser_library/src/processing/statement_analyzers/lsp_analyzer.cpp @@ -198,9 +198,9 @@ void lsp_analyzer::macrodef_finished(context::macro_def_ptr macrodef, macrodef_p { if (!result.invalid) { + const auto* md = macrodef.get(); // add instruction occurrence of macro name - const auto& macro_file = macrodef->definition_location.resource_loc; - macro_occurrences_[macro_file].first.emplace_back(macrodef->id, macrodef, result.prototype.macro_name_range); + const auto& macro_file = md->definition_location.resource_loc; auto m_i = std::make_shared(result.external, location(result.prototype.macro_name_range.start, macro_file), @@ -208,6 +208,7 @@ void lsp_analyzer::macrodef_finished(context::macro_def_ptr macrodef, macrodef_p std::move(result.variable_symbols), std::move(result.file_scopes), std::move(macro_occurrences_)); + m_i->file_occurrences_[macro_file].first.emplace_back(md->id, md, result.prototype.macro_name_range); if (result.external) lsp_ctx_.add_macro(std::move(m_i), lsp::text_data_view(file_text_)); @@ -319,7 +320,7 @@ void lsp_analyzer::collect_occurrence(const semantics::instruction_si& instructi auto* macro_def = std::get_if(&opcode.opcode_detail); if (!opcode.opcode.empty() || macro_def) collector.occurrences.emplace_back( - opcode.opcode, macro_def ? std::move(*macro_def) : context::macro_def_ptr {}, instruction.field_range); + opcode.opcode, macro_def ? macro_def->get() : nullptr, instruction.field_range); } else if (instruction.type == semantics::instruction_si_type::ORD && collector.collector_kind == lsp::occurrence_kind::INSTR_LIKE) diff --git a/parser_library/test/lsp/lsp_completion_test.cpp b/parser_library/test/lsp/lsp_completion_test.cpp index 9e7a9b78a..1868c2823 100644 --- a/parser_library/test/lsp/lsp_completion_test.cpp +++ b/parser_library/test/lsp/lsp_completion_test.cpp @@ -35,8 +35,8 @@ TEST(lsp_completion, completion_list_instr) auto aaaa = a.context().lsp_ctx->get_macro_info(context::id_index("AAAA")); ASSERT_TRUE(aaaa); - std::unordered_map m; - m.try_emplace(aaaa->macro_definition, aaaa); + std::unordered_map m; + m.try_emplace(aaaa->macro_definition.get(), aaaa); auto result = lsp::generate_completion(lsp::completion_list_source( lsp::completion_list_instructions { "AAAAA", 1, &m, a.context().lsp_ctx.get(), { "AAAA", "ADATA" } })); @@ -59,8 +59,8 @@ TEST(lsp_completion, completion_list_instr_exact) auto aaaa = a.context().lsp_ctx->get_macro_info(context::id_index("AAAA")); ASSERT_TRUE(aaaa); - std::unordered_map m; - m.try_emplace(aaaa->macro_definition, aaaa); + std::unordered_map m; + m.try_emplace(aaaa->macro_definition.get(), aaaa); auto result = lsp::generate_completion(lsp::completion_list_source( lsp::completion_list_instructions { "AAA", 1, &m, a.context().lsp_ctx.get(), { "AAAA", "ADATA" } }));