Skip to content

Commit

Permalink
Performance Improvements vol.2 (eclipse-che4z#80)
Browse files Browse the repository at this point in the history
* preparation for hl test
* Revert "preparation for hl test"
This reverts commit 098a08c0fab1c34f65602280de8b517c441e3f2a.
* merge fix
* latest pull req suggestions
* reworked variants to templates
* lazy documentation loading
* ajds to lazy documentation
* changes
* added tests for server features
* fixed test paths
  • Loading branch information
Marcel Hruska authored and slavek-kucera committed Jan 24, 2020
1 parent 82587a0 commit cf2600e
Show file tree
Hide file tree
Showing 40 changed files with 1,016 additions and 497 deletions.
2 changes: 1 addition & 1 deletion benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int argc, char** argv)
// configuration path
ws_folder = argv[1];

auto conf_path = ws_folder + "/pgm_conf.json";
auto conf_path = ws_folder + "/.hlasmplugin/pgm_conf.json";

std::ifstream in(conf_path);
if (in.fail())
Expand Down
28 changes: 17 additions & 11 deletions clients/vscode-hlasmplugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const useTcp = false;
* your extension is activated the very first time the command is executed
*/
var highlight: ASMSemanticHighlightingFeature;
var hlasmpluginClient: vscodelc.LanguageClient;

export function activate(context: vscode.ExtensionContext) {
//debug setup
context.subscriptions.push(vscode.commands.registerCommand('extension.hlasm-plugin.getProgramName', config => {
Expand Down Expand Up @@ -87,7 +89,7 @@ export function activate(context: vscode.ExtensionContext) {
};

//client init
var hlasmpluginClient = new vscodelc.LanguageClient('Hlasmplugin Language Server', serverOptions, clientOptions);
hlasmpluginClient = new vscodelc.LanguageClient('Hlasmplugin Language Server', serverOptions, clientOptions);
//asm contribution
highlight = new ASMSemanticHighlightingFeature(hlasmpluginClient);
hlasmpluginClient.registerFeature(highlight);
Expand All @@ -97,9 +99,11 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(highlight.progress);

//first run, set the language if possible and configs
editorChanged(vscode.window.activeTextEditor);
if (vscode.window.activeTextEditor)
{
highlight.showProgress(vscode.window.activeTextEditor.document);
editorChanged(vscode.window.activeTextEditor.document);
}

// vscode/theia compatibility temporary fix
// theia uses monaco commands
Expand Down Expand Up @@ -373,6 +377,7 @@ vscode.workspace.onDidChangeTextDocument(event => {
// when document opens, show parse progress
vscode.workspace.onDidOpenTextDocument((document: vscode.TextDocument) => {
highlight.showProgress(document);
editorChanged(document);
})

vscode.workspace.onDidChangeConfiguration(event =>
Expand All @@ -398,20 +403,17 @@ const macroInstruction =new RegExp("( |\\t)+MACRO( |\\t)*");

// should the configs be checked
var configs = true;
function editorChanged(editor: vscode.TextEditor)
function editorChanged(document: vscode.TextDocument)
{
if (editor)
{
setHlasmLanguage(editor.document);
if (editor.document.languageId == 'hlasm' && vscode.workspace.workspaceFolders && configs)
checkConfigs(vscode.workspace.workspaceFolders[0].uri.fsPath);
}
if (setHlasmLanguage(document) && vscode.workspace.workspaceFolders && configs)
checkConfigs(vscode.workspace.workspaceFolders[0].uri.fsPath);
}

// when active editor changes, try to set a language for it
vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor) =>
{
editorChanged(editor);
if (editor)
editorChanged(editor.document);
})

function checkHlasmLanguage(text: string)
Expand Down Expand Up @@ -448,11 +450,15 @@ function checkHlasmLanguage(text: string)
}

//automatic detection function
function setHlasmLanguage(document: vscode.TextDocument) {
function setHlasmLanguage(document: vscode.TextDocument) : Boolean {
if (document.languageId == 'plaintext') {
if (checkHlasmLanguage(document.getText()))
{
vscode.languages.setTextDocumentLanguage(document, 'hlasm');
return true;
}
}
return document.languageId == 'hlasm';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion language_server/src/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace language_server {
# define LOG_INFO(x) hlasm_plugin::language_server::logger::get_instance().log(x)
#else
# define LOG_ERROR(x) hlasm_plugin::language_server::logger::get_instance().log(x)
# define LOG_WARNING(x) hlasm_plugin::language_server::logger::get_instance().log(x)
# define LOG_WARNING(x)
# define LOG_INFO(x)
#endif

Expand Down
2 changes: 1 addition & 1 deletion language_server/src/lsp/feature_language_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <iostream>

namespace hlasm_plugin::language_server {
namespace hlasm_plugin::language_server::lsp {

feature_language_features::feature_language_features(parser_library::workspace_manager & ws_mngr, response_provider& response_provider) : feature(ws_mngr, response_provider)
{}
Expand Down
37 changes: 17 additions & 20 deletions language_server/src/lsp/feature_language_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,23 @@
#include "../logger.h"


namespace hlasm_plugin {
namespace language_server {

class feature_language_features : public feature
{
public:
feature_language_features(parser_library::workspace_manager & ws_mngr, response_provider& response_provider);

void virtual register_methods(std::map<std::string, method> & methods) override;
json virtual register_capabilities() override;
void virtual initialize_feature(const json & initialise_params) override;

private:
void definition(const json& id, const json & params);
void references(const json& id, const json& params);
void hover(const json& id, const json& params);
void completion(const json& id, const json& params);
};

}
namespace hlasm_plugin::language_server::lsp {
class feature_language_features : public feature
{
public:
feature_language_features(parser_library::workspace_manager & ws_mngr, response_provider& response_provider);

void virtual register_methods(std::map<std::string, method> & methods) override;
json virtual register_capabilities() override;
void virtual initialize_feature(const json & initialise_params) override;

private:
void definition(const json& id, const json & params);
void references(const json& id, const json& params);
void hover(const json& id, const json& params);
void completion(const json& id, const json& params);
};

}

#endif
105 changes: 105 additions & 0 deletions language_server/test/feature_language_features_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2019 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_TEST_FEATURE_LANGUAGE_FEATURES_TEST_H
#define HLASMPLUGIN_LANGUAGESERVER_TEST_FEATURE_LANGUAGE_FEATURES_TEST_H

#include "../src/lsp/feature_language_features.h"
#include "../../parser_library/src/semantics/lsp_info_processor.h"
#include "ws_mngr_mock.h"
#include "response_provider_mock.h"

#ifdef _WIN32
constexpr const char * path = "c:\\test";
#else
constexpr const char* path = "/home/test";
#endif

TEST(language_features, completion)
{
using namespace ::testing;
ws_mngr_mock ws_mngr;
NiceMock<response_provider_mock> response_mock;
lsp::feature_language_features f(ws_mngr, response_mock);
std::map<std::string, method> notifs;
f.register_methods(notifs);
#ifdef _WIN32
json params1 = R"({"textDocument":{"uri":"file:///c%3A/test"},"position":{"line":0,"character":1},"context":{"triggerKind":1}})"_json;
#else
json params1 = R"({"textDocument":{"uri":"file:///home/test"},"position":{"line":0,"character":1},"context":{"triggerKind":1}})"_json;
#endif
std::vector<context::completion_item_s> item_list
= { context::completion_item_s("LR", "machine", "LR", std::vector<std::string>{"machine doc"}) };
auto list_s = semantics::completion_list_s(false, item_list);
EXPECT_CALL(ws_mngr, completion(StrEq(path), position(0, 1), '\0', 1)).WillOnce(Return(completion_list(list_s)));
notifs["textDocument/completion"]("", params1);
}

TEST(language_features, hover)
{
using namespace ::testing;
ws_mngr_mock ws_mngr;
NiceMock<response_provider_mock> response_mock;
lsp::feature_language_features f(ws_mngr, response_mock);
std::map<std::string, method> notifs;
f.register_methods(notifs);
#ifdef _WIN32
json params1 = R"({"textDocument":{"uri":"file:///c%3A/test"},"position":{"line":0,"character":1}})"_json;
#else
json params1 = R"({"textDocument":{"uri":"file:///home/test"},"position":{"line":0,"character":1}})"_json;
#endif
std::string s("test");
std::vector<const char*> coutput = { s.c_str() };
const string_array ret({coutput.data(),coutput.size()});
EXPECT_CALL(ws_mngr, hover(StrEq(path), position(0, 1))).WillOnce(Return(ret));
notifs["textDocument/hover"]("", params1);
}

TEST(language_features, definition)
{
using namespace ::testing;
ws_mngr_mock ws_mngr;
NiceMock<response_provider_mock> response_mock;
lsp::feature_language_features f(ws_mngr, response_mock);
std::map<std::string, method> notifs;
f.register_methods(notifs);
#ifdef _WIN32
json params1 = R"({"textDocument":{"uri":"file:///c%3A/test"},"position":{"line":0,"character":1}})"_json;
#else
json params1 = R"({"textDocument":{"uri":"file:///home/test"},"position":{"line":0,"character":1}})"_json;
#endif

semantics::position_uri_s pos_s(path, position(0, 1));
EXPECT_CALL(ws_mngr, definition(StrEq(path), position(0, 1))).WillOnce(Return(position_uri(pos_s)));
notifs["textDocument/definition"]("", params1);
}

TEST(language_features, references)
{
using namespace ::testing;
ws_mngr_mock ws_mngr;
NiceMock<response_provider_mock> response_mock;
lsp::feature_language_features f(ws_mngr, response_mock);
std::map<std::string, method> notifs;
f.register_methods(notifs);
#ifdef _WIN32
json params1 = R"({"textDocument":{"uri":"file:///c%3A/test"},"position":{"line":0,"character":1}})"_json;
#else
json params1 = R"({"textDocument":{"uri":"file:///home/test"},"position":{"line":0,"character":1}})"_json;
#endif
std::vector<semantics::position_uri_s> ret = {semantics::position_uri_s(path,position(0, 1))};
EXPECT_CALL(ws_mngr, references(StrEq(path), position(0, 1))).WillOnce(Return(position_uris(ret.data(),ret.size())));
notifs["textDocument/references"]("", params1);
}
#endif
6 changes: 4 additions & 2 deletions language_server/test/feature_text_synchronization_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
* Broadcom, Inc. - initial API and implementation
*/

#ifndef HLASMPLUGIN_LANGUAGESERVER_TEST_FEATURE_TEXT_SYNCHRONIZATION_TEST_H
#define HLASMPLUGIN_LANGUAGESERVER_TEST_FEATURE_TEXT_SYNCHRONIZATION_TEST_H

#include "../src/lsp/feature_text_synchronization.h"

#include "ws_mngr_mock.h"
#include "response_provider_mock.h"
#ifdef _WIN32

TEST(text_synchronization, did_open_file)
Expand Down Expand Up @@ -124,3 +125,4 @@ TEST(feature, path_to_uri)

#endif // _WIN32

#endif // !HLASMPLUGIN_LANGUAGESERVER_TEST_FEATURE_TEXT_SYNCHRONIZATION_TEST_H
1 change: 1 addition & 0 deletions language_server/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "gmock/gmock.h"

#include "feature_language_features_test.h"
#include "workspace_folders_test.h"
#include "feature_text_synchronization_test.h"
#include "server_test.h"
Expand Down
2 changes: 1 addition & 1 deletion language_server/test/workspace_folders_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


#include "../src/lsp/feature_workspace_folders.h"

#include <string>
#include "ws_mngr_mock.h"
using namespace hlasm_plugin::language_server;
#ifdef _WIN32
Expand Down
6 changes: 5 additions & 1 deletion language_server/test/ws_mngr_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ using namespace hlasm_plugin::parser_library;
class ws_mngr_mock : public workspace_manager
{
public:

MOCK_METHOD2(get_workspaces, size_t(ws_id * workspaces, size_t max_size));
MOCK_METHOD0(get_workspaces_count, size_t());
MOCK_METHOD2(add_workspace, void(const char * name, const char * uri));
Expand All @@ -33,6 +32,11 @@ class ws_mngr_mock : public workspace_manager
MOCK_METHOD4(did_open_file, void(const char * document_uri, version_t version, const char * text, size_t text_length));
MOCK_METHOD4(did_change_file, void(const char * document_uri, version_t version, const document_change * changes, size_t ch_size));
MOCK_METHOD1(did_close_file, void(const char * document_uri));

MOCK_METHOD(position_uri, definition, (const char* document_uri, const position pos), (override));
MOCK_METHOD(position_uris, references,(const char* document_uri, const position pos), (override));
MOCK_METHOD(const string_array, hover, (const char* document_uri, const position pos), (override));
MOCK_METHOD(completion_list, completion, (const char* document_uri, const position pos, const char trigger_char, int trigger_kind), (override));
};

#endif // !HLASMPLUGIN_LANGUAGESERVER_TEST_WS_MNGR_MOCK_H
2 changes: 1 addition & 1 deletion parser_library/include/shared/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct PARSER_LIBRARY_EXPORT string_array
using version_t = uint64_t;

namespace context {
struct completion_item_s;
class completion_item_s;
}

namespace semantics {
Expand Down
7 changes: 3 additions & 4 deletions parser_library/include/shared/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ struct PARSER_LIBRARY_EXPORT range

struct PARSER_LIBRARY_EXPORT file_range
{
file_range() {}
file_range(range r, std::string file) : r(r), file(std::move(file)) {}
file_range(range r) : r(r), file("") {}
file_range(range r, const std::string* file) : r(r), file(file) {}
file_range(range r) : r(r), file(nullptr) {}
bool operator==(const file_range& fr) const
{
return r == fr.r && file == fr.file;
}
range r;
std::string file;
const std::string* file;
};

struct PARSER_LIBRARY_EXPORT location
Expand Down
8 changes: 4 additions & 4 deletions parser_library/include/shared/workspace_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ class PARSER_LIBRARY_EXPORT workspace_manager
virtual void did_close_file(const char * document_uri);
virtual void did_change_watched_files(const char** paths, size_t size);

position_uri definition(const char * document_uri, const position pos);
position_uris references(const char * document_uri, const position pos);
const string_array hover(const char * document_uri, const position pos);
completion_list completion(const char* document_uri, const position pos, const char trigger_char, int trigger_kind);
virtual position_uri definition(const char * document_uri, const position pos);
virtual position_uris references(const char * document_uri, const position pos);
virtual const string_array hover(const char * document_uri, const position pos);
virtual completion_list completion(const char* document_uri, const position pos, const char trigger_char, int trigger_kind);

virtual void register_highlighting_consumer(highlighting_consumer * consumer);
virtual void register_diagnostics_consumer(diagnostics_consumer * consumer);
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ analyzer::analyzer(
:diagnosable_ctx(*hlasm_ctx),
hlasm_ctx_(own_ctx ? context::ctx_ptr(hlasm_ctx) : nullptr), hlasm_ctx_ref_(*hlasm_ctx),
listener_(file_name),
lsp_proc_(file_name, text, hlasm_ctx_ref_.lsp_ctx),
lsp_proc_(file_name, text, hlasm_ctx),
input_(text), lexer_(&input_, &lsp_proc_, &hlasm_ctx_ref_.metrics), tokens_(&lexer_), parser_(new generated::hlasmparser(&tokens_)),
mngr_(std::unique_ptr<processing::opencode_provider>(parser_), hlasm_ctx_ref_, data, file_name, lib_provider, *parser_, tracer)
{
Expand Down
Loading

0 comments on commit cf2600e

Please sign in to comment.