From d57895efa236fbd3c7b6f1f96146377e61a1ed18 Mon Sep 17 00:00:00 2001 From: jirimosinger <99467904+jirimosinger@users.noreply.github.com> Date: Fri, 14 Apr 2023 10:37:11 +0200 Subject: [PATCH] fix: Prevent pgm_conf not found prompt --- clients/vscode-hlasmplugin/CHANGELOG.md | 1 + .../src/configurationsHandler.ts | 17 +++---- clients/vscode-hlasmplugin/src/constants.ts | 1 + .../vscode-hlasmplugin/src/eventsHandler.ts | 2 +- clients/vscode-hlasmplugin/src/helpers.ts | 16 ++++--- .../src/hlasmCodeActionsProvider.ts | 6 +-- clients/vscode-hlasmplugin/src/test/mocks.ts | 47 +++++++++++++++++++ .../test/suite/configurationsHandler.test.ts | 33 ++++++++++++- 8 files changed, 99 insertions(+), 24 deletions(-) diff --git a/clients/vscode-hlasmplugin/CHANGELOG.md b/clients/vscode-hlasmplugin/CHANGELOG.md index a5760ed58..76fb2573b 100644 --- a/clients/vscode-hlasmplugin/CHANGELOG.md +++ b/clients/vscode-hlasmplugin/CHANGELOG.md @@ -15,6 +15,7 @@ - Source code colorization may be flickering while typing - Configuration request sent before initialization is done - VSCode enters an infinite loop of opening and closing files +- "pgm_conf.json not found" prompt shows up even when `.bridge.json` exists ## [1.7.0](https://github.com/eclipse-che4z/che-che4z-lsp-for-hlasm/compare/1.6.0...1.7.0) (2023-03-08) diff --git a/clients/vscode-hlasmplugin/src/configurationsHandler.ts b/clients/vscode-hlasmplugin/src/configurationsHandler.ts index e908ea928..9ae0effaa 100644 --- a/clients/vscode-hlasmplugin/src/configurationsHandler.ts +++ b/clients/vscode-hlasmplugin/src/configurationsHandler.ts @@ -42,19 +42,14 @@ export class ConfigurationsHandler { } /** - * Checks whether both config files are present - * Creates them on demand if not + * Checks whether config files are present + * Creates proc_grps.json or pgm_conf.json on demand if not */ - async checkConfigs(workspace: vscode.Uri) { - // configs exist - if (await ConfigurationsHandler.configFilesExist(workspace)) - return; - - const [g, p, e] = await configurationExists(workspace); + async checkConfigs(workspace: vscode.Uri, documentUri: vscode.Uri) { + const [g, p, b, e] = await configurationExists(workspace, documentUri); const doNotShowAgain = 'Do not track'; - // give option to create proc_grps if (!g.exists) vscode.window.showWarningMessage('proc_grps.json not found', @@ -68,7 +63,7 @@ export class ConfigurationsHandler { ConfigurationsHandler.createProcTemplate(workspace).then(uri => vscode.commands.executeCommand("vscode.open", uri)); } }); - if (!p.exists && !e.exists) + if (!p.exists && !b.exists && !e.exists) vscode.window.showWarningMessage('pgm_conf.json not found', ...['Create empty pgm_conf.json', 'Create pgm_conf.json with this file', doNotShowAgain]) .then((selection) => { @@ -190,7 +185,7 @@ export class ConfigurationsHandler { * Checks if the configs are there and stores their complete paths */ public static async configFilesExist(workspace: vscode.Uri): Promise { - const [g, p, e] = await configurationExists(workspace); + const [g, p] = await configurationExists(workspace, undefined); return g.exists && p.exists; } public static createCompleteConfig(workspace: vscode.Uri, program: string, group: string) { diff --git a/clients/vscode-hlasmplugin/src/constants.ts b/clients/vscode-hlasmplugin/src/constants.ts index 203d4b453..467d6df0e 100644 --- a/clients/vscode-hlasmplugin/src/constants.ts +++ b/clients/vscode-hlasmplugin/src/constants.ts @@ -14,5 +14,6 @@ export const pgm_conf_file = 'pgm_conf.json'; export const proc_grps_file = 'proc_grps.json'; +export const bridge_json_file = '.bridge.json'; export const hlasmplugin_folder = '.hlasmplugin'; export const ebg_folder = '.ebg'; diff --git a/clients/vscode-hlasmplugin/src/eventsHandler.ts b/clients/vscode-hlasmplugin/src/eventsHandler.ts index dfcb0ead2..b6b20a3b5 100644 --- a/clients/vscode-hlasmplugin/src/eventsHandler.ts +++ b/clients/vscode-hlasmplugin/src/eventsHandler.ts @@ -115,7 +115,7 @@ export class EventsHandler { if (!document.isClosed && this.langDetect.setHlasmLanguage(document)) { const workspace = vscode.workspace.getWorkspaceFolder(document.uri); if (workspace) - this.configSetup.checkConfigs(workspace.uri); + this.configSetup.checkConfigs(workspace.uri, document.uri); } }, 50); } diff --git a/clients/vscode-hlasmplugin/src/helpers.ts b/clients/vscode-hlasmplugin/src/helpers.ts index 14c6fb772..0e3d49af6 100644 --- a/clients/vscode-hlasmplugin/src/helpers.ts +++ b/clients/vscode-hlasmplugin/src/helpers.ts @@ -12,19 +12,21 @@ * Broadcom, Inc. - initial API and implementation */ import * as vscode from 'vscode'; -import { hlasmplugin_folder, proc_grps_file, pgm_conf_file, ebg_folder } from './constants'; +import { hlasmplugin_folder, proc_grps_file, pgm_conf_file, bridge_json_file, ebg_folder } from './constants'; -export async function uriExists(uri: vscode.Uri): Promise { - return vscode.workspace.fs.stat(uri).then(() => { return true; }, () => { return false; }) +export async function uriExists(uri: vscode.Uri, fs: vscode.FileSystem = vscode.workspace.fs): Promise { + return fs.stat(uri).then(() => { return true; }, () => { return false; }) } -export async function configurationExists(workspace: vscode.Uri) { +export async function configurationExists(workspace: vscode.Uri, documentUri: vscode.Uri | undefined, fs: vscode.FileSystem = vscode.workspace.fs) { const procGrps = vscode.Uri.joinPath(workspace, hlasmplugin_folder, proc_grps_file); const pgmConf = vscode.Uri.joinPath(workspace, hlasmplugin_folder, pgm_conf_file); + const bridgeJson = documentUri ? vscode.Uri.joinPath(documentUri, "..", bridge_json_file) : undefined; const ebgPath = vscode.Uri.joinPath(workspace, ebg_folder); return Promise.all([ - uriExists(procGrps).then(b => { return { uri: procGrps, exists: b }; }), - uriExists(pgmConf).then(b => { return { uri: pgmConf, exists: b }; }), - uriExists(ebgPath).then(b => { return { uri: ebgPath, exists: b }; }), + uriExists(procGrps, fs).then(b => { return { uri: procGrps, exists: b }; }), + uriExists(pgmConf, fs).then(b => { return { uri: pgmConf, exists: b }; }), + bridgeJson ? uriExists(bridgeJson, fs).then(b => { return { uri: bridgeJson, exists: b }; }) : { uri: vscode.Uri, exists: false }, + uriExists(ebgPath, fs).then(b => { return { uri: ebgPath, exists: b }; }), ]); } diff --git a/clients/vscode-hlasmplugin/src/hlasmCodeActionsProvider.ts b/clients/vscode-hlasmplugin/src/hlasmCodeActionsProvider.ts index 160063f94..f3c0a03a9 100644 --- a/clients/vscode-hlasmplugin/src/hlasmCodeActionsProvider.ts +++ b/clients/vscode-hlasmplugin/src/hlasmCodeActionsProvider.ts @@ -85,7 +85,7 @@ export class HLASMCodeActionsProvider implements vscode.CodeActionProvider { const workspace = vscode.workspace.getWorkspaceFolder(document.uri); if (!workspace) return result; - const [procGrps, pgmConf, ebgConf] = await configurationExists(workspace.uri); + const [procGrps, pgmConf, bridgeJson, ebgConf] = await configurationExists(workspace.uri, document.uri); if (E049.length > 0) { if (procGrps.exists) { @@ -113,7 +113,7 @@ export class HLASMCodeActionsProvider implements vscode.CodeActionProvider { let suggestPgmConfChange = E049.length > 0 || context.diagnostics.some(x => x.code === 'SUP'); if (suggestProcGrpsChange || suggestPgmConfChange) { - if (!procGrps.exists && !pgmConf.exists && !ebgConf.exists) { + if (!procGrps.exists && !pgmConf.exists && !bridgeJson.exists && !ebgConf.exists) { suggestProcGrpsChange = false; suggestPgmConfChange = false; result.push({ @@ -160,7 +160,7 @@ export class HLASMCodeActionsProvider implements vscode.CodeActionProvider { kind: vscode.CodeActionKind.QuickFix }); else { - if (ebgConf.exists) { + if (bridgeJson.exists || ebgConf.exists) { // TODO: could we trigger B4G sync? } result.push({ diff --git a/clients/vscode-hlasmplugin/src/test/mocks.ts b/clients/vscode-hlasmplugin/src/test/mocks.ts index 51d6d1671..1d057728c 100644 --- a/clients/vscode-hlasmplugin/src/test/mocks.ts +++ b/clients/vscode-hlasmplugin/src/test/mocks.ts @@ -248,3 +248,50 @@ export class TextDocumentMock implements vscode.TextDocument { return new vscode.Position(0, this.text.length); } } + +export class FileSystemMock implements vscode.FileSystem { + resource = new Set(); + dummyStat: vscode.FileStat; + + public addResource(uri: vscode.Uri) { + this.resource.add(uri.path); + } + + stat(uri: vscode.Uri): Thenable { + return new Promise((resolve, reject) => { + this.resource.has(uri.path) ? resolve(this.dummyStat) : reject("Resource not found"); + }); + } + + readDirectory(uri: vscode.Uri): Thenable<[string, vscode.FileType][]> { + throw new Error("Method not implemented."); + } + + createDirectory(uri: vscode.Uri): Thenable { + throw new Error("Method not implemented."); + } + + readFile(uri: vscode.Uri): Thenable { + throw new Error("Method not implemented."); + } + + writeFile(uri: vscode.Uri, content: Uint8Array): Thenable { + throw new Error("Method not implemented."); + } + + delete(uri: vscode.Uri, options?: { recursive?: boolean, useTrash?: boolean }): Thenable { + throw new Error("Method not implemented."); + } + + rename(source: vscode.Uri, target: vscode.Uri, options?: { overwrite?: boolean }): Thenable { + throw new Error("Method not implemented."); + } + + copy(source: vscode.Uri, target: vscode.Uri, options?: { overwrite?: boolean }): Thenable { + throw new Error("Method not implemented."); + } + + isWritableFileSystem(scheme: string): boolean | undefined { + throw new Error("Method not implemented."); + } +} diff --git a/clients/vscode-hlasmplugin/src/test/suite/configurationsHandler.test.ts b/clients/vscode-hlasmplugin/src/test/suite/configurationsHandler.test.ts index 7e690c23f..8d402c1c9 100644 --- a/clients/vscode-hlasmplugin/src/test/suite/configurationsHandler.test.ts +++ b/clients/vscode-hlasmplugin/src/test/suite/configurationsHandler.test.ts @@ -13,11 +13,12 @@ */ import * as assert from 'assert'; -import * as path from 'path'; import * as vscode from 'vscode'; import { ConfigurationsHandler } from '../../configurationsHandler'; -import { hlasmplugin_folder, pgm_conf_file, proc_grps_file } from '../../constants'; +import { ebg_folder, bridge_json_file } from '../../constants'; +import { configurationExists } from '../../helpers'; +import { FileSystemMock } from '../mocks'; suite('Configurations Handler Test Suite', () => { const handler = new ConfigurationsHandler(); @@ -35,4 +36,32 @@ suite('Configurations Handler Test Suite', () => { assert.ok(handler.match(vscode.Uri.joinPath(workspaceUri, 'file.asm'))); assert.ok(handler.match(vscode.Uri.joinPath(workspaceUri, 'pgms/file'))); }); + + test('Existing b4g configs', async () => { + const fsMock = new FileSystemMock(); + const pgmUri = vscode.Uri.joinPath(workspaceUri, "SYS/SUB/PGM"); + const bridgeJsonUri = vscode.Uri.joinPath(workspaceUri, "SYS/SUB", bridge_json_file); + const ebgUri = vscode.Uri.joinPath(workspaceUri, ebg_folder); + + fsMock.addResource(bridgeJsonUri); + fsMock.addResource(ebgUri); + fsMock.addResource(pgmUri); + + const [g, p, b, e] = await configurationExists(workspaceUri, pgmUri, fsMock); + assert.equal(b.exists, true); + assert.equal(e.exists, true); + assert.deepStrictEqual(b.uri, bridgeJsonUri); + assert.deepStrictEqual(e.uri, ebgUri); + }); + + test('Non-existing b4g configs', async () => { + const fsMock = new FileSystemMock(); + const pgmUri = vscode.Uri.joinPath(workspaceUri, "SYS/SUB/PGM"); + + fsMock.addResource(pgmUri); + + const [g, p, b, e] = await configurationExists(workspaceUri, pgmUri, fsMock); + assert.equal(b.exists, false); + assert.equal(e.exists, false); + }); });