Skip to content

Commit 3b64742

Browse files
authored
Merge pull request #36 from daimor/explorer
Explorer view
2 parents 3004410 + 37dd9a8 commit 3b64742

39 files changed

+1360
-630
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ root = true
44
[*]
55
charset = utf-8
66
indent_style = space
7-
indent_size = 4
7+
indent_size = 2
88
end_of_line = lf
99
insert_final_newline = true
1010
trim_trailing_whitespace = true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
.idea
33
*.iml
4-
.vscode/**
4+
.vscode/**
5+
out

.vscode/launch.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"type": "extensionHost",
88
"request": "launch",
99
"runtimeExecutable": "${execPath}",
10-
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ]
10+
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11+
"stopOnEntry": false,
12+
"sourceMaps": true,
13+
"outFiles": ["${workspaceRoot}/out/**/*.js"],
14+
"preLaunchTask": "npm"
1115
}
1216
]
13-
}
17+
}

.vscode/tasks.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Available variables which can be used inside of strings.
2+
// ${workspaceRoot}: the root folder of the team
3+
// ${file}: the current opened file
4+
// ${fileBasename}: the current opened file's basename
5+
// ${fileDirname}: the current opened file's dirname
6+
// ${fileExtname}: the current opened file's extension
7+
// ${cwd}: the current working directory of the spawned process
8+
9+
// A task runner that calls a custom npm script that compiles the extension.
10+
{
11+
"version": "0.1.0",
12+
13+
// we want to run npm
14+
"command": "npm",
15+
16+
// the command is a shell script
17+
"isShellCommand": true,
18+
19+
// show the output window only if unrecognized errors occur.
20+
"showOutput": "silent",
21+
22+
// we run the custom script "compile" as defined in package.json
23+
"args": ["run", "compile"],
24+
25+
// The tsc compiler is started in watching mode
26+
"isBackground": true,
27+
28+
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29+
"problemMatcher": "$tsc-watch"
30+
}

commands/currentdoc/cls-check-names.js

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// is name correlate with code ?
2+
// if ( atelier ) {
3+
// testClass({ code: 'test.class.cls', file: 'class.cls' })
4+
// } else {
5+
// testClass({ code: 'test.class.cls', file: 'test.class.cls' })
6+
//}
7+
module.exports = ({ code, file, log = data => console.log(data) }) => {
8+
const arr = code.split(".").filter(s => !!s); // drop empty parts
9+
10+
if (arr.length < 3) {
11+
// without package
12+
log(
13+
`Unable to detect class.name in ${file}. Is it a valid ObjectScript class?`
14+
);
15+
return false;
16+
}
17+
18+
// NOTE: by default, we can use package 'User'
19+
// else if ( parts.length === 2 ){
20+
// arr.unshift( 'User' ) //package by default
21+
// or parse 'import' directive ;)
22+
//}
23+
24+
// is codename contain filename
25+
if (code.toLowerCase().includes(file.toLowerCase())) return true;
26+
// else
27+
log(`'${code}' defined in '${file}'. Rename the file or class`);
28+
return false;
29+
};

commands/currentdoc/cls-regex-name.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

commands/currentdoc/cls-regex-name.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Caché class files can be placed hierarchically (e.g. /src/Package/Class.cls),
2+
// so we pick the class name from the class definition itself
3+
const pattern = /Class ([^\s]+)/i; //'Class test.class'
4+
5+
module.exports = code => {
6+
const arr = code.match(pattern) || []; // ['Class test.class', 'test.class']
7+
const name = arr[1] || "",
8+
ext = "cls";
9+
return { name, ext }; // test.class.cls
10+
};

commands/currentdoc/index.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

commands/currentdoc/index.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Import and compile current file.
3+
*/
4+
const clsRegexName = require("./cls-regex-name");
5+
const clsCheckNames = require("./cls-check-names");
6+
const rtnRegexName = require("./rtn-regex-name");
7+
const rtnCheckNames = require("./rtn-check-names");
8+
9+
// extract and verify name of active document
10+
// env - environment { window, languages, log }
11+
// return { name, content, error }
12+
const CurrentDoc = env => () => {
13+
/*
14+
env ={
15+
window = {},
16+
languages = [ 'cacheobjectscript', 'cacheobjectscriptinclude' ],
17+
log = data => console.log( 'cos.compile:', JSON.stringify( data ) )
18+
}
19+
*/
20+
const { window, languages, log } = env;
21+
const editor = window.activeTextEditor;
22+
if (!editor)
23+
return {
24+
error: "No active editor, open one at first"
25+
};
26+
27+
const doc = editor.document;
28+
if (!doc)
29+
return {
30+
error: "Open ObjectScript file first."
31+
};
32+
33+
const fullname = doc.fileName;
34+
if (!fullname)
35+
return {
36+
error: "You must save the document first"
37+
};
38+
39+
if (!languages.includes(doc.languageId))
40+
return {
41+
error: `${fullname} has unsupported type ${doc.languageId}`
42+
};
43+
44+
let file = (fullname.match(/[^\\\/]+$/) || [])[0] || ""; //only filename without folders
45+
let code = doc.getText();
46+
let ncode = code.replace(/\/\/[^\r\n]*\r?\n/g, ""); // normalize EOL?
47+
let name, ext, codename; //server side name
48+
49+
const cdnm = ({ name, ext }) => [name, ext].join(".");
50+
51+
if (/\.cls$/i.test(fullname)) {
52+
// is class?
53+
54+
({ name, ext } = clsRegexName(ncode));
55+
codename = cdnm({ name, ext });
56+
if (!clsCheckNames({ code: codename, file, log }))
57+
return {
58+
error: "check names"
59+
};
60+
} else {
61+
// routines
62+
63+
({ name, ext } = rtnRegexName(ncode));
64+
codename = cdnm({ name, ext });
65+
if (!rtnCheckNames({ code: codename, file, log }))
66+
return {
67+
error: "check names"
68+
};
69+
}
70+
71+
return {
72+
name: codename,
73+
content: code.split(/\r?\n/g), // get code lines array
74+
error: "",
75+
fileName: fullname
76+
};
77+
};
78+
79+
module.exports = { CurrentDoc };

commands/currentdoc/rtn-check-names.js renamed to commands/currentdoc/rtn-check-names.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,31 @@
55
// testClass({ codename: 'test.rtn.mac', file: 'test.rtn.mac' })
66
//}
77
module.exports = ({ code, file, log }) => {
8-
9-
if ( !code ){
10-
11-
log(
12-
13-
`Unable to detect routine name in source code of ${ file }.
8+
if (!code) {
9+
log(
10+
`Unable to detect routine name in source code of ${file}.
1411
Routine code example:
1512
1613
ROUTINE RtnName [Type=MAC]
1714
w "routine code here"
1815
Quit
1916
`
20-
)
21-
return false
22-
23-
}
24-
25-
if ( !~code.toLowerCase().indexOf( file.toLowerCase() ) ) {
17+
);
18+
return false;
19+
}
2620

27-
log(
28-
`You tried to compile '${ code }' in file '${ file }'
21+
if (!code.toLowerCase().includes(file.toLowerCase())) {
22+
log(
23+
`You tried to compile '${code}' in file '${file}'
2924
Rename the file or routine to correspond to each other.
30-
Routine code example:
25+
Routine code example:
3126
3227
ROUTINE RtnName [Type=MAC]
3328
write "routine code here"
3429
Quit`
35-
)
36-
return false
37-
38-
}
39-
40-
return true
30+
);
31+
return false;
32+
}
4133

42-
}
34+
return true;
35+
};

commands/export/doc-to-file-as-atelier.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { sep } from "path";
2+
//for example: 'mypkg.subpkg.myclass.cls'
3+
// return 'mypkg/subpkg/'
4+
module.exports = docname => {
5+
const parts = docname.split("."); // [ 'mypkg', 'subpkg', 'myclass', 'cls' ]
6+
const packagesEnd = parts.length - 2; // name and extension
7+
return [
8+
parts.slice(0, packagesEnd).join(sep), // packages to subfolders
9+
parts.slice(packagesEnd).join(".")
10+
].join(sep);
11+
};

0 commit comments

Comments
 (0)