Skip to content

Commit

Permalink
fix: Prevent pgm_conf not found prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jirimosinger authored Apr 14, 2023
1 parent 04df0f0 commit d57895e
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 24 deletions.
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 6 additions & 11 deletions clients/vscode-hlasmplugin/src/configurationsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) => {
Expand Down Expand Up @@ -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<boolean> {
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) {
Expand Down
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion clients/vscode-hlasmplugin/src/eventsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 9 additions & 7 deletions clients/vscode-hlasmplugin/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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<boolean> {
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 }; }),
]);
}
6 changes: 3 additions & 3 deletions clients/vscode-hlasmplugin/src/hlasmCodeActionsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
47 changes: 47 additions & 0 deletions clients/vscode-hlasmplugin/src/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
dummyStat: vscode.FileStat;

public addResource(uri: vscode.Uri) {
this.resource.add(uri.path);
}

stat(uri: vscode.Uri): Thenable<vscode.FileStat> {
return new Promise<vscode.FileStat>((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<void> {
throw new Error("Method not implemented.");
}

readFile(uri: vscode.Uri): Thenable<Uint8Array> {
throw new Error("Method not implemented.");
}

writeFile(uri: vscode.Uri, content: Uint8Array): Thenable<void> {
throw new Error("Method not implemented.");
}

delete(uri: vscode.Uri, options?: { recursive?: boolean, useTrash?: boolean }): Thenable<void> {
throw new Error("Method not implemented.");
}

rename(source: vscode.Uri, target: vscode.Uri, options?: { overwrite?: boolean }): Thenable<void> {
throw new Error("Method not implemented.");
}

copy(source: vscode.Uri, target: vscode.Uri, options?: { overwrite?: boolean }): Thenable<void> {
throw new Error("Method not implemented.");
}

isWritableFileSystem(scheme: string): boolean | undefined {
throw new Error("Method not implemented.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
});
});

0 comments on commit d57895e

Please sign in to comment.