Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,545 changes: 419 additions & 1,126 deletions client/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
},
"dependencies": {
"jsdom": "^26.1.0",
"node-html-markdown": "^1.3.0",
"node-html-markdown": "^2.0.0",
"vscode-languageclient": "^7.0.0",
"xml2js": "^0.6.2"
},
"devDependencies": {
"@halcyontech/vscode-ibmi-types": "^2.17.0",
"@types/jsdom": "^27.0.0",
"@types/node": "^18.11.5",
"@halcyontech/vscode-ibmi-types": "^3.0.7",
"@types/jsdom": "^28.0.3",
"@types/node": "^25.9.2",
"@types/vscode": "^1.50.0",
"@types/xml2js": "^0.4.11",
"@vscode/test-electron": "^2.1.2"
"@types/xml2js": "^0.4.14",
"@vscode/test-electron": "^2.5.2"
}
}
2 changes: 1 addition & 1 deletion client/src/clRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function initialiseRunner(context: ExtensionContext) {
const document = editor.document;

if (document && document.languageId === `cl`) {
const connection = instance.getConnection();
const connection = instance?.getConnection();

if (connection) {
const selectedCommand = getCommandString(editor.selection, document);
Expand Down
26 changes: 13 additions & 13 deletions client/src/components/gencmdxml/gencmdxml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentIdentification, ComponentState, IBMiComponent } from "@halcyontech/vscode-ibmi-types/api/components/component";
import { ComponentIdentification, IBMiComponent, SecureComponentState } from "@halcyontech/vscode-ibmi-types/api/components/component";
import IBMi from '@halcyontech/vscode-ibmi-types/api/IBMi';
import { getComponentRegistry, getInstance, getVSCodeTools } from '../../api/ibmi';
import * as xml2js from "xml2js";
Expand All @@ -12,7 +12,7 @@ export default class GenCmdXml implements IBMiComponent {
private library: string | undefined;

getIdentification(): ComponentIdentification {
return { name: GenCmdXml.ID, version: this.currentVersion };
return { name: GenCmdXml.ID, version: this.currentVersion } as any;
}

static get(): GenCmdXml | undefined {
Expand All @@ -22,7 +22,7 @@ export default class GenCmdXml implements IBMiComponent {
const componentManager = connection.getComponentManager();
const componentStates = componentManager.getComponentStates();
const genCmdXmlComponentState = componentStates.find(cs => cs.id.name === GenCmdXml.ID);
if (genCmdXmlComponentState && (genCmdXmlComponentState.state === `Installed` || genCmdXmlComponentState.state === `NeedsUpdate`)) {
if (genCmdXmlComponentState && (genCmdXmlComponentState.state.status === `Installed` || genCmdXmlComponentState.state.status === `NeedsUpdate`)) {
const allAvailableComponents = componentManager.getAllAvailableComponents();
const genCmdXmlComponent = allAvailableComponents.find(ac => ac.getIdentification().name === GenCmdXml.ID) as GenCmdXml;
if (genCmdXmlComponent) {
Expand All @@ -35,15 +35,15 @@ export default class GenCmdXml implements IBMiComponent {
}
}

async getRemoteState(connection: IBMi, installDirectory: string): Promise<ComponentState> {
async getRemoteState(connection: IBMi, installDirectory: string): Promise<SecureComponentState> {
const library = this.getLibrary(connection);

const pgmVersion = await GenCmdXml.getVersionOf(connection, library, GenCmdXml.PGM_NAME);
if (Number.isNaN(pgmVersion) || pgmVersion < this.currentVersion) {
return `NeedsUpdate`;
return { status: `NeedsUpdate` };
}

return `Installed`;
return { status: `Installed` };
}

static registerComponent(context: ExtensionContext) {
Expand All @@ -53,7 +53,7 @@ export default class GenCmdXml implements IBMiComponent {
}


async update(connection: IBMi, installDirectory: string): Promise<ComponentState> {
async update(connection: IBMi, installDirectory: string): Promise<SecureComponentState> {
const content = connection.getContent();
const tempLib = this.getLibrary(connection);

Expand All @@ -70,10 +70,10 @@ export default class GenCmdXml implements IBMiComponent {
noLibList: true
});
if (createProgram.code !== 0) {
return `Error`
return { status: `Error` };
}

return `Installed`;
return { status: `Installed` };
}

reset?(): void | Promise<void> {
Expand All @@ -87,14 +87,14 @@ export default class GenCmdXml implements IBMiComponent {
if (genCmdXml) {
try {
const instance = getInstance();
const connection = instance.getConnection();
const connection = instance?.getConnection();
if (connection) {
const content = connection.getContent();
const tempLib = this.getLibrary(connection);

const targetCommand = objectName.padEnd(10) + library.padEnd(10);
const vsCodeTools = getVSCodeTools();
const targetName = vsCodeTools.makeid();
const targetName = vsCodeTools!.makeid();

const callResult = await connection.runCommand({
command: `CALL PGM(${tempLib}/${GenCmdXml.PGM_NAME}) PARM('${targetName}' '${targetCommand}')`,
Expand All @@ -108,8 +108,8 @@ export default class GenCmdXml implements IBMiComponent {
connection.sendCommand({ command: `rm -rf ${resultingFile}` });
const commandData = await xml2js.parseStringPromise(xml);
return commandData;
} catch (e) {
console.log(`Command likely doesn't exist: ${targetCommand}: ${e.message}`);
} catch (e: any) {
console.log(`Command likely doesn't exist: ${targetCommand}: ${e.message ? e.message : e}`);
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions client/src/components/syntaxChecker/checker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { ComponentIdentification, ComponentState, IBMiComponent } from "@halcyontech/vscode-ibmi-types/api/components/component";
import { ComponentIdentification, SecureComponentState, IBMiComponent } from "@halcyontech/vscode-ibmi-types/api/components/component";
import IBMi from '@halcyontech/vscode-ibmi-types/api/IBMi';
import { getCLCheckerCPPSrc } from './cppSource';
import { getCLCheckerUDTFSrc } from './udtfSource';
Expand Down Expand Up @@ -32,24 +32,24 @@ export class CLSyntaxChecker implements IBMiComponent {
private library: string | undefined;

getIdentification(): ComponentIdentification {
return { name: CLSyntaxChecker.ID, version: this.currentVersion };
return { name: CLSyntaxChecker.ID, version: this.currentVersion } as any;
}

static get(): CLSyntaxChecker | undefined {
static async get(): Promise<CLSyntaxChecker | undefined> {
const instance = getInstance();
const connection = instance?.getConnection();
return connection?.getComponent<CLSyntaxChecker>(CLSyntaxChecker.ID);
return await connection?.getComponent<CLSyntaxChecker>(CLSyntaxChecker.ID);
}

async getRemoteState(connection: IBMi, installDirectory: string): Promise<ComponentState> {
async getRemoteState(connection: IBMi, installDirectory: string): Promise<SecureComponentState> {
const library = this.getLibrary(connection);

const udtfVersion = await CLSyntaxChecker.getVersionOf(connection, library!, CLSyntaxChecker.UDTF_NAME);
if (udtfVersion < this.currentVersion) {
return `NeedsUpdate`;
return { status: `NeedsUpdate` };
}

return `Installed`;
return { status: `Installed` };
}

static registerComponent(context: ExtensionContext) {
Expand All @@ -58,7 +58,7 @@ export class CLSyntaxChecker implements IBMiComponent {
componentRegistry?.registerComponent(context, clSyntaxChecker);
}

async update(connection: IBMi, installDirectory: string): Promise<ComponentState> {
async update(connection: IBMi, installDirectory: string): Promise<SecureComponentState> {
return await connection.withTempDirectory(async (tempDir: string) => {
const content = connection.getContent();
const textEncoder = new TextEncoder();
Expand All @@ -77,7 +77,7 @@ export class CLSyntaxChecker implements IBMiComponent {
noLibList: true
});
if (createModuleResult.code !== 0) {
return `Error`;
return { status: `Error` };
}

// Create C++ program
Expand All @@ -87,7 +87,7 @@ export class CLSyntaxChecker implements IBMiComponent {
noLibList: true
});
if (createProgramResult.code !== 0) {
return `Error`;
return { status: `Error` };
}

// Upload UDTF source
Expand All @@ -97,8 +97,8 @@ export class CLSyntaxChecker implements IBMiComponent {
await content.writeStreamfileRaw(sqlPath, sqlBytes);

// Drop existing UDTF specific
const dropUdtf = `DROP SPECIFIC FUNCTION ${library}.${CLSyntaxChecker.UDTF_NAME}`;
try {
const dropUdtf = `DROP SPECIFIC FUNCTION ${library}.${CLSyntaxChecker.UDTF_NAME}`;
const dropUdtfResult = await connection.runSQL(dropUdtf);
} catch (error) {
// Ignore error as UDTF may not exist
Expand All @@ -111,10 +111,10 @@ export class CLSyntaxChecker implements IBMiComponent {
noLibList: true
});
if (createUdtfResult.code !== 0) {
return `Error`
return { status: `Error` }
}

return `Installed`;
return { status: `Installed` };
});
}

Expand Down
56 changes: 31 additions & 25 deletions client/src/components/syntaxChecker/problemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ export namespace ProblemProvider {
}
}),

workspace.onDidOpenTextDocument(e => {
workspace.onDidOpenTextDocument(async e => {
const isSupportedLanguage = SUPPORTED_LANGUAGE_IDS.includes(e.languageId as SupportedLanguageId);
if (isSupportedLanguage) {
if (checkerAvailable() && !isSafeDocument(e)) {
if (await checkerAvailable() && !isSafeDocument(e)) {
const basename = e.fileName ? path.basename(e.fileName) : `Untitled`;
documentLargeError(basename);
}
Expand All @@ -46,13 +46,13 @@ export namespace ProblemProvider {
}
}),

workspace.onDidChangeTextDocument(e => {
workspace.onDidChangeTextDocument(async e => {
shiftDiagnostics(e.document, e.contentChanges);

const isSupportedLanguage = SUPPORTED_LANGUAGE_IDS.includes(e.document.languageId as SupportedLanguageId);
if (isSupportedLanguage) {
const checkOnChange = Configuration.get<boolean>(`syntax.checkOnEdit`) || false;
if (checkerAvailable() && checkOnChange && e.contentChanges.length > 0) {
if (await checkerAvailable() && checkOnChange && e.contentChanges.length > 0) {
if (currentTimeout) {
clearTimeout(currentTimeout);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ export namespace ProblemProvider {
// Diagnostics within the change are removed
return diag;
}
});
}).filter((diag) => diag !== undefined);

// Update the diagnostic collection
clleDiagnosticCollection.set(document.uri, updatedDiagnostics);
Expand All @@ -158,7 +158,7 @@ export namespace ProblemProvider {
}

async function validateCLDocument(document: TextDocument, specificLines?: number[]) {
const checker = CLSyntaxChecker.get();
const checker = await CLSyntaxChecker.get();
if (checker) {
const basename = document.fileName ? path.basename(document.fileName) : `Untitled`;
if (isSafeDocument(document)) {
Expand All @@ -185,7 +185,11 @@ export namespace ProblemProvider {

// Remove duplicate commands to check
commandsToCheck = commandsToCheck.filter((command, index, self) =>
index === self.findIndex((c) => c.content === command.content && c.range.start === command.range.start && c.range.end === command.range.end)
index === self.findIndex((c) =>
c.content === command.content &&
c.range && command.range &&
c.range.start === command.range.start &&
c.range.end === command.range.end)
);

// Get any existing diagnostics for this document
Expand All @@ -203,11 +207,11 @@ export namespace ProblemProvider {
for (const commandToCheck of commandsToCheck) {
const diagStart = diag.range.start.line;
const diagEnd = diag.range.end.line;
const cmdStart = commandToCheck.range.start;
const cmdEnd = commandToCheck.range.end;
const cmdStart = commandToCheck.range?.start;
const cmdEnd = commandToCheck.range?.end;

// Check if diagnostic overlaps with command range
if (diagStart <= cmdEnd && diagEnd >= cmdStart) {
if (cmdStart && cmdEnd && diagStart <= cmdEnd && diagEnd >= cmdStart) {
diagnostics.splice(i, 1);
break;
}
Expand All @@ -233,17 +237,19 @@ export namespace ProblemProvider {
const results = await checker.check(command.content, languageId);
if (results) {
for (const result of results) {
const startLine = command.range.start;
const startCharacter = document.lineAt(startLine).firstNonWhitespaceCharacterIndex;
const endLine = command.range.end;
const endCharacter = document.lineAt(endLine).text.length;
const range = new Range(startLine, startCharacter, endLine, endCharacter);
const diagnostic = new Diagnostic(
range,
`${result.msgid}: ${result.msgtext}`,
DiagnosticSeverity.Error
);
diagnostics.push(diagnostic);
const startLine = command.range?.start;
const endLine = command.range?.end;
if (startLine && endLine) {
const startCharacter = document.lineAt(startLine).firstNonWhitespaceCharacterIndex;
const endCharacter = document.lineAt(endLine).text.length;
const range = new Range(startLine, startCharacter, endLine, endCharacter);
const diagnostic = new Diagnostic(
range,
`${result.msgid}: ${result.msgtext}`,
DiagnosticSeverity.Error
);
diagnostics.push(diagnostic);
}
}
}
} catch (error) {
Expand All @@ -267,12 +273,12 @@ export namespace ProblemProvider {
return isSupportedLanguage && isBelowMaxLength;
}

function checkerAvailable() {
return CLSyntaxChecker.get() !== undefined;
async function checkerAvailable() {
return (await CLSyntaxChecker.get()) !== undefined;
}

export function setCheckerAvailableContext(additionalState = true) {
const available = checkerAvailable() && additionalState;
export async function setCheckerAvailableContext(additionalState = true) {
const available = await checkerAvailable() && additionalState;
commands.executeCommand(`setContext`, `vscode-clle.syntax.checkerAvailable`, available);
}

Expand Down
4 changes: 2 additions & 2 deletions client/src/gencmddoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export class GenCmdDoc {

public static async generateHtml(object: string, library: string): Promise<string | undefined> {
const instance = getInstance();
const connection = instance.getConnection();
const connection = instance?.getConnection();

if (connection) {
const content = connection.getContent();
const config = connection.getConfig();

const cmd = `${library}/${object}`;
const toStmf = `${library.replace('*', '')}_${object}`;
const toDir = config.tempDir;
const toDir = connection.getTempDirectory();
const generateResult = await connection.runCommand({
command: `GENCMDDOC CMD(${cmd}) GENOPT(*HTML *SHOWCHOICEPGMVAL) REPLACE(*YES) TOSTMF('${toStmf}') TODIR('${toDir}')`
});
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function removePlusJoins(lines: string[]) {
*/
export async function getFileDefinition(objectName: string, library = `*LIBL`): Promise<any | undefined> {
const instance = getInstance();
const connection = instance.getConnection();
const connection = instance?.getConnection();
if (connection) {
const content = connection.getContent();
const config = connection.getConfig();
Expand Down
Loading
Loading