Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
worksofliam authored Jan 22, 2024
2 parents c79a4a1 + 511d8c3 commit 61d5ac2
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 40 deletions.
14 changes: 7 additions & 7 deletions extension/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extension/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"vscode-languageclient": "^7.0.0"
},
"devDependencies": {
"@halcyontech/vscode-ibmi-types": "^2.1.0",
"@halcyontech/vscode-ibmi-types": "^2.6.5",
"@types/vscode": "^1.63.0",
"@vscode/test-electron": "^2.1.2"
}
Expand Down
33 changes: 23 additions & 10 deletions extension/client/src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export function initialise(context: ExtensionContext) {
const instance = getInstance();
const editor = window.activeTextEditor;

let exists = false;

if (editor && ![`member`, `streamfile`].includes(editor.document.uri.scheme)) {
const workspaces = workspace.workspaceFolders;
if (workspaces && workspaces.length > 0) {
Expand Down Expand Up @@ -44,15 +46,23 @@ export function initialise(context: ExtensionContext) {
}

} else if (instance && instance.getConnection()) {
const connection = instance.getConnection();
const content = instance.getContent();

/** @type {"member"|"streamfile"} */
let type = `member`;
let configPath: string | undefined;

if (filter && filter.description) {
// Bad way to get the library for the filter ..
const library = filter.description.split(`/`)[0];
const library = (filter.description.split(`/`)[0]).toLocaleUpperCase();
configPath = `${library}/VSCODE/RPGLINT.JSON`;

exists = (await connection.runCommand({
command: `CHKOBJ OBJ(${library}/VSCODE) OBJTYPE(*FILE) MBR(RPGLINT)`,
noLibList: true
})).code === 0;

} else if (editor) {
//@ts-ignore
type = editor.document.uri.scheme;
Expand All @@ -74,12 +84,18 @@ export function initialise(context: ExtensionContext) {
});

configPath = memberUri.path;

exists = (await connection.runCommand({
command: `CHKOBJ OBJ(${memberPath.library!.toLocaleUpperCase()}/VSCODE) OBJTYPE(*FILE) MBR(RPGLINT)`,
noLibList: true
})).code === 0;
break;

case `streamfile`:
const config = instance.getConfig();
if (config.homeDirectory) {
configPath = path.posix.join(config.homeDirectory, `.vscode`, `rpglint.json`)
exists = (await connection.sendCommand({ command: `test -e ${configPath}` })).code === 0;
}
break;
}
Expand All @@ -90,12 +106,9 @@ export function initialise(context: ExtensionContext) {
if (configPath) {
console.log(`Current path: ${configPath}`);

const exists = await commands.executeCommand(`code-for-ibmi.openEditable`, configPath, 1);

if (!exists) {
const connection = instance.getConnection();
const content = instance.getContent();

if (exists) {
await commands.executeCommand(`code-for-ibmi.openEditable`, configPath);
} else {
window.showErrorMessage(`RPGLE linter config doesn't exist for this file. Would you like to create a default at ${configPath}?`, `Yes`, `No`).then
(async (value) => {
if (value === `Yes`) {
Expand Down Expand Up @@ -157,10 +170,10 @@ export function initialise(context: ExtensionContext) {
)
}

function parseMemberUri(path: string): {asp?: string, library?: string, file?: string, name: string} {
const parts = path.split(`/`).map(s => s.split(`,`)).flat().filter(s => s.length >= 1);
function parseMemberUri(fullPath: string): {asp?: string, library?: string, file?: string, name: string} {
const parts = fullPath.split(`/`).map(s => s.split(`,`)).flat().filter(s => s.length >= 1);
return {
name: parts[parts.length - 1],
name: path.parse(parts[parts.length - 1]).name,
file: parts[parts.length - 2],
library: parts[parts.length - 3],
asp: parts[parts.length - 4]
Expand Down
2 changes: 1 addition & 1 deletion extension/server/src/providers/linter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export async function refreshLinterDiagnostics(document: TextDocument, docs: Cac
}

// Turn on for SQLRunner suggestions
// options.SQLRunner = true;
options.SQLRunner = true;

options.StringLiteralDupe = true;

Expand Down
27 changes: 21 additions & 6 deletions language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,26 @@ export default class Parser {
directiveLength = 9
};

/** @type {string|undefined} */
let directiveValue;

if (directivePosition >= 0) {
if (comment >= 0) {
return line.substring(directivePosition+directiveLength, comment).trim();
directiveValue = line.substring(directivePosition+directiveLength, comment).trim();
} else {
return line.substring(directivePosition+directiveLength).trim();
directiveValue = line.substring(directivePosition+directiveLength).trim();
}
}

if (directiveValue) {
const spaceIndex = directiveValue.indexOf(` `);
if (spaceIndex >= 0) {
directiveValue = directiveValue.substring(0, spaceIndex);
}

return directiveValue;
}

}

/**
Expand Down Expand Up @@ -1032,10 +1045,12 @@ export default class Parser {
scope.files.push(currentItem);
} else {
currentItem = scope.files[scope.files.length-1];
currentItem.keywords = [
...(currentItem.keywords ? currentItem.keywords : []),
...fSpec.keywords
]
if (currentItem) {
currentItem.keywords = [
...(currentItem.keywords ? currentItem.keywords : []),
...fSpec.keywords
]
}
}

resetDefinition = true;
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/halcyon-tech/vscode-rpgle"
},
"license": "MIT",
"version": "0.23.0",
"version": "0.24.1",
"engines": {
"vscode": "^1.70.0"
},
Expand Down
82 changes: 82 additions & 0 deletions tests/suite/fixed.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

const assert = require(`assert`);
const path = require(`path`);

const {default: parserSetup} = require(`../parserSetup`);

Expand Down Expand Up @@ -416,6 +417,37 @@ exports.fixed9_2 = async () => {
assert.strictEqual(theExtProcedure.subItems.length, 1);
};



exports.fixed9_3 = async () => {
const lines = [
``,
` Ctl-Opt DftActGrp(*No);`,
` /copy tests,eof4 Call plist update program ESF`,
` *COPY EQCPYLESRC,PLUPT_SB Call plist update program ESF`,
``,
` Dcl-s MyVariable2 Char(20);`,
``,
` Dcl-C theConstant 'Hello world';`,
``,
` dsply theConstant;`,
``,
` Return;`
].join(`\n`);

const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true});

assert.strictEqual(cache.includes.length, 1);
assert.strictEqual(cache.variables.length, 1, `Expect length of 1`);
assert.strictEqual(cache.constants.length, 1, `Expect length of 1`);
assert.strictEqual(cache.procedures.length, 1, `Expect length of 1`);

const uppercase = cache.find(`UPPERCASE`);

const baseNameInclude = path.basename(uppercase.position.path);
assert.strictEqual(baseNameInclude, `eof4.rpgle`);
}

/**
* Issue with detecting correct type on subfield.
*/
Expand Down Expand Up @@ -1088,4 +1120,54 @@ exports.file_keywords = async () => {
assert.strictEqual(ord100d.keyword[`INDDS`], `indds`);
assert.strictEqual(ord100d.keyword[`SFILE`], `sfl01:rrn01`);
assert.strictEqual(ord100d.keyword[`INFDS`], `Info`);
}

exports.plist_test = async () => {
const lines = [
``,
` ?* PLPVD`,
` ?* PLPVD - Calling Plist for prompt/validate module driver PLPVD`,
` ?* PLPVD`,
` ?* Kaprog - E3A PLPVD`,
` ?* PLPVD`,
` ?* @PGMID - Program name PLPVD`,
` ?* @FLN - Field to prompt/validate on PLPVD`,
` ?* @SQN - Sequence number of type of validation/prompt PLPVD`,
` ?* @PRMPT - Prompt mode ('Y' or 'N') PLPVD`,
` ?* CCN - Communication array PLPVD`,
` ?* @ERMSG - Error message return field & parms PLPVD`,
` ?* @NUM - Numeric return field PLPVD`,
` ?* @CKEY - Command key used from prompt screen return field PLPVD`,
` ?* @PPF - Prompt performed flag ('Y' or 'N') returned PLPVD`,
` ?* @DSCNTRL - API Control Fields PLPVD`,
` ?* @DSSUPER - API Supervisor Data PLPVD`,
` ?* @DSINCRM - API Incremental Mode Control Fields PLPVD`,
` ?* @DSPV - PV Control Fields PLPVD`,
` ?* @DLFILTER - DL Filter Data PLDLD`,
` ?* @DLLIST - Array of DL row data PLDLD`,
` ?* @DLSELECTION - DL Selected Item PLDLD`,
` ?* PLDLD`,
` C PLPVD PLIST`,
` C PARM @PGMID 10`,
` C PARM @FLN 6`,
` C PARM @SQN 2 0`,
` C PARM @PRMPT 1`,
` C PARM CCN`,
` C DSEPMS PARM DSEPMS @ERMSG 37`,
` C PARM @NUM 15 0`,
` C PARM @CKEY 2`,
` C PARM @PPF 1`,
` C PARM @DSCNTRL`,
` C PARM @DSSUPER`,
` C PARM @DSINCRM`,
` C PARM @DSPV`,
` C PARM @PVFILTER 256`,
` C PARM @PVLIST 9999`,
` C PARM @PVSELECTION 256`,
``
].join(`\n`);

const cache = await parser.getDocs(uri, lines, {ignoreCache: true, withIncludes: true});

assert.strictEqual(cache.variables.length, 0);
}

0 comments on commit 61d5ac2

Please sign in to comment.