Skip to content

Commit

Permalink
Code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Dec 23, 2022
1 parent b6ad558 commit d52b8fe
Show file tree
Hide file tree
Showing 35 changed files with 131 additions and 121 deletions.
12 changes: 6 additions & 6 deletions clients/vscode-hlasmplugin/src/configurationsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ export class ConfigurationsHandler {

// converts wildcards to regexes
private convertWildcardToRegex(wildcard: string): RegExp {
var regexStr = wildcard.replace(/\(|\[|\{|\\|\^|\-|\=|\$|\!|\||\]|\}|\)|\./g, (char) => { return "\\" + char });
regexStr = regexStr.replace(/%3[fF]/g, ".");
regexStr = regexStr.replace(/%2[aA]/g, (char) => { return ".*?"; });
regexStr = regexStr.replace(/%2[bB]/g, (char) => { return ".+?"; });
regexStr = '^' + regexStr + '$';
return new RegExp(regexStr);
return new RegExp('^' +
wildcard.replace(/\(|\[|\{|\\|\^|\-|\=|\$|\!|\||\]|\}|\)|\./g, (char) => { return "\\" + char })
.replace(/%3[fF]/g, ".")
.replace(/%2[aA]/g, (char) => { return ".*?"; })
.replace(/%2[bB]/g, (char) => { return ".+?"; })
+ '$');
}


Expand Down
8 changes: 4 additions & 4 deletions clients/vscode-hlasmplugin/src/customEditorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class CustomEditorCommands {
-1;

// position of cursor after delete
var newCursorPosition = new vscode.Position(
let newCursorPosition = new vscode.Position(
editor.selection.active.line,
editor.selection.active.character - ((selectionSize >= -1) ? selectionSize : 0));

Expand Down Expand Up @@ -132,7 +132,7 @@ export class CustomEditorCommands {
: 1;

// position of cursor after delete
var newCursorPosition =
let newCursorPosition =
new vscode.Position(
editor.selection.active.line,
editor.selection.active.character - ((selectionSize > 0 && editor.selection.active.character > 0) ? selectionSize : 0));
Expand Down Expand Up @@ -172,8 +172,8 @@ export class CustomEditorCommands {

// find space for line, used for custom type
private findSpace(textLine: vscode.TextLine, length: number, editor: vscode.TextEditor, continuationOffset: number) {
var spacePosition = continuationOffset - 1;
var currentSymbol = textLine.text[spacePosition];
let spacePosition = continuationOffset - 1;
let currentSymbol = textLine.text[spacePosition];
// go backwards through all the symbols since the continuation and check whether there are enough spaces to compensate for the input
while (currentSymbol == " " && spacePosition > editor.selection.active.character && length > 0) {
spacePosition--;
Expand Down
4 changes: 2 additions & 2 deletions clients/vscode-hlasmplugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ export async function activate(context: vscode.ExtensionContext) {


// create server options
var factory = new ServerFactory();
const factory = new ServerFactory();

const serverOptions = await factory.create(serverVariant);

//client init
var hlasmpluginClient = new vscodelc.LanguageClient('Hlasmplugin Language Server', serverOptions, clientOptions);
const hlasmpluginClient = new vscodelc.LanguageClient('Hlasmplugin Language Server', serverOptions, clientOptions);

clientErrorHandler.defaultHandler = hlasmpluginClient.createDefaultErrorHandler();
// The objectToString is necessary, because telemetry reporter only takes objects with
Expand Down
6 changes: 3 additions & 3 deletions clients/vscode-hlasmplugin/src/hlasmLanguageDetection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export class HLASMLanguageDetection {
if (!getConfig<boolean>('useAutodetection', false))
return false;

var score = 0;
var lines = 0;
var lastContinued = false;
let score = 0;
let lines = 0;
let lastContinued = false;
//iterate line by line
const split = text.split('\n');
//check whether the first line is MACRO and immediately set to hlasm
Expand Down
2 changes: 1 addition & 1 deletion clients/vscode-hlasmplugin/src/serverFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class ServerFactory {
}
// returns random free port
private getRandomPort = () => new Promise<number>((resolve, reject) => {
var srv = net.createServer();
const srv = net.createServer();
srv.unref();
srv.listen(0, "127.0.0.1", () => {
const address = srv.address();
Expand Down
16 changes: 8 additions & 8 deletions clients/vscode-hlasmplugin/src/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ export class TextEditorEditMock implements vscode.TextEditorEdit {
}
_insert(location: vscode.Position, value: string): void {
let pos = this.skipLines(this._text, location.line);
var before = this._text.slice(0, pos + location.character);
var after = this._text.slice(pos + location.character);
const before = this._text.slice(0, pos + location.character);
const after = this._text.slice(pos + location.character);
this._text = before + value + after;
}
_delete(location: vscode.Range | vscode.Selection): void {
let pos_start = this.skipLines(this._text, location.start.line);
let pos_end = this.skipLines(this._text, location.end.line);
var before = this._text.slice(0, pos_start + location.start.character);
var after = this._text.slice(pos_end + location.end.character);
const pos_start = this.skipLines(this._text, location.start.line);
const pos_end = this.skipLines(this._text, location.end.line);
const before = this._text.slice(0, pos_start + location.start.character);
const after = this._text.slice(pos_end + location.end.character);
this._text = before + after;
}
setEndOfLine(endOfLine: vscode.EndOfLine): void {
Expand Down Expand Up @@ -216,8 +216,8 @@ export class TextDocumentMock implements vscode.TextDocument {
lineAt(line: number): vscode.TextLine;
lineAt(position: vscode.Position): vscode.TextLine;
lineAt(position: any) {
var line = new TextLineMock();
var lines = this.text.split(/\r?\n/);
const line = new TextLineMock();
const lines = this.text.split(/\r?\n/);
if ((position as vscode.Position).line !== undefined)
line.lineNumber = (position as vscode.Position).line;
else
Expand Down
25 changes: 8 additions & 17 deletions clients/vscode-hlasmplugin/src/test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,15 @@ async function main() {
const extensionDevelopmentPath = path.join(__dirname, '../../');
const extensionTestsPath = path.join(__dirname, './suite/index');
const launchArgs = [path.join(__dirname, './workspace/'), '--disable-extensions', '--disable-workspace-trust'];
var options: TestOptions;
if (process.argv.length > 2 && process.argv[2] == 'insiders') {
const vscodeExecutablePath = await downloadAndUnzipVSCode('insiders');
options = {
vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath,
launchArgs
}
} else {
options = {
extensionDevelopmentPath,
extensionTestsPath,
launchArgs
}
}
const vscodeExecutablePath = process.argv.length > 2 && process.argv[2] == 'insiders' && await downloadAndUnzipVSCode('insiders') || undefined;

// run tests
await runTests(options);
await runTests({
vscodeExecutablePath,
extensionDevelopmentPath,
extensionTestsPath,
launchArgs
});
} catch (error) {
console.log(error);
console.error('Tests Failed');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ suite('Continuation Handler Test Suite', () => {
document.uri = vscode.Uri.file('file');
// prepare editor and edit
const editor = new TextEditorMock(document);
var cursorPosition = new vscode.Position(1, 0);
let cursorPosition = new vscode.Position(1, 0);
editor.selection = new vscode.Selection(cursorPosition, cursorPosition);
const edit = new TextEditorEditMock('continuation X\r\n ');
document.text = edit.text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ suite('Debug Provider Test Suite', () => {

// resolve empty configuration
const emptyDebugConf = new DebugConfigurationMock();
var result = <vscode.DebugConfiguration>(debugProvider.resolveDebugConfiguration(vscode.workspace.workspaceFolders[0], emptyDebugConf));
let result = <vscode.DebugConfiguration>(debugProvider.resolveDebugConfiguration(vscode.workspace.workspaceFolders[0], emptyDebugConf));
assert.equal(result.type, 'hlasm');
assert.equal(result.name, 'Macro tracer: current program');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ suite('Language Detection Test Suite', () => {
});
// if file has no extension return false
test('non HLASM file extension test false_one', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = nonHlasmContents;
Expand All @@ -50,7 +50,7 @@ suite('Language Detection Test Suite', () => {
assert.ok(!detector.EndsWithExtension(document));
});
test('non HLASM file extension test false_two', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = nonHlasmContents;
Expand All @@ -59,7 +59,7 @@ suite('Language Detection Test Suite', () => {
assert.ok(!detector.EndsWithExtension(document));
});
test('non HLASM file extension test false_three', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = nonHlasmContents;
Expand All @@ -68,7 +68,7 @@ suite('Language Detection Test Suite', () => {
assert.ok(!detector.EndsWithExtension(document));
});
test('Cobol file containing several dots but not extension returns false', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = nonHlasmContents;
Expand All @@ -77,7 +77,7 @@ suite('Language Detection Test Suite', () => {
assert.ok(!detector.EndsWithExtension(document));
});
test('Cobol file ending with extension', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = nonHlasmContents;
Expand All @@ -87,48 +87,48 @@ suite('Language Detection Test Suite', () => {
});
// if file has extension return true
test('non HLASM file extension test true', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = nonHlasmContents;
document.fileName = "file.cbl";
document.uri = vscode.Uri.file('file.cbl');
assert.ok(detector.EndsWithExtension(document));

});
//Dont set to Hlasm if file extension exist other than .hlasm or file assosciations irrespective of content
test('non HLASM test based on file extension and language id', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = hlasmContents;
document.fileName = "file.cbl";
document.uri = vscode.Uri.file('file.cbl');
assert.ok(!detector.setHlasmLanguage(document));

});
test('HLASM test based on file extension and language id', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'hlasm';
document.text = hlasmContents;
document.fileName = "file.hlasm";
document.uri = vscode.Uri.file('file.hlasm');
assert.ok(detector.setHlasmLanguage(document));

});

// set non HLASM file as HLASM
test('non HLASM files test', async () => {
var document = new TextDocumentMock();
const document = new TextDocumentMock();
// set plain text file to HLASM
document.languageId = 'plaintext';
document.text = nonHlasmContents;
document.uri = vscode.Uri.file('file');
document.fileName = "file";
assert.ok(!detector.setHlasmLanguage(document));
});

});

const hlasmContents = `
Expand Down
16 changes: 13 additions & 3 deletions clients/vscode-hlasmplugin/src/test/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ import * as process from 'process';
import { timeout } from './testHelper';
import { EXTENSION_ID } from '../../extension';

async function primeExtension() {
const ext = await vscode.extensions.getExtension(EXTENSION_ID).activate();
const lang: {
onReady(): Promise<void>;
sendRequest<R>(method: string, param: any, token?: vscode.CancellationToken): Promise<R>;
} = ext!.getExtension()!;
// wait for the language server initialization
await Promise.race([lang.onReady(), timeout(30000, 'Language server initialization failed')]);
// prime opcode suggestions to avoid timeouts
await Promise.race([lang.sendRequest<object>('textDocument/$/opcode_suggestion', { opcodes: ['OPCODE'] }), timeout(30000, 'Opcode suggestion request failed')]);
}

export async function run(): Promise<void> {
const is_vscode = process.execPath.includes('Code');

Expand All @@ -39,9 +51,7 @@ export async function run(): Promise<void> {
// Add files to the test suite
files.forEach(file => mocha.addFile(path.resolve(testsPath, file)));

const ext = await vscode.extensions.getExtension(EXTENSION_ID).activate();
const lang: { onReady(): Promise<void>; } = ext!.getExtension();
await Promise.race([lang!.onReady(), timeout(30000, 'Language server initialization failed')]);
await primeExtension();

await new Promise((resolve, reject) => {
// Run the mocha test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import * as glob from 'glob';
import { ServerFactory } from '../../serverFactory'

suite('ServerFactory Test Suite', () => {
var factory = new ServerFactory();
const factory = new ServerFactory();

test('non TCP server options test', async () => {
// create standard server options
const options = await factory.create('native');
Expand Down
4 changes: 3 additions & 1 deletion language_server/src/lsp/feature_text_synchronization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "feature_text_synchronization.h"

#include <memory>

#include "../logger.h"
#include "protocol.h"
#include "utils/resource_location.h"
Expand Down Expand Up @@ -92,7 +94,7 @@ void feature_text_synchronization::on_did_change(const json&, const json& params

++i;
}
ws_mngr_.did_change_file(doc_uri.c_str(), version, &*changes.begin(), changes.size());
ws_mngr_.did_change_file(doc_uri.c_str(), version, changes.data(), changes.size());
}

void feature_text_synchronization::on_did_close(const json&, const json& params)
Expand Down
2 changes: 1 addition & 1 deletion parser_library/include/range.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct PARSER_LIBRARY_EXPORT position

struct PARSER_LIBRARY_EXPORT range
{
range() {}
range() = default;
range(position start, position end)
: start(start)
, end(end)
Expand Down
6 changes: 3 additions & 3 deletions parser_library/src/checking/instr_operand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
using namespace hlasm_plugin::parser_library;
using namespace hlasm_plugin::parser_library::checking;

complex_operand::complex_operand() {}
complex_operand::complex_operand() = default;

complex_operand::complex_operand(
std::string operand_identifier, std::vector<std::unique_ptr<asm_operand>> operand_params)
: operand_identifier(operand_identifier)
, operand_parameters(std::move(operand_params)) {};

machine_operand::machine_operand() {}
machine_operand::machine_operand() = default;

bool machine_operand::is_operand_corresponding(int operand, parameter param)
{
Expand Down Expand Up @@ -328,7 +328,7 @@ bool one_operand::check(
return true;
}

empty_operand::empty_operand() {}
empty_operand::empty_operand() = default;
empty_operand::empty_operand(range r)
: operand(r)
{}
Expand Down
Loading

0 comments on commit d52b8fe

Please sign in to comment.