From dc08a9bd4bea9ddc5d59715a31c4837b73cd977f Mon Sep 17 00:00:00 2001 From: slavek-kucera <53339291+slavek-kucera@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:46:09 +0100 Subject: [PATCH] refactor: Move constants --- .../vscode-hlasmplugin/src/branchDecorator.ts | 5 +- .../src/commentEditorCommands.ts | 3 +- clients/vscode-hlasmplugin/src/constants.ts | 14 ++ .../vscode-hlasmplugin/src/debugProvider.ts | 15 +- .../vscode-hlasmplugin/src/eventsHandler.ts | 7 +- clients/vscode-hlasmplugin/src/extension.ts | 24 +-- .../src/hlasmLanguageDetection.ts | 7 +- .../src/hlasmListingServices.ts | 10 +- .../src/hlasmOutputContentProvider.ts | 9 +- .../src/hlasmVirtualFileContentProvider.ts | 3 +- .../src/serverFactory.web.ts | 2 +- .../src/test/suite/index.ts | 183 ++++++++-------- .../src/test/suite/index.web.ts | 197 +++++++++--------- .../src/test/suite/integration.test.ts | 7 +- .../src/test/suite/testHelper.ts | 3 +- 15 files changed, 252 insertions(+), 237 deletions(-) diff --git a/clients/vscode-hlasmplugin/src/branchDecorator.ts b/clients/vscode-hlasmplugin/src/branchDecorator.ts index 31989e17f..9acf2dc02 100644 --- a/clients/vscode-hlasmplugin/src/branchDecorator.ts +++ b/clients/vscode-hlasmplugin/src/branchDecorator.ts @@ -15,6 +15,7 @@ import * as vscode from 'vscode'; import * as vscodelc from 'vscode-languageclient'; import { HlasmPluginMiddleware } from './languageClientMiddleware'; +import { languageIdHlasm } from './constants'; type BranchInfo = { line: number, col: number, up: boolean, down: boolean, somewhere: boolean, @@ -144,9 +145,9 @@ function initializeRequestHandling(client: vscodelc.BaseLanguageClient) { function decorationsEnabled(document: vscode.TextDocument, expectedVersion: number | undefined = undefined) { return !document.isClosed - && document.languageId === 'hlasm' + && document.languageId === languageIdHlasm && (expectedVersion === undefined || document.version === expectedVersion) - && vscode.workspace.getConfiguration('hlasm', document).get('showBranchInformation', true); + && vscode.workspace.getConfiguration(languageIdHlasm, document).get('showBranchInformation', true); } function ignoreFailure() { } diff --git a/clients/vscode-hlasmplugin/src/commentEditorCommands.ts b/clients/vscode-hlasmplugin/src/commentEditorCommands.ts index b376a7a75..aa1479330 100644 --- a/clients/vscode-hlasmplugin/src/commentEditorCommands.ts +++ b/clients/vscode-hlasmplugin/src/commentEditorCommands.ts @@ -13,6 +13,7 @@ */ import * as vscode from 'vscode'; +import { continuationColumn } from './constants'; export enum CommentOption { toggle, @@ -35,7 +36,7 @@ function seq(low: number, high: number): number[] { } function isContinued(text: string): boolean { - return text.length > 71 && ([...text][71] ?? ' ') !== ' '; + return text.length > continuationColumn && ([...text][continuationColumn] ?? ' ') !== ' '; } function findFirstLine(doc: vscode.TextDocument, lineno: number): number { diff --git a/clients/vscode-hlasmplugin/src/constants.ts b/clients/vscode-hlasmplugin/src/constants.ts index 334273c7a..5de6a6305 100644 --- a/clients/vscode-hlasmplugin/src/constants.ts +++ b/clients/vscode-hlasmplugin/src/constants.ts @@ -22,3 +22,17 @@ export const ebg_folder = '.ebg'; export const hlasmplugin_folder_filter: vscode.DocumentFilter = { language: 'json', pattern: '**/.hlasmplugin/*' }; export const bridge_json_filter: vscode.DocumentFilter = { language: 'json', pattern: '**/.bridge.json' }; + +export const EXTENSION_ID = "broadcommfd.hlasm-language-support"; + +export const continuationColumn = 71; +export const initialBlanks = 15; + +export const languageIdHlasm = 'hlasm'; +export const languageIdHlasmListing = 'hlasmListing'; + +export const debugTypeHlasm = 'hlasm'; + +export const schemeExternalFiles = 'hlasm-external'; +export const schemeVirtualFiles = 'hlasm'; +export const schemeOutput = 'hlasm-output'; diff --git a/clients/vscode-hlasmplugin/src/debugProvider.ts b/clients/vscode-hlasmplugin/src/debugProvider.ts index d862a7915..da39f0515 100644 --- a/clients/vscode-hlasmplugin/src/debugProvider.ts +++ b/clients/vscode-hlasmplugin/src/debugProvider.ts @@ -13,6 +13,7 @@ */ import * as vscode from 'vscode'; +import { debugTypeHlasm, languageIdHlasm } from './constants'; // debug configuration provider, adds port number dynamically export class HLASMConfigurationProvider implements vscode.DebugConfigurationProvider { @@ -21,10 +22,10 @@ export class HLASMConfigurationProvider implements vscode.DebugConfigurationProv : vscode.ProviderResult { // no launch.json, debug current if (!config.type && !config.request && !config.name) { - config.type = "hlasm"; - config.request = "launch"; - config.name = "Macro tracer: current program"; - config.program = "${command:extension.hlasm-plugin.getCurrentProgramName}"; + config.type = debugTypeHlasm; + config.request = 'launch'; + config.name = 'Macro tracer: current program'; + config.program = '${command:extension.hlasm-plugin.getCurrentProgramName}'; config.stopOnEntry = true; } return config; @@ -34,8 +35,8 @@ export class HLASMConfigurationProvider implements vscode.DebugConfigurationProv // show an input box to select the program to trace export function getProgramName() { return vscode.window.showInputBox({ - placeHolder: "Please enter the name of a program in the workspace folder", - value: "pgm" + placeHolder: 'Please enter the name of a program in the workspace folder', + value: 'pgm' }); } @@ -46,7 +47,7 @@ export function getCurrentProgramName() { vscode.window.showErrorMessage('No file open.'); return undefined; } - if (editor.document.languageId != 'hlasm') { + if (editor.document.languageId != languageIdHlasm) { vscode.window.showErrorMessage(editor.document.fileName + ' is not a HLASM file.'); return undefined; } diff --git a/clients/vscode-hlasmplugin/src/eventsHandler.ts b/clients/vscode-hlasmplugin/src/eventsHandler.ts index 0b9e43bf0..0cbe2d2f5 100644 --- a/clients/vscode-hlasmplugin/src/eventsHandler.ts +++ b/clients/vscode-hlasmplugin/src/eventsHandler.ts @@ -17,6 +17,7 @@ import * as vscode from 'vscode'; import { ConfigurationsHandler } from './configurationsHandler' import { isLineContinued } from './customEditorCommands'; import { HLASMLanguageDetection } from './hlasmLanguageDetection' +import { languageIdHlasm } from './constants'; /** * Handles various events happening in VSCode @@ -49,11 +50,11 @@ export class EventsHandler { // when contents of a document change, issue a completion request onDidChangeTextDocument(event: vscode.TextDocumentChangeEvent, continuationOffset: number): boolean { if (getConfig('continuationHandling', false)) { - if (event.document.languageId != 'hlasm') + if (event.document.languageId != languageIdHlasm) return false; //const editor = vscode.window.activeTextEditor; - if (event.contentChanges.length == 0 || event.document.languageId != "hlasm") + if (event.contentChanges.length == 0 || event.document.languageId != languageIdHlasm) return false; const change = event.contentChanges[0]; @@ -138,6 +139,6 @@ export class EventsHandler { * @param defaultValue default value to return if option is not set */ export function getConfig(option: string, defaultValue: T) { - const config = vscode.workspace.getConfiguration('hlasm'); + const config = vscode.workspace.getConfiguration(languageIdHlasm); return config.get(option, defaultValue); } diff --git a/clients/vscode-hlasmplugin/src/extension.ts b/clients/vscode-hlasmplugin/src/extension.ts index 7aeda3620..569236f5c 100644 --- a/clients/vscode-hlasmplugin/src/extension.ts +++ b/clients/vscode-hlasmplugin/src/extension.ts @@ -29,7 +29,7 @@ import { HLASMVirtualFileContentProvider } from './hlasmVirtualFileContentProvid import { downloadDependencies } from './hlasmDownloadCommands'; import { blockCommentCommand, CommentOption, lineCommentCommand } from './commentEditorCommands'; import { HLASMCodeActionsProvider } from './hlasmCodeActionsProvider'; -import { hlasmplugin_folder, hlasmplugin_folder_filter, bridge_json_filter } from './constants'; +import { hlasmplugin_folder, hlasmplugin_folder_filter, bridge_json_filter, schemeExternalFiles, continuationColumn, initialBlanks, languageIdHlasm, debugTypeHlasm, schemeVirtualFiles } from './constants'; import { ConfigurationsHandler } from './configurationsHandler'; import { HlasmPluginMiddleware, getLanguageClientMiddleware } from './languageClientMiddleware'; import { HLASMExternalFiles } from './hlasmExternalFiles'; @@ -45,12 +45,6 @@ import { registerListingServices } from './hlasmListingServices'; import { MementoKey } from './mementoKeys'; import { registerOutputDocumentContentProvider, showOutputCommand } from './hlasmOutputContentProvider'; -export const EXTENSION_ID = "broadcommfd.hlasm-language-support"; - -const continuationColumn = 71; -const initialBlanks = 15; -const externalFilesScheme = 'hlasm-external'; - const sleep = (ms: number) => { return new Promise((resolve) => { setTimeout(resolve, ms) }); }; @@ -111,7 +105,7 @@ export async function activate(context: vscode.ExtensionContext): Promise('syncFileEvents', true); const clientOptions: vscodelc.LanguageClientOptions = { - documentSelector: [{ language: 'hlasm' }], + documentSelector: [{ language: languageIdHlasm }], synchronize: !syncFileEvents ? undefined : { fileEvents: [ vscode.workspace.createFileSystemWatcher(filePattern), @@ -124,7 +118,7 @@ export async function activate(context: vscode.ExtensionContext): Promise command == "extension.hlasm-plugin.insertContinuation" || command == "extension.hlasm-plugin.removeContinuation"))) { @@ -292,13 +286,13 @@ async function registerDebugSupport(context: vscode.ExtensionContext, client: vs context.subscriptions.push(vscode.commands.registerCommand('extension.hlasm-plugin.getCurrentProgramName', () => getCurrentProgramName())); // register provider for all hlasm debug configurations - context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('hlasm', new HLASMConfigurationProvider())); - context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory('hlasm', new HLASMDebugAdapterFactory(client))); + context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(debugTypeHlasm, new HLASMConfigurationProvider())); + context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory(debugTypeHlasm, new HLASMDebugAdapterFactory(client))); } async function registerExternalFileSupport(context: vscode.ExtensionContext, client: vscodelc.BaseLanguageClient, extFiles: HLASMExternalFiles) { context.subscriptions.push(client.onDidChangeState(e => e.newState === vscodelc.State.Starting && extFiles.reset())); - context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(externalFilesScheme, extFiles.getTextDocumentContentProvider())); + context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(schemeExternalFiles, extFiles.getTextDocumentContentProvider())); const datasetClient = HLASMExternalFilesFtp(context); if (datasetClient) extFiles.setClient('DATASET', datasetClient); @@ -312,11 +306,11 @@ async function registerExternalFileSupport(context: vscode.ExtensionContext, cli } async function registerToContextWithClient(context: vscode.ExtensionContext, client: vscodelc.BaseLanguageClient, telemetry: Telemetry) { - context.subscriptions.push(vscode.languages.registerCodeActionsProvider(['hlasm', hlasmplugin_folder_filter, bridge_json_filter], new HLASMCodeActionsProvider(client))); + context.subscriptions.push(vscode.languages.registerCodeActionsProvider([languageIdHlasm, hlasmplugin_folder_filter, bridge_json_filter], new HLASMCodeActionsProvider(client))); context.subscriptions.push(vscode.commands.registerCommand('extension.hlasm-plugin.toggleAdvisoryConfigurationDiagnostics', () => toggleAdvisoryConfigurationDiagnostics(client))); - context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider("hlasm", new HLASMVirtualFileContentProvider(client))); + context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider(schemeVirtualFiles, new HLASMVirtualFileContentProvider(client))); context.subscriptions.push(vscode.commands.registerCommand("extension.hlasm-plugin.downloadDependencies", (...args: any[]) => downloadDependencies(context, telemetry, client.outputChannel, ...args))); diff --git a/clients/vscode-hlasmplugin/src/hlasmLanguageDetection.ts b/clients/vscode-hlasmplugin/src/hlasmLanguageDetection.ts index 952bca918..96c69af50 100644 --- a/clients/vscode-hlasmplugin/src/hlasmLanguageDetection.ts +++ b/clients/vscode-hlasmplugin/src/hlasmLanguageDetection.ts @@ -15,6 +15,7 @@ import * as vscode from 'vscode'; import { ConfigurationsHandler } from './configurationsHandler' import { getConfig } from './eventsHandler'; +import { continuationColumn, languageIdHlasm } from './constants'; /** * Runs automatic HLASM language detection on given files @@ -39,11 +40,11 @@ export class HLASMLanguageDetection { // check only plain text files if (document.languageId == 'plaintext' && this.withoutExtension(document.uri)) { if (this.checkHlasmLanguage(document)) { - vscode.languages.setTextDocumentLanguage(document, 'hlasm'); + vscode.languages.setTextDocumentLanguage(document, languageIdHlasm); return true; } } - return document.languageId == 'hlasm'; + return document.languageId == languageIdHlasm; } //Checks for extension for plaintext files @@ -80,7 +81,7 @@ export class HLASMLanguageDetection { if ((this.referenceInstructions.test(line.toUpperCase()) || lastContinued) && line.length <= 80) { score++; // naive continuation check - lastContinued = line.length > 71 && ([...line][71] ?? ' ') !== ' '; + lastContinued = line.length > continuationColumn && ([...line][continuationColumn] ?? ' ') !== ' '; } } }); diff --git a/clients/vscode-hlasmplugin/src/hlasmListingServices.ts b/clients/vscode-hlasmplugin/src/hlasmListingServices.ts index ca3ef926b..b20805fdf 100644 --- a/clients/vscode-hlasmplugin/src/hlasmListingServices.ts +++ b/clients/vscode-hlasmplugin/src/hlasmListingServices.ts @@ -13,9 +13,7 @@ */ import * as vscode from 'vscode'; -import { EXTENSION_ID } from './extension'; - -const languageIdHlasmListing = 'hlasmListing'; +import { EXTENSION_ID, initialBlanks, languageIdHlasmListing } from './constants'; const ordchar = /[A-Za-z0-9$#@_]/; @@ -385,7 +383,7 @@ function isolateSymbol(l: Listing, document: vscode.TextDocument, position: vsco const prevContinued = prevLine >= 0 && /[^ ]/.test(prevText[right]); const thisContinued = /[^ ]/.test(thisText[right]); - const thisOffset = prevContinued ? 15 : 0; + const thisOffset = prevContinued ? initialBlanks : 0; while (start > left + thisOffset && ordchar.test(thisText[start - 1])) --start; @@ -404,10 +402,10 @@ function isolateSymbol(l: Listing, document: vscode.TextDocument, position: vsco prefix = prevText.substring(start, right); } if (thisContinued && end == right) { - end = left + 15; + end = left + initialBlanks; while (end < right && ordchar.test(nextText[end])) ++end; - suffix = nextText.substring(left + 15, end); + suffix = nextText.substring(left + initialBlanks, end); } return (prefix + result + suffix).toUpperCase(); diff --git a/clients/vscode-hlasmplugin/src/hlasmOutputContentProvider.ts b/clients/vscode-hlasmplugin/src/hlasmOutputContentProvider.ts index d82eff886..091f95178 100644 --- a/clients/vscode-hlasmplugin/src/hlasmOutputContentProvider.ts +++ b/clients/vscode-hlasmplugin/src/hlasmOutputContentProvider.ts @@ -17,6 +17,7 @@ import * as vscodelc from 'vscode-languageclient'; import { uriFriendlyBase16Decode, uriFriendlyBase16Encode } from './conversions'; import { isCancellationError } from './helpers'; import { pickUser } from './uiUtils'; +import { languageIdHlasm, schemeOutput } from './constants'; type OutputLine = { level: number; @@ -26,8 +27,6 @@ type OutputResult = OutputLine[]; type Options = { mnote: true, punch: true } | { mnote: false, punch: true } | { mnote: true, punch: false }; -const scheme = 'hlasm-output'; - function translateOptions(options: Options) { let result = ''; if (options.mnote) result += 'M'; @@ -49,11 +48,11 @@ function createOutputUri(uri: vscode.Uri, options: Options) { const query = uriFriendlyBase16Encode(uri.toString()); const path = `/${translateOptions(options)}/${uri.path.substring(uri.path.lastIndexOf('/') + 1)}.output`; - return vscode.Uri.from({ scheme, path, query }); + return vscode.Uri.from({ scheme: schemeOutput, path, query }); } export async function showOutputCommand(editor: vscode.TextEditor, _: vscode.TextEditorEdit, args: any) { - if (editor.document.languageId !== 'hlasm') return; + if (editor.document.languageId !== languageIdHlasm) return; if (!args || args instanceof vscode.Uri) args = await pickUser('Outputs to include:', [ { label: 'MNOTE and PUNCH', value: { mnote: true, punch: true } }, @@ -80,7 +79,7 @@ export function registerOutputDocumentContentProvider( }, disposables: vscode.Disposable[]) { const changed = new vscode.EventEmitter() - const provider = vscode.workspace.registerTextDocumentContentProvider(scheme, { + const provider = vscode.workspace.registerTextDocumentContentProvider(schemeOutput, { onDidChange: changed.event, async provideTextDocumentContent(uri: vscode.Uri, token: vscode.CancellationToken) { const opts = extractOptions(uri); diff --git a/clients/vscode-hlasmplugin/src/hlasmVirtualFileContentProvider.ts b/clients/vscode-hlasmplugin/src/hlasmVirtualFileContentProvider.ts index fe66d13ed..b658dde70 100644 --- a/clients/vscode-hlasmplugin/src/hlasmVirtualFileContentProvider.ts +++ b/clients/vscode-hlasmplugin/src/hlasmVirtualFileContentProvider.ts @@ -14,6 +14,7 @@ import * as vscode from 'vscode'; import * as vscodelc from 'vscode-languageclient'; +import { schemeVirtualFiles } from './constants'; interface FileContent { content: string; @@ -25,7 +26,7 @@ export class HLASMVirtualFileContentProvider implements vscode.TextDocumentConte return new Promise((resolve, reject) => { const trimmed = uri.authority.trim(); const file_id = +trimmed; - if (uri.scheme === 'hlasm' && trimmed.length > 0 && !isNaN(file_id)) + if (uri.scheme === schemeVirtualFiles && trimmed.length > 0 && !isNaN(file_id)) this.client.sendRequest("get_virtual_file_content", { id: file_id }, token) .then(c => resolve(c.content)) .catch(e => reject(e)); diff --git a/clients/vscode-hlasmplugin/src/serverFactory.web.ts b/clients/vscode-hlasmplugin/src/serverFactory.web.ts index 9537d735c..88e45bb65 100644 --- a/clients/vscode-hlasmplugin/src/serverFactory.web.ts +++ b/clients/vscode-hlasmplugin/src/serverFactory.web.ts @@ -14,9 +14,9 @@ import * as vscode from 'vscode'; import * as vscodelc from 'vscode-languageclient/browser'; -import { EXTENSION_ID } from './extension'; import { getConfig } from './eventsHandler'; import { ServerVariant, decorateArgs } from './serverFactory.common'; +import { EXTENSION_ID } from './constants'; function worker_main(extensionUri: string, hlasm_arguments: string[]) { diff --git a/clients/vscode-hlasmplugin/src/test/suite/index.ts b/clients/vscode-hlasmplugin/src/test/suite/index.ts index 3b8a78e07..ed1e5d51f 100644 --- a/clients/vscode-hlasmplugin/src/test/suite/index.ts +++ b/clients/vscode-hlasmplugin/src/test/suite/index.ts @@ -18,115 +18,116 @@ import * as glob from 'glob'; import * as vscode from 'vscode'; import * as process from 'process'; import { popWaitRequestResolver } from './testHelper'; -import { EXTENSION_ID, activate } from '../../extension'; +import { activate } from '../../extension'; +import { EXTENSION_ID, debugTypeHlasm } from '../../constants'; async function registerTestImplementations(): Promise { - const ext = await vscode.extensions.getExtension>(EXTENSION_ID)!.activate(); + const ext = await vscode.extensions.getExtension>(EXTENSION_ID)!.activate(); - ext.registerExternalFileClient('TEST', { - async parseArgs(p: string, _purpose) { - const [path, file] = p.split('/').slice(1).map(decodeURIComponent).map(x => x.toUpperCase()); - return { - details: { - path: path || '', - file: (file || '').split('.')[0], - toDisplayString() { return `${path}/${file}`; }, - normalizedPath() { return `/${path}/${file}`; }, - }, - server: undefined, - } - }, + ext.registerExternalFileClient('TEST', { + async parseArgs(p: string, _purpose) { + const [path, file] = p.split('/').slice(1).map(decodeURIComponent).map(x => x.toUpperCase()); + return { + details: { + path: path || '', + file: (file || '').split('.')[0], + toDisplayString() { return `${path}/${file}`; }, + normalizedPath() { return `/${path}/${file}`; }, + }, + server: undefined, + } + }, - listMembers: (arg) => { - const { path } = arg; - return Promise.resolve(['MACA', 'MACB', 'MACC'].map(x => `/${path}/${x}`)); - }, + listMembers: (arg) => { + const { path } = arg; + return Promise.resolve(['MACA', 'MACB', 'MACC'].map(x => `/${path}/${x}`)); + }, - readMember: (args) => { - if (/^MAC[A-C]$/.test(args.file)) - return Promise.resolve(`.* + readMember: (args) => { + if (/^MAC[A-C]$/.test(args.file)) + return Promise.resolve(`.* MACRO ${args.file} MEND`); - return Promise.resolve(null); - }, - }); + return Promise.resolve(null); + }, + }); - ext.registerExternalConfigurationProvider((uri: vscode.Uri) => { - const uriString = uri.toString(); - if (uriString.includes("AAAAA")) - return { - configuration: { - name: "P1", - asm_options: { - SYSPARM: "AAAAA" - }, - libs: [ - { - path: "libs" - }, - "copy" - ] - } - }; - else if (uriString.includes("BBBBB")) - return { - configuration: 'P1' - }; - else - return null; - }); + ext.registerExternalConfigurationProvider((uri: vscode.Uri) => { + const uriString = uri.toString(); + if (uriString.includes("AAAAA")) + return { + configuration: { + name: "P1", + asm_options: { + SYSPARM: "AAAAA" + }, + libs: [ + { + path: "libs" + }, + "copy" + ] + } + }; + else if (uriString.includes("BBBBB")) + return { + configuration: 'P1' + }; + else + return null; + }); - return [vscode.debug.registerDebugAdapterTrackerFactory('hlasm', { - createDebugAdapterTracker: function (session: vscode.DebugSession): vscode.ProviderResult { - return { - onDidSendMessage: (message: any) => { - if (message.type !== 'response') - return; - const resolver = popWaitRequestResolver(message.command, session.id); - if (resolver) - resolver(); - } - }; - } - })]; + return [vscode.debug.registerDebugAdapterTrackerFactory(debugTypeHlasm, { + createDebugAdapterTracker: function(session: vscode.DebugSession): vscode.ProviderResult { + return { + onDidSendMessage: (message: any) => { + if (message.type !== 'response') + return; + const resolver = popWaitRequestResolver(message.command, session.id); + if (resolver) + resolver(); + } + }; + } + })]; } export async function run(): Promise { - const is_theia = 'THEIA_PARENT_PID' in process.env; + const is_theia = 'THEIA_PARENT_PID' in process.env; - // Create the mocha test - const mocha = new Mocha({ ui: 'tdd', color: true }); - const testsPath = path.join(__dirname, '..'); + // Create the mocha test + const mocha = new Mocha({ ui: 'tdd', color: true }); + const testsPath = path.join(__dirname, '..'); - const files = await new Promise((resolve, reject) => { - glob((!is_theia) ? '**/**.test.js' : '**/integration.test.js', { cwd: testsPath }, (err, files) => { - if (err) - reject(err); - else - resolve(files); - }); - }); + const files = await new Promise((resolve, reject) => { + glob((!is_theia) ? '**/**.test.js' : '**/integration.test.js', { cwd: testsPath }, (err, files) => { + if (err) + reject(err); + else + resolve(files); + }); + }); - // Add files to the test suite - files.forEach(file => mocha.addFile(path.resolve(testsPath, file))); + // Add files to the test suite + files.forEach(file => mocha.addFile(path.resolve(testsPath, file))); - const toDispose = await registerTestImplementations(); + const toDispose = await registerTestImplementations(); - await new Promise((resolve, reject) => { - // Run the mocha test - mocha.run(failures => { - if (failures > 0) { - if (is_theia) - console.error('>>>THEIA TESTS FAILED<<<'); - reject(new Error(`${failures} tests failed.`)); - } else { - resolve(undefined); - } - }); - }).finally(() => { toDispose.forEach(d => d.dispose()) }); + await new Promise((resolve, reject) => { + // Run the mocha test + mocha.run(failures => { + if (failures > 0) { + if (is_theia) + console.error('>>>THEIA TESTS FAILED<<<'); + reject(new Error(`${failures} tests failed.`)); + } else { + resolve(undefined); + } + }); + }).finally(() => { toDispose.forEach(d => d.dispose()) }); - if (is_theia) - console.log('>>>THEIA TESTS PASSED<<<'); + if (is_theia) + console.log('>>>THEIA TESTS PASSED<<<'); } diff --git a/clients/vscode-hlasmplugin/src/test/suite/index.web.ts b/clients/vscode-hlasmplugin/src/test/suite/index.web.ts index d951d40b5..5bde29ad3 100644 --- a/clients/vscode-hlasmplugin/src/test/suite/index.web.ts +++ b/clients/vscode-hlasmplugin/src/test/suite/index.web.ts @@ -15,119 +15,120 @@ import { default as Mocha } from 'mocha/mocha'; import * as vscode from 'vscode'; import { popWaitRequestResolver } from './testHelper'; -import { EXTENSION_ID, activate } from '../../extension'; +import { activate } from '../../extension'; +import { EXTENSION_ID, debugTypeHlasm } from '../../constants'; async function registerTestImplementations(): Promise { - const ext = await vscode.extensions.getExtension>(EXTENSION_ID)!.activate(); + const ext = await vscode.extensions.getExtension>(EXTENSION_ID)!.activate(); - ext.registerExternalFileClient('TEST', { - async parseArgs(p: string, _purpose) { - const [path, file] = p.split('/').slice(1).map(decodeURIComponent).map(x => x.toUpperCase()); - return { - details: { - path: path || '', - file: (file || '').split('.')[0], - toDisplayString() { return `${path}/${file}`; }, - normalizedPath() { return `/${path}/${file}`; }, - }, - server: undefined, - } - }, + ext.registerExternalFileClient('TEST', { + async parseArgs(p: string, _purpose) { + const [path, file] = p.split('/').slice(1).map(decodeURIComponent).map(x => x.toUpperCase()); + return { + details: { + path: path || '', + file: (file || '').split('.')[0], + toDisplayString() { return `${path}/${file}`; }, + normalizedPath() { return `/${path}/${file}`; }, + }, + server: undefined, + } + }, - listMembers: (arg) => { - const { path } = arg; - return Promise.resolve(['MACA', 'MACB', 'MACC'].map(x => `/${path}/${x}`)); - }, + listMembers: (arg) => { + const { path } = arg; + return Promise.resolve(['MACA', 'MACB', 'MACC'].map(x => `/${path}/${x}`)); + }, - readMember: (args) => { - if (/^MAC[A-C]$/.test(args.file)) - return Promise.resolve(`.* + readMember: (args) => { + if (/^MAC[A-C]$/.test(args.file)) + return Promise.resolve(`.* MACRO ${args.file} MEND`); - return Promise.resolve(null); - }, - }); + return Promise.resolve(null); + }, + }); - ext.registerExternalConfigurationProvider((uri: vscode.Uri) => { - const uriString = uri.toString(); - if (uriString.includes("AAAAA")) - return { - configuration: { - name: "P1", - asm_options: { - SYSPARM: "AAAAA" - }, - libs: [ - { - path: "libs" - }, - "copy" - ] - } - }; - else if (uriString.includes("BBBBB")) - return { - configuration: 'P1' - }; - else - return null; - }); + ext.registerExternalConfigurationProvider((uri: vscode.Uri) => { + const uriString = uri.toString(); + if (uriString.includes("AAAAA")) + return { + configuration: { + name: "P1", + asm_options: { + SYSPARM: "AAAAA" + }, + libs: [ + { + path: "libs" + }, + "copy" + ] + } + }; + else if (uriString.includes("BBBBB")) + return { + configuration: 'P1' + }; + else + return null; + }); - return [vscode.debug.registerDebugAdapterTrackerFactory('hlasm', { - createDebugAdapterTracker: function(session: vscode.DebugSession): vscode.ProviderResult { - return { - onDidSendMessage: (message: any) => { - if (message.type !== 'response') - return; - const resolver = popWaitRequestResolver(message.command, session.id); - if (resolver) - resolver(); - } - }; - } - })]; + return [vscode.debug.registerDebugAdapterTrackerFactory(debugTypeHlasm, { + createDebugAdapterTracker: function(session: vscode.DebugSession): vscode.ProviderResult { + return { + onDidSendMessage: (message: any) => { + if (message.type !== 'response') + return; + const resolver = popWaitRequestResolver(message.command, session.id); + if (resolver) + resolver(); + } + }; + } + })]; } export async function run(): Promise { - const mocha = Mocha.setup({ ui: 'tdd', color: false, reporter: null }); + const mocha = Mocha.setup({ ui: 'tdd', color: false, reporter: null }); - await import('./asyncMutex.test.js'); - await import('./codeActions.test.js'); - await import('./commentEditorCommands.test.js'); - await import('./completionList.test.js'); - await import('./configurationsHandler.test.js'); - await import('./connectionPool.test.js'); - await import('./continuationHandler.test.js'); - await import('./conversions.test.js'); - await import('./customEditorCommands.test.js'); - await import('./debugProvider.test.js'); - await import('./debugging.test.js'); - await import('./eventsHandler.test.js'); - //await import('./fbUtils.test.js'); - //await import('./ftpUtils.test.js'); - //await import('./hlasmDownloadCommands.test.js'); - await import('./hlasmExternalConfigurationProvider.test.js'); - await import('./hlasmExternalFiles.test.js'); - await import('./hlasmExternalFilesEndevor.test.js'); - //await import('./hlasmExternalFilesFtp.test.js'); - await import('./hlasmLanguageDetection.test.js'); - await import('./hlasmListingServices.test.js'); - await import('./hlasmOutputContentProvider.test.js'); - await import('./integration.test.js'); - await import('./utils.test.js'); + await import('./asyncMutex.test.js'); + await import('./codeActions.test.js'); + await import('./commentEditorCommands.test.js'); + await import('./completionList.test.js'); + await import('./configurationsHandler.test.js'); + await import('./connectionPool.test.js'); + await import('./continuationHandler.test.js'); + await import('./conversions.test.js'); + await import('./customEditorCommands.test.js'); + await import('./debugProvider.test.js'); + await import('./debugging.test.js'); + await import('./eventsHandler.test.js'); + //await import('./fbUtils.test.js'); + //await import('./ftpUtils.test.js'); + //await import('./hlasmDownloadCommands.test.js'); + await import('./hlasmExternalConfigurationProvider.test.js'); + await import('./hlasmExternalFiles.test.js'); + await import('./hlasmExternalFilesEndevor.test.js'); + //await import('./hlasmExternalFilesFtp.test.js'); + await import('./hlasmLanguageDetection.test.js'); + await import('./hlasmListingServices.test.js'); + await import('./hlasmOutputContentProvider.test.js'); + await import('./integration.test.js'); + await import('./utils.test.js'); - const toDispose = await registerTestImplementations(); + const toDispose = await registerTestImplementations(); - await new Promise((resolve, reject) => { - // Run the mocha test - mocha.run(failures => { - if (failures > 0) { - reject(new Error(`${failures} tests failed.`)); - } else { - resolve(undefined); - } - }); - }).finally(() => { toDispose.forEach(d => d.dispose()) }); + await new Promise((resolve, reject) => { + // Run the mocha test + mocha.run(failures => { + if (failures > 0) { + reject(new Error(`${failures} tests failed.`)); + } else { + resolve(undefined); + } + }); + }).finally(() => { toDispose.forEach(d => d.dispose()) }); } diff --git a/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts b/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts index 5ac00b65e..8328bcfbc 100644 --- a/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts +++ b/clients/vscode-hlasmplugin/src/test/suite/integration.test.ts @@ -15,20 +15,21 @@ import * as assert from 'assert'; import * as vscode from 'vscode'; import * as helper from './testHelper'; -import { EXTENSION_ID, activate } from '../../extension'; +import { activate } from '../../extension'; import { ConfigurationProviderRegistration } from '../../hlasmExternalConfigurationProvider'; +import { EXTENSION_ID } from '../../constants'; suite('Integration Test Suite', () => { const workspace_file = 'open'; let editor: vscode.TextEditor; - suiteSetup(async function () { + suiteSetup(async function() { this.timeout(30000); editor = (await helper.showDocument(workspace_file)).editor; }); - suiteTeardown(async function () { + suiteTeardown(async function() { await helper.closeAllEditors(); }); diff --git a/clients/vscode-hlasmplugin/src/test/suite/testHelper.ts b/clients/vscode-hlasmplugin/src/test/suite/testHelper.ts index f40e043de..2a280d8bf 100644 --- a/clients/vscode-hlasmplugin/src/test/suite/testHelper.ts +++ b/clients/vscode-hlasmplugin/src/test/suite/testHelper.ts @@ -13,6 +13,7 @@ */ import * as assert from 'assert'; import * as vscode from 'vscode'; +import { languageIdHlasm } from '../../constants'; const debuggerWaitRequests = new Map void>(); @@ -75,7 +76,7 @@ export async function closeAllEditors() { } export async function addBreakpoints(file: string, lines: Array) { - const document = (await showDocument(file, 'hlasm')).document; + const document = (await showDocument(file, languageIdHlasm)).document; await vscode.debug.addBreakpoints(lines.map(l => new vscode.SourceBreakpoint(new vscode.Location(document.uri, new vscode.Position(l, 0)), true))); }