Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/xml2js-and-azure/c…
Browse files Browse the repository at this point in the history
…ore-http-0.5.0
  • Loading branch information
waldo1001 committed Oct 20, 2023
2 parents d0f386e + b715b60 commit e21ece4
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
@@ -1,6 +1,6 @@
# Change Log
All notable changes to the "crs-al-language-extension" extension:
## [1.5.26] - 2023-07-12
## [1.5.28] - 2023-07-12
Fix from [James Pearson](https://github.com/jimmymcp): pull request [#282 - Do not add quotes to object names if not necessary when reorganising](https://github.com/waldo1001/crs-al-language-extension/pull/282/files) - thanks!

## [1.5.25] - 2023-01-20
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -221,7 +221,7 @@ tableextension 50100 "Just Some Table Extension" extends Customer //18
* `DisableWaldoSnippets`: Disables the CRS snippets that come with this extension. When you change the setting, you need to restart VSCode twice. Once for disabling the snippets on activation (at that time, the snippets are still loaded). And the second time to actually not load the snippets anymore.
* `SkipWarningMessageOnRenameAll`: Skips the Warning when renaming all files which can disturb custom VS tasks.
* `RenameWithGit`: Use 'git mv' to rename a file. This keeps history of the file, but stages the rename, which you should commit separately. **The feature is still in preview-mode, therefore the default value is 'false'**

* `ReorganizeByNamespace`: This is a feature that allows for the automatic reorganization of files by creating folder structures based on the namespaces defined within the files. **The feature is still in preview-mode, therefore the default value is 'false'**
## Skip String manipulation

You can skip string manipulation by adding comments to your code:
Expand Down
17 changes: 8 additions & 9 deletions package-lock.json

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

8 changes: 7 additions & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "crs-al-language-extension",
"displayName": "waldo's CRS AL Language Extension",
"description": "Make working with the (Dynamics NAV / 365) AL Language easier and more efficient.",
"version": "1.5.26",
"version": "1.5.28",
"publisher": "waldo",
"icon": "images/waldo.png",
"author": {
Expand Down Expand Up @@ -267,6 +267,12 @@
"description": "Use 'git mv' to rename a file. This keeps history of the file, but stages the rename, which you should commit separately. The feature is still in preview-mode, therefore the default value is 'false'",
"scope": "resource"
},
"CRS.ReorganizeByNamespace": {
"type": "boolean",
"default": false,
"description": "This is a feature that allows for the automatic reorganization of files by creating folder structures based on the namespaces defined within the files. The feature is still in preview-mode, therefore the default value is 'false'",
"scope": "resource"
},
"CRS.SearchObjectNamesRegexPattern": {
"type": "string",
"default": "^\\w+ (\\d* )?\"*",
Expand Down
8 changes: 7 additions & 1 deletion src/NAVObject.ts
Expand Up @@ -8,6 +8,7 @@ export class NAVObject {
public objectType: string;
public objectId: string;
public objectName: string;
public objectNamespace: string;
public objectActions: NAVObjectAction[] = new Array();
public tableFields: NAVTableField[] = new Array();
public pageFields: NAVPageField[] = new Array();
Expand Down Expand Up @@ -155,6 +156,7 @@ export class NAVObject {
this.objectType = '';
this.objectId = '';
this.objectName = '';
this.objectNamespace = '';
this.extendedObjectName = '';
this.extendedObjectId = '';
var ObjectNamePattern = '"[^"]*"' // All characters except "
Expand Down Expand Up @@ -273,7 +275,11 @@ export class NAVObject {
return null
}
}

var patternObject = new RegExp('namespace\\s+([A-Za-z0-9_.]+?)\\s*;', "i");
var match = this.NAVObjectText.match(patternObject);
if (match && match[1]) {
this.objectNamespace = match[1];
}
this.objectType = this.objectType.trim().toString();
this.objectId = this.objectId.trim().toString();
this.objectName = this.objectName.trim().toString().replace(/["]/g, '');
Expand Down
2 changes: 2 additions & 0 deletions src/Settings.ts
Expand Up @@ -34,6 +34,7 @@ export class Settings {
static readonly DisableDefaultAlSnippets = 'DisableDefaultAlSnippets';
static readonly DisableCRSSnippets = 'DisableCRSSnippets';
static readonly RenameWithGit = 'RenameWithGit';
static readonly ReorganizeByNamespace = 'ReorganizeByNamespace';
static readonly Browser = 'browser';
static readonly Incognito = 'incognito';
static readonly packageCachePath = 'packageCachePath';
Expand Down Expand Up @@ -100,6 +101,7 @@ export class Settings {
this.SettingCollection[this.DisableCRSSnippets] = this.getSetting(this.DisableCRSSnippets);
this.SettingCollection[this.PublicWebBaseUrl] = this.getSetting(this.PublicWebBaseUrl);
this.SettingCollection[this.RenameWithGit] = this.getSetting(this.RenameWithGit);
this.SettingCollection[this.ReorganizeByNamespace] = this.getSetting(this.ReorganizeByNamespace);
this.SettingCollection[this.SearchObjectNamesRegexPattern] = this.getSetting(this.SearchObjectNamesRegexPattern);
this.SettingCollection[this.DependencyGraphIncludeTestApps] = this.getSetting(this.DependencyGraphIncludeTestApps);
this.SettingCollection[this.DependencyGraphExcludeAppNames] = this.getSetting(this.DependencyGraphExcludeAppNames);
Expand Down
31 changes: 26 additions & 5 deletions src/WorkspaceFiles.ts
Expand Up @@ -88,7 +88,7 @@ export class WorkspaceFiles {
if (navObject.objectFileName && navObject.objectFileName != '' && fixedname && fixedname != '') {

let objectFolder = path.join(vscode.workspace.getWorkspaceFolder(fileName).uri.fsPath, this.getDestinationFolder(navObject, settings));
let objectTypeFolder = path.join(objectFolder, this.getObjectTypeFolder(navObject));
let objectTypeFolder = path.join(objectFolder, this.getObjectTypeFolder(navObject, settings));//Boe
let objectSubFolder = path.join(objectTypeFolder, this.getObjectSubFolder(navObject));
let destinationFileName = path.join(objectSubFolder, fixedname);

Expand All @@ -97,9 +97,10 @@ export class WorkspaceFiles {
return fileName.fsPath;
} else {

(!fs.existsSync(objectFolder)) ? fs.mkdirSync(objectFolder) : '';
(!fs.existsSync(objectTypeFolder)) ? fs.mkdirSync(objectTypeFolder) : '';
(!fs.existsSync(objectSubFolder)) ? fs.mkdirSync(objectSubFolder) : '';
//(!fs.existsSync(objectFolder)) ? fs.mkdirSync(objectFolder) : '';
//(!fs.existsSync(objectTypeFolder)) ? fs.mkdirSync(objectTypeFolder) : '';
//(!fs.existsSync(objectSubFolder)) ? fs.mkdirSync(objectSubFolder) : '';
this.createDirectoryIfNotExists(objectSubFolder);

withGit = withGit ? withGit : (git.isGitRepositorySync() && settings[Settings.RenameWithGit])
this.DoRenameFile(fileName, destinationFileName, withGit)
Expand Down Expand Up @@ -308,13 +309,19 @@ export class WorkspaceFiles {
return mySettings[Settings.AlSubFolderName]
}

static getObjectTypeFolder(navObject: NAVObject): string {
static getObjectTypeFolder(navObject: NAVObject, mySettings: any): string {
if (navObject.objectCodeunitSubType) {
if (navObject.objectCodeunitSubType.toLowerCase() == 'test') {
return ''
}
}

if (mySettings[Settings.ReorganizeByNamespace])
{
let directoryPath = path.join(...navObject.objectNamespace.split("."))
return directoryPath
}

return navObject.objectType
}

Expand All @@ -326,6 +333,20 @@ export class WorkspaceFiles {
return "";
}

static createDirectoryIfNotExists(dir) {
const segments = dir.split(path.sep);
let currentPath = segments[0];

for (let i = 1; i < segments.length; i++) {
if (segments[i]) {
currentPath = path.join(currentPath, segments[i]);
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath);
}
}
}
}

static async CreateGraphVizDependencyGraph() {
crsOutput.showOutput(`Creating dependency graph (GraphViz) from apps in this workspace`, true);

Expand Down
21 changes: 21 additions & 0 deletions src/test/suite/NAVTestObjectLibrary.ts
Expand Up @@ -113,6 +113,27 @@ export function getNormalCodeunitWithLongName(): NAVTestObject {
return object;
}

export function getNormalCodeunitWithNamespace(): NAVTestObject {
let object = new NAVTestObject;

object.ObjectFileName = 'Cod50100.justAName.al'
object.ObjectText = `
namespace spycoclown.test;
using Microsoft.Inventory.Item;
codeunit 50100 "Test Overload"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::LogInManagement, 'OnAfterLogInStart', '', false, false)]
local procedure TestOverLoad()
var
Item: Record Item;
begin
item.CalculateClassification(true, 'namespace');
end;
}
`
return object;
}

export function getTestCodeunit(): NAVTestObject {
let object = new NAVTestObject;

Expand Down
15 changes: 13 additions & 2 deletions src/test/suite/WorkspaceFiles.test.ts
Expand Up @@ -34,7 +34,7 @@ suite("WorkspaceFiles Tests", () => {
let navTestObject = NAVTestObjectLibrary.getTestCodeunit();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName);

let foldersuggestion = WorkspaceFiles.getObjectTypeFolder(navObject);
let foldersuggestion = WorkspaceFiles.getObjectTypeFolder(navObject,testSettings);

assert.strictEqual(foldersuggestion.toLowerCase(), '');
})
Expand All @@ -44,9 +44,20 @@ suite("WorkspaceFiles Tests", () => {
let navTestObject = NAVTestObjectLibrary.getNormalCodeunitWithLongName();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName);

let foldersuggestion = WorkspaceFiles.getObjectTypeFolder(navObject);
let foldersuggestion = WorkspaceFiles.getObjectTypeFolder(navObject,testSettings);

assert.strictEqual(foldersuggestion.toLowerCase().toString(), navObject.objectType.toString());
assert.notStrictEqual(foldersuggestion.toLowerCase().toString(), '');
})
test("getObjectTypeFolder - return namespace", () => {
let testSettings = Settings.GetConfigSettings(null);
testSettings[Settings.ReorganizeByNamespace] = true;
let navTestObject = NAVTestObjectLibrary.getNormalCodeunitWithNamespace();
let navObject = new NAVObject(navTestObject.ObjectText, testSettings, navTestObject.ObjectFileName);

let foldersuggestion = WorkspaceFiles.getObjectTypeFolder(navObject,testSettings);

assert.notStrictEqual(foldersuggestion.toLowerCase().toString(), navObject.objectNamespace.toLowerCase().toString());
assert.strictEqual(foldersuggestion.toLowerCase().toString(), 'spycoclown\\test');
})
})
4 changes: 2 additions & 2 deletions yarn.lock
Expand Up @@ -1429,8 +1429,8 @@ which@2.0.2, which@^2.0.1:
isexe "^2.0.0"

word-wrap@^1.2.3:
version "1.2.3"
resolved "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz"
version "1.2.4"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f"

workerpool@6.2.0:
version "6.2.0"
Expand Down

0 comments on commit e21ece4

Please sign in to comment.