Skip to content

Support for global RPGLINT configuration path #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions .github/workflows/package-extension.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build VSIX

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- run: npm install

- name: Compile extension/client only
run: tsc -p extension/client/tsconfig.json

- name: Package VSIX
run: npx vsce package

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: rpgle-extension
path: '*.vsix'
1 change: 1 addition & 0 deletions extension/client/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export function get<T>(prop: string) {
}

export const RULER_ENABLED_BY_DEFAULT = `rulerEnabledByDefault`;
export const GLOBAL_LINT_CONFIG_PATH = `globalLintConfigPath`;
export const projectFilesGlob = `**/*.{rpgle,RPGLE,sqlrpgle,SQLRPGLE,rpgleinc,RPGLEINC}`;
24 changes: 16 additions & 8 deletions extension/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,22 @@ export function activate(context: ExtensionContext) {

// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
const serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};
const globalLintPath = workspace.getConfiguration('vscode-rpgle').get<string>('globalLintConfigPath');
const env = { ...process.env } as NodeJS.ProcessEnv;
if (globalLintPath) env.GLOBAL_LINT_CONFIG_PATH = globalLintPath;

const serverOptions: ServerOptions = {
run: {
module: serverModule,
transport: TransportKind.ipc,
options: { env }
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: { ...debugOptions, env }
}
};

loadBase();

Expand Down
51 changes: 46 additions & 5 deletions extension/client/src/linter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path = require('path');
import { commands, ExtensionContext, Uri, ViewColumn, window, workspace } from 'vscode';
import {getInstance} from './base';
import * as Configuration from './configuration';

import {DEFAULT_SCHEMA} from "./schemas/linter"

Expand Down Expand Up @@ -46,8 +47,34 @@ export function initialise(context: ExtensionContext) {
}

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

let globalPath = Configuration.get<string>(Configuration.GLOBAL_LINT_CONFIG_PATH);

if (globalPath?.startsWith('/')) {
globalPath = globalPath.substring(1);
}

if (globalPath) {
try {
const parts = connection.parserMemberPath(globalPath);
const existsRes = await connection.runCommand({
command: `CHKOBJ OBJ(${parts.library}/${parts.file}) OBJTYPE(*FILE) MBR(${parts.name})`,
noLibList: true
});

if (existsRes.code === 0) {
await commands.executeCommand(`code-for-ibmi.openEditable`, globalPath);
} else {
window.showErrorMessage(`Global lint config does not exist at ${globalPath}.`);
}
} catch (e) {
console.log(e);
window.showErrorMessage(`Failed to open global lint configuration.`);
}
return;
}

/** @type {"member"|"streamfile"} */
let type = `member`;
Expand Down Expand Up @@ -117,8 +144,22 @@ export function initialise(context: ExtensionContext) {
} 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`) {
const jsonString = JSON.stringify(DEFAULT_SCHEMA, null, 2);
if (value === `Yes`) {
let jsonString: string | undefined;

if (type === `member`) {
const globalPath = Configuration.get<string>(Configuration.GLOBAL_LINT_CONFIG_PATH);
if (globalPath) {
try {
const globalParts = connection.parserMemberPath(globalPath);
jsonString = await content.downloadMemberContent(globalParts.library, globalParts.file, globalParts.name);
} catch (e) {
console.log(`Failed to load global lint config: ${e}`);
}
}
}

if (!jsonString) jsonString = JSON.stringify(DEFAULT_SCHEMA, null, 2);

switch (type) {
case `member`:
Expand Down Expand Up @@ -184,4 +225,4 @@ function parseMemberUri(fullPath: string): {asp?: string, library?: string, file
library: parts[parts.length - 3],
asp: parts[parts.length - 4]
}
};
};
40 changes: 23 additions & 17 deletions extension/client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"outDir": "out",
"rootDir": "src",
"lib": [ "es2020" ],
"sourceMap": true,
"composite": true
},
"include": [
"src"
],
"exclude": [
"node_modules", ".vscode-test", "src/test"
]
}
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"outDir": "../../out/client",
"lib": ["ES2020"],
"sourceMap": true,
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"noUnusedLocals": false,
"moduleResolution": "node",
"types": [],
"typeRoots": ["node_modules/@types"]
},
"include": ["src/**/*.ts"],
"exclude": [
"**/node_modules",
"**/vscode-ibmi-types/**/*",
"**/node-ssh/**/*"
]
}
31 changes: 23 additions & 8 deletions extension/server/src/providers/linter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,29 @@ enum ResolvedState {
let boundLintConfig: {[workingUri: string]: {resolved: ResolvedState, uri: string}} = {};

export async function getLintConfigUri(workingUri: string) {
const uri = URI.parse(workingUri);
let cleanString: string | undefined;

const cached = boundLintConfig[workingUri];

if (cached) {
return cached.resolved === ResolvedState.Found ? cached.uri : undefined;
}
const uri = URI.parse(workingUri);
let cleanString: string | undefined;

const cached = boundLintConfig[workingUri];

if (cached) {
return cached.resolved === ResolvedState.Found ? cached.uri : undefined;
}

if (uri.scheme === `member`) {
const globalPath = process.env.GLOBAL_LINT_CONFIG_PATH;
if (globalPath) {
cleanString = URI.from({ scheme: `member`, path: globalPath }).toString();
cleanString = await validateUri(cleanString, `member`);
if (cleanString) {
boundLintConfig[workingUri] = {
resolved: ResolvedState.Found,
uri: cleanString
};
return cleanString;
}
}
}

switch (uri.scheme) {
case `member`:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@
"configuration": {
"title": "RPGLE language tools",
"properties": {
"vscode-rpgle.rulerEnabledByDefault": {
"type": "boolean",
"default": true,
"description": "Whether to show the fixed-format ruler by default."
}
}
},
"vscode-rpgle.rulerEnabledByDefault": {
"type": "boolean",
"default": true,
"description": "Whether to show the fixed-format ruler by default."
},
"vscode-rpgle.globalLintConfigPath": {
"type": "string",
"default": "",
"description": "QSYS.LIB path for global RPGLINT.JSON."
}
}
},
"snippets": [
{
"path": "./schemas/rpgle.code-snippets",
Expand Down
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2020",
"outDir": "../../out/client",
"lib": ["ES2020"],
"sourceMap": true,
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"noUnusedLocals": false,
"moduleResolution": "node",
"forceConsistentCasingInFileNames": false
},
"include": ["src/**/*.ts"],
"exclude": ["**/node_modules"]
}
Binary file added vscode-rpgle-0.32.1.vsix
Binary file not shown.
Binary file added vscode-rpgle-0.32.3.vsix
Binary file not shown.