Skip to content

Commit bbd00b1

Browse files
authored
Improve client-side DFI workflow (#808)
1 parent 1304722 commit bbd00b1

File tree

2 files changed

+59
-14
lines changed

2 files changed

+59
-14
lines changed

src/commands/export.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const getCategory = (fileName: string, addCategory: any | boolean): strin
2323
case "int":
2424
case "inc":
2525
case "mac":
26+
case "dfi":
2627
return fileExt;
2728
default:
2829
return "oth";
@@ -44,17 +45,26 @@ export const getFileName = (
4445
const cat = addCategory ? getCategory(name, addCategory) : null;
4546
return [folder, cat, ...nameArr].filter(notNull).join(path.sep);
4647
} else {
47-
// This is a class, routine or include file
48-
if (map) {
49-
for (const pattern of Object.keys(map)) {
50-
if (new RegExp(`^${pattern}$`).test(name)) {
51-
name = name.replace(new RegExp(`^${pattern}$`), map[pattern]);
52-
break;
48+
let fileNameArray: string[];
49+
let fileExt: string;
50+
if (/\.dfi$/i.test(name)) {
51+
// This is a DFI file
52+
fileNameArray = name.split("-");
53+
fileNameArray.push(fileNameArray.pop().slice(0, -4));
54+
fileExt = "dfi";
55+
} else {
56+
// This is a class, routine or include file
57+
if (map) {
58+
for (const pattern of Object.keys(map)) {
59+
if (new RegExp(`^${pattern}$`).test(name)) {
60+
name = name.replace(new RegExp(`^${pattern}$`), map[pattern]);
61+
break;
62+
}
5363
}
5464
}
65+
fileNameArray = name.split(".");
66+
fileExt = fileNameArray.pop().toLowerCase();
5567
}
56-
const fileNameArray: string[] = name.split(".");
57-
const fileExt = fileNameArray.pop().toLowerCase();
5868
const cat = addCategory ? getCategory(name, addCategory) : null;
5969
if (split) {
6070
const fileName = [folder, cat, ...fileNameArray].filter(notNull).join(path.sep);

src/utils/index.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as url from "url";
55
import { exec } from "child_process";
66
import * as vscode from "vscode";
77
import { config, schemas, workspaceState, terminals } from "../extension";
8+
import { getCategory } from "../commands/export";
89

910
let latestErrorMessage = "";
1011
export const outputChannel: {
@@ -59,23 +60,57 @@ export interface ConnectionTarget {
5960
* Determine the server name of a local non-ObjectScript file (any file that's not CLS,MAC,INT,INC).
6061
* @param localPath The full path to the file on disk.
6162
* @param workspace The workspace the file is in.
63+
* @param fileExt The extension of the file.
6264
*/
63-
function getServerDocName(localPath: string, workspace: string): string {
65+
function getServerDocName(localPath: string, workspace: string, fileExt: string): string {
6466
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
6567
const filePathNoWorkspaceArr = localPath.replace(workspacePath + path.sep, "").split(path.sep);
66-
return filePathNoWorkspaceArr.slice(filePathNoWorkspaceArr.indexOf("csp")).join("/");
68+
if (fileExt !== "dfi") {
69+
return filePathNoWorkspaceArr.slice(filePathNoWorkspaceArr.indexOf("csp")).join("/");
70+
}
71+
const { atelier, folder, addCategory } = config("export", workspace);
72+
const root = [
73+
typeof folder === "string" && folder.length ? folder : null,
74+
addCategory ? getCategory(localPath, addCategory) : null,
75+
]
76+
.filter(notNull)
77+
.join(path.sep);
78+
let filePath = filePathNoWorkspaceArr.join(path.sep).slice(root.length + path.sep.length);
79+
if (atelier) {
80+
filePath = filePath.replaceAll(path.sep, "-");
81+
}
82+
return filePath;
6783
}
6884

6985
/**
70-
* Determine if this non-InterSystems local file is importable
71-
* (i.e. is part of a CSP application).
86+
* Determine if this non-ObjectScript local file is importable
87+
* (i.e. is part of a CSP application or is a DFI file).
7288
* @param file The file to check.
7389
*/
7490
export function isImportableLocalFile(file: vscode.TextDocument): boolean {
7591
const workspace = currentWorkspaceFolder(file);
7692
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
7793
const filePathNoWorkspaceArr = file.fileName.replace(workspacePath + path.sep, "").split(path.sep);
78-
return filePathNoWorkspaceArr.includes("csp");
94+
if (filePathNoWorkspaceArr.includes("csp")) {
95+
return true;
96+
} else if (file.uri.path.toLowerCase().endsWith(".dfi")) {
97+
// This is a DFI file, so make sure it matches our export settings
98+
const { atelier, folder, addCategory } = config("export", workspace);
99+
const expectedRoot = [
100+
typeof folder === "string" && folder.length ? folder : null,
101+
addCategory ? getCategory(file.fileName, addCategory) : null,
102+
]
103+
.filter(notNull)
104+
.join(path.sep);
105+
let filePath = filePathNoWorkspaceArr.join(path.sep);
106+
if (filePath.startsWith(expectedRoot)) {
107+
filePath = filePath.slice(expectedRoot.length + path.sep.length);
108+
if ((atelier && !filePath.includes("-")) || !atelier) {
109+
return true;
110+
}
111+
}
112+
}
113+
return false;
79114
}
80115

81116
export function currentFile(document?: vscode.TextDocument): CurrentFile {
@@ -130,7 +165,7 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
130165
// This is a csp or csr file that's not in a csp directory
131166
return null;
132167
}
133-
name = getServerDocName(fileName, currentWorkspaceFolder(document));
168+
name = getServerDocName(fileName, currentWorkspaceFolder(document), fileExt);
134169
} else {
135170
name = fileName;
136171
}

0 commit comments

Comments
 (0)