Skip to content

Commit

Permalink
refactor: Remove proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Apr 25, 2024
1 parent dfdcf40 commit 81c1bb1
Show file tree
Hide file tree
Showing 166 changed files with 4,303 additions and 5,044 deletions.
13 changes: 6 additions & 7 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,12 @@ void log_w(Args... args)

struct parsing_metadata_collector final : public parser_library::parsing_metadata_consumer
{
void consume_parsing_metadata(
parser_library::sequence<char>, double, const parser_library::parsing_metadata& metadata) override
void consume_parsing_metadata(std::string_view, double, const parser_library::parsing_metadata& metadata) override
{
data.emplace_back(metadata);
}

void outputs_changed(parser_library::sequence<char>) override {}
void outputs_changed(std::string_view) override {}

std::vector<parser_library::parsing_metadata> data;
};
Expand Down Expand Up @@ -402,7 +401,7 @@ class bench
annotation = get_file_message(current_iteration, bc);
ws->register_diagnostics_consumer(&diag_counter);
ws->register_parsing_metadata_consumer(&collector);
ws->add_workspace(bc.ws_folder.c_str(), utils::path::path_to_uri(bc.ws_folder).c_str());
ws->add_workspace(bc.ws_folder, utils::path::path_to_uri(bc.ws_folder));
ws->idle_handler();
}

Expand Down Expand Up @@ -592,7 +591,7 @@ class bench
annotation.append(parse_params.annotation).append(reparse ? "Reparsing " : "Parsing ");
auto& ws = parse_params.ws;
const auto source_uri = utils::path::path_to_uri(parse_params.source_path);
static const parser_library::document_change dummy_change({}, "", 0);
static const parser_library::document_change dummy_change({}, {});

// Log a message before starting the clock
log_if(annotation, "file: ", parse_params.source_file);
Expand All @@ -604,8 +603,8 @@ class bench
// open file/parse
try
{
reparse ? ws->did_change_file(source_uri.c_str(), 1, &dummy_change, 1)
: ws->did_open_file(source_uri.c_str(), 1, content.c_str(), content.length());
reparse ? ws->did_change_file(source_uri, 1, std::span(&dummy_change, 1))
: ws->did_open_file(source_uri, 1, content);

ws->idle_handler();
}
Expand Down
13 changes: 6 additions & 7 deletions benchmark/diagnostic_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#include "diagnostic.h"
#include "nlohmann/json.hpp"
#include "protocol.h"
#include "workspace_manager.h"
Expand All @@ -30,17 +30,16 @@ namespace hlasm_plugin::benchmark {
class diagnostic_counter : public hlasm_plugin::parser_library::diagnostics_consumer
{
public:
void consume_diagnostics(hlasm_plugin::parser_library::diagnostic_list diagnostics,
hlasm_plugin::parser_library::fade_message_list) override
void consume_diagnostics(std::span<const hlasm_plugin::parser_library::diagnostic> diagnostics,
std::span<const hlasm_plugin::parser_library::fade_message>) override
{
for (size_t i = 0; i < diagnostics.diagnostics_size(); i++)
for (const auto& d : diagnostics)
{
if (auto diag_sev = diagnostics.diagnostics(i).severity();
diag_sev == hlasm_plugin::parser_library::diagnostic_severity::error)
if (auto diag_sev = d.severity; diag_sev == hlasm_plugin::parser_library::diagnostic_severity::error)
error_count++;
else if (diag_sev == hlasm_plugin::parser_library::diagnostic_severity::warning)
warning_count++;
message_counts[diagnostics.diagnostics(i).code()]++;
message_counts[d.code]++;
}
}

Expand Down
85 changes: 43 additions & 42 deletions language_server/src/dap/dap_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,17 @@ void dap_feature::register_methods(std::map<std::string, method>& methods)
}
nlohmann::json dap_feature::register_capabilities() { return nlohmann::json(); }

void dap_feature::stopped(
hlasm_plugin::parser_library::sequence<char> reason, hlasm_plugin::parser_library::sequence<char> details)
void dap_feature::stopped(std::string_view reason, std::string_view details)
{
nlohmann::json args {
{ "reason", std::string_view(reason) },
{ "reason", reason },
{ "threadId", THREAD_ID },
{ "allThreadsStopped", true },
};
if (details.size() > 0)
{
args["description"] = std::string_view(details);
args["text"] = std::string_view(details);
args["description"] = details;
args["text"] = details;
}

response_->notify("stopped", args);
Expand All @@ -127,21 +126,21 @@ void dap_feature::exited(int exit_code)
response_->notify("terminated", nlohmann::json());
}

void dap_feature::mnote(unsigned char level, hlasm_plugin::parser_library::sequence<char> text)
void dap_feature::mnote(unsigned char level, std::string_view text)
{
response_->notify("output",
nlohmann::json {
{ "category", "stderr" },
{ "output", (std::to_string(level) + ":").append(std::string_view(text)).append("\n") },
{ "output", (std::to_string(level) + ":").append(text).append("\n") },
});
}

void dap_feature::punch(hlasm_plugin::parser_library::sequence<char> text)
void dap_feature::punch(std::string_view text)
{
response_->notify("output",
nlohmann::json {
{ "category", "stdout" },
{ "output", std::string(std::string_view(text)).append("\n") },
{ "output", std::string(text).append("\n") },
});
}

Expand Down Expand Up @@ -219,7 +218,7 @@ void dap_feature::on_set_breakpoints(const request_id& request_seq, const nlohma
nlohmann::json breakpoints_verified = nlohmann::json::array();

auto source = server_conformant_path(args.at("source").at("path").get<std::string_view>(), client_path_format_);
std::vector<parser_library::breakpoint> breakpoints;
std::vector<parser_library::debugging::breakpoint> breakpoints;

if (auto bpoints_found = args.find("breakpoints"); bpoints_found != args.end())
{
Expand All @@ -229,7 +228,7 @@ void dap_feature::on_set_breakpoints(const request_id& request_seq, const nlohma
breakpoints_verified.push_back(nlohmann::json { { "verified", true } });
}
}
debugger->breakpoints(source, hlasm_plugin::parser_library::sequence(breakpoints));
debugger->breakpoints(source, breakpoints);

response_->respond(request_seq, "setBreakpoints", nlohmann::json { { "breakpoints", breakpoints_verified } });
}
Expand All @@ -245,13 +244,13 @@ void dap_feature::on_set_function_breakpoints(const request_id& request_seq, con
return;

nlohmann::json breakpoints_verified = nlohmann::json::array();
std::vector<parser_library::function_breakpoint> breakpoints;
std::vector<parser_library::debugging::function_breakpoint> breakpoints;

if (auto bpoints_found = args.find("breakpoints"); bpoints_found != args.end())
{
for (auto& bp_json : bpoints_found.value())
{
breakpoints.emplace_back(parser_library::sequence<char>(bp_json.at("name").get<std::string_view>()));
breakpoints.emplace_back(bp_json.at("name").get<std::string_view>());
breakpoints_verified.push_back(nlohmann::json { { "verified", true } });
}
}
Expand Down Expand Up @@ -282,9 +281,9 @@ void dap_feature::on_threads(const request_id& request_seq, const nlohmann::json
} });
}

[[nodiscard]] nlohmann::json source_to_json(parser_library::source source, path_format path_format)
[[nodiscard]] nlohmann::json source_to_json(const parser_library::debugging::source& source, path_format path_format)
{
return nlohmann::json { { "path", client_conformant_path(std::string_view(source.uri), path_format) } };
return nlohmann::json { { "path", client_conformant_path(source.uri, path_format) } };
}

void dap_feature::on_stack_trace(const request_id& request_seq, const nlohmann::json&)
Expand All @@ -298,12 +297,12 @@ void dap_feature::on_stack_trace(const request_id& request_seq, const nlohmann::
{
frames_json.push_back(nlohmann::json {
{ "id", frame.id },
{ "name", std::string_view(frame.name) },
{ "source", source_to_json(frame.source_file, client_path_format_) },
{ "line", frame.source_range.start.line + line_1_based_ },
{ "column", frame.source_range.start.column + column_1_based_ },
{ "endLine", frame.source_range.end.line + line_1_based_ },
{ "endColumn", frame.source_range.end.column + column_1_based_ },
{ "name", frame.name },
{ "source", source_to_json(frame.frame_source, client_path_format_) },
{ "line", frame.begin_line + line_1_based_ },
{ "column", column_1_based_ },
{ "endLine", frame.end_line + line_1_based_ },
{ "endColumn", column_1_based_ },
});
}

Expand All @@ -323,14 +322,13 @@ void dap_feature::on_scopes(const request_id& request_seq, const nlohmann::json&

nlohmann::json scopes_json = nlohmann::json::array();

for (const auto& s : debugger->scopes(args.at("frameId").get<nlohmann::json::number_unsigned_t>()))
for (const auto& scope : debugger->scopes(args.at("frameId").get<nlohmann::json::number_unsigned_t>()))
{
auto scope = parser_library::scope(s);
auto scope_json = nlohmann::json {
{ "name", std::string_view(scope.name) },
{ "variablesReference", scope.variable_reference },
{ "name", scope.name },
{ "variablesReference", scope.var_reference },
{ "expensive", false },
{ "source", source_to_json(scope.source_file, client_path_format_) },
{ "source", source_to_json(scope.scope_source, client_path_format_) },
};
scopes_json.push_back(std::move(scope_json));
}
Expand Down Expand Up @@ -374,18 +372,21 @@ void dap_feature::on_variables(const request_id& request_seq, const nlohmann::js

nlohmann::json variables_json = nlohmann::json::array();

for (auto var : debugger->variables(parser_library::var_reference_t(args.at("variablesReference"))))
for (const auto& var :
debugger->variables(parser_library::debugging::var_reference_t(args.at("variablesReference"))))
{
using enum parser_library::debugging::set_type;

std::string type;
switch (var.type)
{
case parser_library::set_type::A_TYPE:
case A_TYPE:
type = "A_TYPE";
break;
case parser_library::set_type::B_TYPE:
case B_TYPE:
type = "B_TYPE";
break;
case parser_library::set_type::C_TYPE:
case C_TYPE:
type = "C_TYPE";
break;
default:
Expand All @@ -395,14 +396,14 @@ void dap_feature::on_variables(const request_id& request_seq, const nlohmann::js
nlohmann::json var_json;
if (type == "")
var_json = nlohmann::json {
{ "name", std::string_view(var.name) },
{ "value", std::string_view(var.value) },
{ "variablesReference", var.variable_reference },
{ "name", var.name },
{ "value", var.value },
{ "variablesReference", var.var_reference },
};
else
var_json = nlohmann::json { { "name", std::string_view(var.name) },
{ "value", std::string_view(var.value) },
{ "variablesReference", var.variable_reference },
var_json = nlohmann::json { { "name", var.name },
{ "value", var.value },
{ "variablesReference", var.var_reference },
{ "type", type } };

variables_json.push_back(std::move(var_json));
Expand Down Expand Up @@ -436,18 +437,18 @@ void dap_feature::on_evaluate(const request_id& request_seq, const nlohmann::jso
if (!debugger)
return;
const std::string_view expression = args.at("expression").get<std::string_view>();
const auto frame_id = args.value("frameId", parser_library::frame_id_t(-1));
const auto frame_id = args.value("frameId", parser_library::debugging::frame_id_t(-1));

auto result = debugger->evaluate(parser_library::sequence<char>(expression), frame_id);
auto result = debugger->evaluate(expression, frame_id);

if (result.is_error())
response_->respond_error(request_seq, "evaluate", -1, std::string_view(result.result()), nlohmann::json());
if (result.error)
response_->respond_error(request_seq, "evaluate", -1, result.result, nlohmann::json());
else
response_->respond(request_seq,
"evaluate",
nlohmann::json {
{ "result", std::string_view(result.result()) },
{ "variablesReference", result.var_ref() },
{ "result", result.result },
{ "variablesReference", result.var_ref },
});
}

Expand Down
7 changes: 3 additions & 4 deletions language_server/src/dap/dap_feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ class dap_feature : public feature, public hlasm_plugin::parser_library::debuggi
nlohmann::json register_capabilities() override;

// Inherited via debug_event_consumer
void stopped(hlasm_plugin::parser_library::sequence<char> reason,
hlasm_plugin::parser_library::sequence<char> addtl_info) override;
void stopped(std::string_view reason, std::string_view addtl_info) override;
void exited(int exit_code) override;
void mnote(unsigned char level, hlasm_plugin::parser_library::sequence<char> text) override;
void punch(hlasm_plugin::parser_library::sequence<char> text) override;
void mnote(unsigned char level, std::string_view text) override;
void punch(std::string_view text) override;

parser_library::debugger_configuration_provider& dc_provider;
std::optional<hlasm_plugin::parser_library::debugging::debugger> debugger;
Expand Down
2 changes: 1 addition & 1 deletion language_server/src/dap/dap_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void session::thread_routine()
LOG_ERROR("DAP Thread encountered an unknown exception.");
}
}
void session::provide_debugger_configuration(parser_library::sequence<char> document_uri,
void session::provide_debugger_configuration(std::string_view document_uri,
parser_library::workspace_manager_response<parser_library::debugging::debugger_configuration> conf)
{
struct proxy
Expand Down
2 changes: 1 addition & 1 deletion language_server/src/dap/dap_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class session final : public json_sink, parser_library::debugger_configuration_p

void thread_routine();

void provide_debugger_configuration(parser_library::sequence<char> document_uri,
void provide_debugger_configuration(std::string_view document_uri,
parser_library::workspace_manager_response<parser_library::debugging::debugger_configuration> conf) override;

public:
Expand Down
15 changes: 7 additions & 8 deletions language_server/src/external_file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ bool external_file_reader::enqueue_message(
return true;
}

void external_file_reader::read_external_file(const char* url, workspace_manager_response<sequence<char>> content)
void external_file_reader::read_external_file(
std::string_view url, workspace_manager_response<std::string_view> content)
{
auto next_id = m_next_id.fetch_add(1, std::memory_order_relaxed);
nlohmann::json msg = {
Expand All @@ -78,15 +79,15 @@ void external_file_reader::read_external_file(const char* url, workspace_manager
else if (!result.is_string())
content.error(utils::error::invalid_json);
else
content.provide(sequence<char>(result.get<std::string_view>()));
content.provide(result.get<std::string_view>());
};

if (!enqueue_message(next_id, std::move(msg), std::move(handler)))
content.error(utils::error::message_send);
}

void external_file_reader::read_external_directory(
const char* url, workspace_manager_response<workspace_manager_external_directory_result> members, bool subdir)
std::string_view url, workspace_manager_response<workspace_manager_external_directory_result> members, bool subdir)
{
auto next_id = m_next_id.fetch_add(1, std::memory_order_relaxed);
nlohmann::json msg = {
Expand All @@ -110,7 +111,7 @@ void external_file_reader::read_external_directory(
members.error(utils::error::invalid_json);
return;
}
std::vector<sequence<char>> tmp;
std::vector<std::string_view> tmp;
try
{
tmp.reserve(result.size());
Expand All @@ -127,12 +128,10 @@ void external_file_reader::read_external_directory(
members.error(utils::error::invalid_json);
return;
}
tmp.emplace_back(sequence<char>(item.get<std::string_view>()));
tmp.emplace_back(item.get<std::string_view>());
}

members.provide({
.member_urls = sequence<sequence<char>>(tmp),
});
members.provide({ .member_urls = tmp });
};

if (!enqueue_message(next_id, std::move(msg), std::move(handler)))
Expand Down
5 changes: 2 additions & 3 deletions language_server/src/external_file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include "message_router.h"
#include "nlohmann/json_fwd.hpp"
#include "sequence.h"
#include "workspace_manager_external_file_requests.h"

namespace hlasm_plugin::language_server {
Expand Down Expand Up @@ -54,8 +53,8 @@ class external_file_reader final : public parser_library::workspace_manager_exte

// Inherited via workspace_manager_external_file_requests
void read_external_file(
const char* url, parser_library::workspace_manager_response<parser_library::sequence<char>> content) override;
void read_external_directory(const char* url,
std::string_view url, parser_library::workspace_manager_response<std::string_view> content) override;
void read_external_directory(std::string_view url,
parser_library::workspace_manager_response<parser_library::workspace_manager_external_directory_result> members,
bool subdir = false) override;

Expand Down
Loading

0 comments on commit 81c1bb1

Please sign in to comment.