Skip to content

Commit 3b3f715

Browse files
authored
Don't split dots in names of 'other' files into folders on export (intersystems-community#948)
1 parent 49e2d87 commit 3b3f715

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

docs/SettingsReference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The extensions in the InterSystems ObjectScript Extension Pack provide many sett
4343
| `"objectscript.debug.debugThisMethod"` | Show inline `Debug this method` CodeLens action for ClassMethods. | `boolean` | `true` | |
4444
| `"objectscript.explorer.alwaysShowServerCopy"` | Always show the server copy of a document in the ObjectScript Explorer. | `boolean` | `false` | |
4545
| `"objectscript.export.addCategory"` | Add a category folder to the beginning of the export path. | `boolean` or `object` | `false` | |
46-
| `"objectscript.export.atelier"` | Export source code as Atelier did it, with packages as subfolders. | `boolean` | `true` | |
46+
| `"objectscript.export.atelier"` | Export source code as Atelier did it, with packages as subfolders. | `boolean` | `true` | This setting only affects classes, routines, include files and DFI files. |
4747
| `"objectscript.export.category"` | Category of source code to export: `CLS` = classes; `RTN` = routines; `CSP` = csp files; `OTH` = other. Default is `*` = all. | `string` or `object` | `"*"` | |
4848
| `"objectscript.export.dontExportIfNoChanges"` | Do not rewrite the local file if the content is identical to what came from the server. | `boolean` | `false` | |
4949
| `"objectscript.export.exactFilter"` | SQL filter to limit what to export. | `string` | `""` | The filter is applied to document names using the [LIKE predicate](https://irisdocs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls?KEY=RSQL_like) (i.e. `Name LIKE 'exactFilter'`). If provided, `objectscript.export.filter` is ignored. |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@
11171117
"additionalProperties": false
11181118
},
11191119
"atelier": {
1120-
"description": "Export source code as Atelier did it, with packages as subfolders.",
1120+
"description": "Export source code as Atelier did it, with packages as subfolders. This setting only affects classes, routines, include files and DFI files.",
11211121
"type": "boolean"
11221122
},
11231123
"generated": {

src/commands/export.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const getFileName = (
5252
fileNameArray = name.split("-");
5353
fileNameArray.push(fileNameArray.pop().slice(0, -4));
5454
fileExt = "dfi";
55-
} else {
55+
} else if (/\.(?:cls|mac|int|inc)$/.test(name)) {
5656
// This is a class, routine or include file
5757
if (map) {
5858
for (const pattern of Object.keys(map)) {
@@ -64,6 +64,11 @@ export const getFileName = (
6464
}
6565
fileNameArray = name.split(".");
6666
fileExt = fileNameArray.pop().toLowerCase();
67+
} else {
68+
// This is some other type of file (LUT,HL7,...)
69+
const lastDot = name.lastIndexOf(".");
70+
fileNameArray = [name.slice(0, lastDot)];
71+
fileExt = name.slice(lastDot + 1);
6772
}
6873
const cat = addCategory ? getCategory(name, addCategory) : null;
6974
if (split) {

src/utils/index.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,40 @@ export function cspAppsForUri(uri: vscode.Uri): string[] {
8080
function getServerDocName(localPath: string, workspace: string, fileExt: string): string {
8181
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
8282
const filePathNoWorkspaceArr = localPath.replace(workspacePath + path.sep, "").split(path.sep);
83-
if (fileExt !== "dfi") {
84-
const uri = vscode.Uri.file(localPath);
85-
return uri.path.slice(uri.path.indexOf(cspAppsForUri(uri).find((cspApp) => uri.path.includes(cspApp + "/"))));
86-
}
87-
const { atelier, folder, addCategory } = config("export", workspace);
88-
const root = [
89-
typeof folder === "string" && folder.length ? folder : null,
90-
addCategory ? getCategory(localPath, addCategory) : null,
91-
]
92-
.filter(notNull)
93-
.join(path.sep);
94-
let filePath = filePathNoWorkspaceArr.join(path.sep).slice(root.length + path.sep.length);
95-
if (atelier) {
96-
filePath = filePath.replaceAll(path.sep, "-");
83+
const uri = vscode.Uri.file(localPath);
84+
const cspIdx = uri.path.indexOf(cspAppsForUri(uri).find((cspApp) => uri.path.includes(cspApp + "/")));
85+
if (cspIdx != -1) {
86+
return uri.path.slice(cspIdx);
87+
} else {
88+
const { atelier, folder, addCategory } = config("export", workspace);
89+
const root = [
90+
typeof folder === "string" && folder.length ? folder : null,
91+
addCategory ? getCategory(localPath, addCategory) : null,
92+
]
93+
.filter(notNull)
94+
.join(path.sep);
95+
let filePath = filePathNoWorkspaceArr.join(path.sep).slice(root.length + path.sep.length);
96+
if (fileExt == "dfi" && atelier) {
97+
filePath = filePath.replaceAll(path.sep, "-");
98+
}
99+
return filePath;
97100
}
98-
return filePath;
99101
}
100102

101103
/**
102104
* Determine if this non-ObjectScript local file is importable
103-
* (i.e. is part of a CSP application or is a DFI file).
105+
* (i.e. is part of a CSP application or matches our export settings).
104106
* @param file The file to check.
105107
*/
106108
export function isImportableLocalFile(file: vscode.TextDocument): boolean {
107109
const workspace = currentWorkspaceFolder(file);
108110
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
109111
const filePathNoWorkspaceArr = file.fileName.replace(workspacePath + path.sep, "").split(path.sep);
110-
if (file.uri.path.toLowerCase().endsWith(".dfi")) {
111-
// This is a DFI file, so make sure it matches our export settings
112+
const isCSP = cspAppsForUri(file.uri).findIndex((cspApp) => file.uri.path.includes(cspApp + "/")) != -1;
113+
if (isCSP) {
114+
return true;
115+
} else {
116+
// Check if this file matches our export settings
112117
const { atelier, folder, addCategory } = config("export", workspace);
113118
const expectedRoot = [
114119
typeof folder === "string" && folder.length ? folder : null,
@@ -119,14 +124,17 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
119124
let filePath = filePathNoWorkspaceArr.join(path.sep);
120125
if (filePath.startsWith(expectedRoot)) {
121126
filePath = filePath.slice(expectedRoot.length + path.sep.length);
122-
if ((atelier && !filePath.includes("-")) || !atelier) {
127+
if (file.uri.path.toLowerCase().endsWith(".dfi")) {
128+
// DFI files can be split using the atelier setting
129+
if ((atelier && !filePath.includes("-")) || !atelier) {
130+
return true;
131+
}
132+
} else {
123133
return true;
124134
}
125135
}
126-
} else {
127-
return cspAppsForUri(file.uri).findIndex((cspApp) => file.uri.path.includes(cspApp + "/")) != -1;
136+
return false;
128137
}
129-
return false;
130138
}
131139

132140
export function currentFileFromContent(fileName: string, content: string): CurrentFile {

0 commit comments

Comments
 (0)