Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
#17 Added procedureTypes configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Krieg committed Jul 24, 2020
1 parent 7846c92 commit fe8b45b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 11 deletions.
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,40 @@
],
"description": "Specifies the accessibility level (scope) of the procedures to be exported as markdown."
},
"bdev-al-xml-doc.procedureTypes": {
"type": "array",
"items": {
"anyOf": [
{
"type": "string",
"enum": [
"Global Procedures",
"Local Procedures",
"Internal Procedures",
"Event Publisher",
"Event Subscriber",
"Trigger Procedures",
"Test Procedures"
],
"enumDescriptions": [
"Global procedures.",
"Local procedures.",
"Internal procedures.",
"Procedures with [BusinessEvent], [IntegrationEvent] or [InternalEvent] declaration.",
"Procedures with [EventSubscriber] declaration.",
"Trigger procedures (e.g. OnAfterGetRecord()).",
"Procedures in Test codeunits with [Test] declaration."
]
},
{
"type": "string"
}
]
},
"uniqueItems": true,
"description": "Sets the list of procedure types (e.g. event publisher, tests) checked.",
"scope": "resource"
},
"bdev-al-xml-doc.enableDocComments": {
"type": "boolean",
"scope": "resource",
Expand Down
10 changes: 9 additions & 1 deletion src/DoCheckDocumentation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { window, workspace, TextEditor, languages, commands, Position, SnippetString, TextDocument, Range } from "vscode";
import { ALCheckDocumentation } from "./util/ALCheckDocumentation";
import { ALFixDocumentation } from "./util/ALFixDocumentation";
import { VSCodeApi } from "./api/VSCodeApi";
import { ALDocCommentUtil } from "./util/ALDocCommentUtil";
import { ALSyntaxUtil } from "./util/ALSyntaxUtil";
import { Configuration } from "./util/Configuration";

export class DoCheckDocumentation {
private activeEditor!: TextEditor;
Expand Down Expand Up @@ -33,6 +33,14 @@ export class DoCheckDocumentation {
this.alUpdateDecorations.CheckDocumentation(this.activeEditor.document);
});

workspace.onDidChangeConfiguration(event => {
let affected = event.affectsConfiguration(Configuration.ExtensionIdent());
if (affected) {
Configuration.AskEnableCheckProcedureDocumentation();
this.InitializeCheckDocumentation();
}
});

languages.registerCodeActionsProvider('al',
new ALFixDocumentation(), {
providedCodeActionKinds: ALFixDocumentation.providedCodeActionKinds
Expand Down
2 changes: 1 addition & 1 deletion src/doComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class DoComment {
return code.trim();
}

if (ALSyntaxUtil.IsProcedure(line)) {
if (ALSyntaxUtil.IsProcedure(line, (i >= 0) ? this.vsCodeApi.ReadLine(i) : '')) {
this.codeType = CodeType.Procedure;
return code.trim();
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/ALDocCommentUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ALDocCommentUtil {
let line = alCode[lineNo];
switch (true) {
case ALSyntaxUtil.IsObject(line):
case ALSyntaxUtil.IsProcedure(line):
case ALSyntaxUtil.IsProcedure(line, (lineNo > 0) ? alCode[lineNo - 1] : ""):
case ALSyntaxUtil.IsBeginEnd(line):
return -1;
default:
Expand Down Expand Up @@ -99,7 +99,7 @@ export class ALDocCommentUtil {
let line = alCode[lineNo];
switch (true) {
case ALSyntaxUtil.IsObject(line):
case ALSyntaxUtil.IsProcedure(line):
case ALSyntaxUtil.IsProcedure(line, (lineNo > 0) ? alCode[lineNo - 1] : ""):
case ALSyntaxUtil.IsBeginEnd(line):
if (!isInsideDoc) {
return -1; // should never happen
Expand Down
2 changes: 1 addition & 1 deletion src/util/ALHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ALHoverProvider implements HoverProvider {
if (line.trim().startsWith('///')) {
docBuffer = `${line.replace('///','').trim()}\r\n${docBuffer}`;
}
if ((ALSyntaxUtil.IsProcedure(line)) || (ALSyntaxUtil.IsObject(line))) {
if ((ALSyntaxUtil.IsProcedure(line, (i > 0) ? alSourceCodeLines[i - 1] : "")) || (ALSyntaxUtil.IsObject(line))) {
break;
}
}
Expand Down
39 changes: 33 additions & 6 deletions src/util/ALSyntaxUtil.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isNullOrUndefined } from "util";
import { TextDocument, Range, Position } from "vscode";
import { Configuration } from "./Configuration";

export class ALSyntaxUtil {
public static IsObject(line: string): boolean {
Expand All @@ -22,28 +23,54 @@ export class ALSyntaxUtil {
return true;
}

public static IsProcedure(line: string): boolean {
public static IsProcedure(line: string, prevLine: string): boolean {
if (line === null) {
return false;
}

let procedureTypes = Configuration.ProcedureTypes();

const isEventPublisher: boolean = (prevLine.trim().startsWith('[BusinessEvent')) || (prevLine.trim().startsWith('[IntegrationEvent')) || (prevLine.trim().startsWith('[InternalEvent')) ;
if (isEventPublisher) {
if ((procedureTypes.length === 0) || (procedureTypes.includes('Event Publisher'))) {
return true;
}
return false;
}

const isEventSubscriber: boolean = prevLine.trim().startsWith('[EventSubscriber');
if (isEventSubscriber) {
if ((procedureTypes.length === 0) || (procedureTypes.includes('Event Subscriber'))) {
return true;
}
return false;
}

const isTestProcedure: boolean = prevLine.trim().startsWith('[Test');
if (isTestProcedure) {
if ((procedureTypes.length === 0) || (procedureTypes.includes('Test Procedures'))) {
return true;
}
return false;
}

const isProcedure: boolean = line.trim().startsWith('procedure');
if (isProcedure) {
if ((isProcedure) && ((procedureTypes.length === 0) || (procedureTypes.includes('Global Procedures')))) {
return true;
}

const isInternalProcedure: boolean = line.trim().startsWith('internal procedure');
if (isInternalProcedure) {
if ((isInternalProcedure) && ((procedureTypes.length === 0) || (procedureTypes.includes('Internal Procedures')))) {
return true;
}

const isLocalProcedure: boolean = line.trim().startsWith('local procedure');
if (isLocalProcedure) {
if ((isLocalProcedure) && ((procedureTypes.length === 0) || (procedureTypes.includes('Local Procedures')))) {
return true;
}

const isTriggerProcedure: boolean = line.trim().startsWith('trigger');
if (isTriggerProcedure) {
if ((isTriggerProcedure) && ((procedureTypes.length === 0) || (procedureTypes.includes('Trigger Procedures')))) {
return true;
}

Expand Down Expand Up @@ -71,7 +98,7 @@ export class ALSyntaxUtil {
let line = alCode[lineNo];
switch (true)
{
case ALSyntaxUtil.IsProcedure(line):
case ALSyntaxUtil.IsProcedure(line, (lineNo > 0) ? alCode[lineNo - 1] : ""):
if (alProcedureState !== null ){
return alProcedureState;
}
Expand Down
4 changes: 4 additions & 0 deletions src/util/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class Configuration {
return workspace.getConfiguration(this.ExtensionIdent()).checkProcedureDocumentation;
}

public static ProcedureTypes(): string[] {
return workspace.getConfiguration(this.ExtensionIdent()).procedureTypes;
}

public dispose() {
}
}

0 comments on commit fe8b45b

Please sign in to comment.