Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow viewing content generated by AINSERT instruction and preprocessors #248

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## ****Unreleased****

#### Added
- Allow viewing content generated by AINSERT instruction and preprocessors

#### Fixed
- Fixed an issue preventing correct N' attribute evaluation of empty subscript arrays
Expand All @@ -13,14 +14,14 @@
#### Added
- USING and DROP support
- SYSSTMT support
- Instruction operand checking utilizes USING map
- Instruction operand checking now utilizes the USING map

#### Fixed
- Behavior of currently supported subscripted system variables corrected
- Cross-section relative immediate references should be only warned upon
- Incorrect module layout computed when ORG instruction is used in sections with multiple location counters
- AINSERT can now do immediate variable evaluatation correctly
- Highlighting of single character strings (which could represent data attributes - e.g. `I'`, `L'`, `S'` and others) is fixed
- Improved the behavior of supported subscripted system variables
- Cross-section relative immediate references now only generate warnings
- Incorrect module layout is computed when the ORG instruction is used in sections with multiple location counters
- Immediate variable evaluation now works correctly in statements that use the AINSERT instruction
- Fixed the highlighting of single-character strings that resemble data attributes
- Document navigation does not work correctly in Untitled documents

## [1.0.0](https://github.com/eclipse/che-che4z-lsp-for-hlasm/compare/0.15.1...1.0.0) (2022-01-31)
Expand Down
3 changes: 3 additions & 0 deletions clients/vscode-hlasmplugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ServerFactory, ServerVariant } from './serverFactory';
import { HLASMDebugAdapterFactory } from './hlasmDebugAdapterFactory';
import { Telemetry } from './telemetry';
import { LanguageClientErrorHandler } from './languageClientErrorHandler';
import { HLASMVirtualFileContentProvider } from './hlasmVirtualFileContentProvider';

const offset = 71;
const continueColumn = 15;
Expand Down Expand Up @@ -186,5 +187,7 @@ async function registerToContext(context: vscode.ExtensionContext, client: vscod
context.subscriptions.push(vscode.commands.registerCommand('extension.hlasm-plugin.getProgramName', () => getProgramName()));
context.subscriptions.push(vscode.commands.registerCommand('extension.hlasm-plugin.getCurrentProgramName', () => getCurrentProgramName()));

context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider("hlasm", new HLASMVirtualFileContentProvider(client)));

return handler;
}
44 changes: 44 additions & 0 deletions clients/vscode-hlasmplugin/src/hlasmVirtualFileContentProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2022 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*/

import * as vscode from 'vscode';
import * as vscodelc from 'vscode-languageclient/node';
import assert = require('assert');

class FileContent {
content: string;
}

export class HLASMVirtualFileContentProvider implements vscode.TextDocumentContentProvider {
onDidChange?: vscode.Event<vscode.Uri> = undefined;
provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken): vscode.ProviderResult<string> {
return new Promise((resolve, reject) => {
this.client.onReady().then(() => {
assert(uri.scheme === 'hlasm');
const trimmed = uri.authority.trim();
const file_id = +trimmed;
if (trimmed.length > 0 && !isNaN(file_id))
this.client.sendRequest<FileContent>("get_virtual_file_content", { id: file_id }, token)
.then(c => resolve(c.content))
.catch(e => reject(e));

else
reject("Invalid virtual HLASM file.");
});
});
}

constructor(private client: vscodelc.BaseLanguageClient) {
}
}
2 changes: 2 additions & 0 deletions language_server/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ target_sources(language_server_base PRIVATE
telemetry_broker.h
telemetry_info.h
telemetry_sink.h
virtual_file_provider.cpp
virtual_file_provider.h
)

if(EMSCRIPTEN)
Expand Down
6 changes: 5 additions & 1 deletion language_server/src/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "feature.h"

#include <filesystem>
#include <regex>

#include "network/uri/uri.hpp"

Expand Down Expand Up @@ -71,9 +72,12 @@ std::string feature::uri_to_path(const std::string& uri)
return utils::path::lexically_normal(network::detail::decode(auth_path)).string();
}

// one letter schemas are valid, but Windows paths collide
const std::regex uri_like("^[A-Za-z][A-Za-z0-9+\\-.]+:");

std::string feature::path_to_uri(std::string_view path)
{
if (path.substr(0, untitled.size()) == untitled)
if (std::regex_search(path.begin(), path.end(), uri_like))
return std::string(path);

// network::detail::encode_path(uri) ignores @, which is incompatible with VS Code
Expand Down
4 changes: 2 additions & 2 deletions language_server/src/lsp/feature_language_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void feature_language_features::hover(const json& id, const json& params)
parser_library::position(params["position"]["line"].get<int>(), params["position"]["character"].get<int>());


auto hover_list = ws_mngr_.hover(uri_to_path(document_uri).c_str(), pos);
auto hover_list = std::string_view(ws_mngr_.hover(uri_to_path(document_uri).c_str(), pos));

response_->respond(id, "", json { { "contents", hover_list.empty() ? json() : get_markup_content(hover_list) } });
}
Expand Down Expand Up @@ -331,7 +331,7 @@ void feature_language_features::semantic_tokens(const json& id, const json& para
{
auto document_uri = params["textDocument"]["uri"].get<std::string>();

auto tokens = ws_mngr_.semantic_tokens(uri_to_path(document_uri).c_str());
auto tokens = std::vector<parser_library::token_info>(ws_mngr_.semantic_tokens(uri_to_path(document_uri).c_str()));
json num_array = convert_tokens_to_num_array(tokens);

response_->respond(id, "", { { "data", num_array } });
Expand Down
4 changes: 4 additions & 0 deletions language_server/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "scope_exit.h"
#include "server_streams.h"
#include "telemetry_broker.h"
#include "virtual_file_provider.h"
#include "workspace_manager.h"

using namespace hlasm_plugin::language_server;
Expand All @@ -44,14 +45,17 @@ class main_program : public json_sink
std::thread lsp_thread;
telemetry_broker dap_telemetry_broker;
dap::session_manager dap_sessions;
virtual_file_provider virtual_files;

public:
main_program(json_sink& json_output, int& ret)
: ws_mngr(&cancel)
, router(&lsp_queue)
, dap_sessions(ws_mngr, json_output, &dap_telemetry_broker)
, virtual_files(ws_mngr, json_output)
{
router.register_route(dap_sessions.get_filtering_predicate(), dap_sessions);
router.register_route(virtual_files.get_filtering_predicate(), virtual_files);

lsp_thread = std::thread([&ret, this, io = json_channel_adapter(lsp_queue, json_output)]() {
try
Expand Down
72 changes: 72 additions & 0 deletions language_server/src/virtual_file_provider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2022 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*/

#include "virtual_file_provider.h"

#include "logger.h"
#include "nlohmann/json.hpp"
#include "workspace_manager.h"

namespace {
std::string_view extract_method(const nlohmann::json& msg)
{
auto method_it = msg.find("method");
if (method_it == msg.end() || !method_it->is_string())
return {};
return method_it->get<std::string_view>();
}
} // namespace

namespace hlasm_plugin::language_server {

void virtual_file_provider::write(const nlohmann::json& m)
{
try
{
auto s_ = ws_mngr->get_virtual_file_content(m.at("params").at("id").get<unsigned long long>());
if (std::string_view s(s_.data(), s_.size()); !s.empty())
out_stream->write(nlohmann::json {
{ "id", m.at("id") },
{
"result",
nlohmann::json {
{ "content", s },
},
},
});
else
out_stream->write(nlohmann::json {
{ "id", m.at("id") },
{
"error",
nlohmann::json {
{ "code", 1 },
{ "message", "File not found" },
},
},
});
}
catch (const nlohmann::json::exception& e)
{
LOG_ERROR(std::string("Virtual file provider exception: ") + e.what());
}
}
void virtual_file_provider::write(nlohmann::json&& m) { write(m); }

message_router::message_predicate virtual_file_provider::get_filtering_predicate() const
{
return [](const nlohmann::json& msg) { return extract_method(msg) == "get_virtual_file_content"; };
}

} // namespace hlasm_plugin::language_server
49 changes: 49 additions & 0 deletions language_server/src/virtual_file_provider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2022 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*/


#ifndef HLASMPLUGIN_LANGUAGESERVER_VIRTUAL_FILE_PROVIDER_H
#define HLASMPLUGIN_LANGUAGESERVER_VIRTUAL_FILE_PROVIDER_H

#include "json_channel.h"

#include "message_router.h"

namespace hlasm_plugin::parser_library {
class workspace_manager;
}

namespace hlasm_plugin::language_server {

class virtual_file_provider final : public json_sink
{
hlasm_plugin::parser_library::workspace_manager* ws_mngr;
json_sink* out_stream;

public:
// Inherited via json_sink
void write(const nlohmann::json& m) override;
void write(nlohmann::json&& m) override;

virtual_file_provider(hlasm_plugin::parser_library::workspace_manager& ws_mngr, json_sink& out)
: ws_mngr(&ws_mngr)
, out_stream(&out)
{}

[[nodiscard]] message_router::message_predicate get_filtering_predicate() const;
};

} // namespace hlasm_plugin::language_server

#endif
1 change: 1 addition & 0 deletions language_server/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ target_sources(server_test PRIVATE
stream_helper_test.cpp
ws_mngr_mock.h
telemetry_test.cpp
virtual_file_provider_test.cpp
)

add_subdirectory(dap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ TEST(language_features, hover)
: R"({"textDocument":{"uri":"file:///home/test"},"position":{"line":0,"character":1}})"_json;

std::string s("test");
std::string_view ret(s);
parser_library::sequence<char> ret(s);
EXPECT_CALL(ws_mngr, hover(StrEq(path), parser_library::position(0, 1))).WillOnce(Return(ret));
notifs["textDocument/hover"].handler("", params1);
}
Expand Down
Loading