Skip to content

Commit

Permalink
Merge branch 'master' of github.com:halcyon-tech/vscode-ibmi
Browse files Browse the repository at this point in the history
  • Loading branch information
worksofliam committed Nov 13, 2021
2 parents 0335d1e + fd97097 commit 1a64ada
Showing 1 changed file with 53 additions and 29 deletions.
82 changes: 53 additions & 29 deletions src/languages/rpgle/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,6 @@ module.exports = class RPGLinter {
}
}),

vscode.workspace.onDidChangeTextDocument((event) => {
if (Configuration.get(`rpgleIndentationEnabled`)) {
if (event.document.languageId === `rpgle`) {
const isFree = (event.document.getText(new vscode.Range(0, 0, 0, 6)).toUpperCase() === `**FREE`);
const text = event.document.getText();
if (isFree) {
this.linterDiagnostics.set(event.document.uri, this.parseFreeFormatDocument(text, {
indent: Number(vscode.window.activeTextEditor.options.tabSize)
}));
}
}
}
}),

vscode.commands.registerCommand(`code-for-ibmi.rpgleOpenInclude`, async => {
if (Configuration.get(`rpgleContentAssistEnabled`)) {
const editor = vscode.window.activeTextEditor;
Expand Down Expand Up @@ -149,6 +135,48 @@ module.exports = class RPGLinter {
}
}),

vscode.languages.registerCodeActionsProvider(`rpgle`, {
provideCodeActions: async (document, range) => {
let diagnostics = [];
/** @type {vscode.CodeAction[]} */
let actions = [];

const isFree = (document.getText(new vscode.Range(0, 0, 0, 6)).toUpperCase() === `**FREE`);
const text = document.getText();
if (isFree) {
const detail = this.parseFreeFormatDocument(text, {
indent: Number(vscode.window.activeTextEditor.options.tabSize)
});

const edit = new vscode.WorkspaceEdit();

if (detail.length > 0) {
detail.forEach(error => {
const action = new vscode.CodeAction(`Fix indentation on line ${error.line+1}`, vscode.CodeActionKind.QuickFix);
const range = new vscode.Range(error.line, 0, error.line, error.currentIndent);

const diagnostic = new vscode.Diagnostic(
range,
`Incorrect indentation. Expected ${error.expectedIndent}, got ${error.currentIndent}`,
vscode.DiagnosticSeverity.Warning
);

diagnostics.push(diagnostic);
edit.replace(document.uri, range, `${` `.repeat(error.expectedIndent)}`);
});

const action = new vscode.CodeAction(`Fix all indentation warnings`, vscode.CodeActionKind.QuickFix);
action.diagnostics = diagnostics;
action.edit = edit;
actions.push(action);
}
}

this.linterDiagnostics.set(document.uri, diagnostics);
return actions;
}
}),

vscode.languages.registerHoverProvider({language: `rpgle`}, {
provideHover: async (document, position, token) => {
if (Configuration.get(`rpgleContentAssistEnabled`)) {
Expand Down Expand Up @@ -903,7 +931,7 @@ module.exports = class RPGLinter {

let lineNumber = -1;

/** @type {vscode.Diagnostic[]} */
/** @type {{line: number, expectedIndent: number, currentIndent: number}[]} */
let diagnostics = [];

/** @type {Number} */
Expand All @@ -929,13 +957,11 @@ module.exports = class RPGLinter {
skipIndentCheck = true;

if (currentIndent < expectedIndent) {
diagnostics.push(
new vscode.Diagnostic(
new vscode.Range(lineNumber, 0, lineNumber, currentIndent),
`Incorrect indentation. Expected ${expectedIndent}, got ${currentIndent}`,
vscode.DiagnosticSeverity.Warning
)
);
diagnostics.push({
line: lineNumber,
expectedIndent,
currentIndent
});
}
}

Expand Down Expand Up @@ -972,13 +998,11 @@ module.exports = class RPGLinter {
}

if (currentIndent !== expectedIndent && !skipIndentCheck) {
diagnostics.push(
new vscode.Diagnostic(
new vscode.Range(lineNumber, 0, lineNumber, currentIndent),
`Incorrect indentation. Expected ${expectedIndent}, got ${currentIndent}`,
vscode.DiagnosticSeverity.Warning
)
);
diagnostics.push({
line: lineNumber,
expectedIndent,
currentIndent
});
}

if ([
Expand Down

0 comments on commit 1a64ada

Please sign in to comment.