Skip to content

Improve client-side DFI workflow #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/commands/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const getCategory = (fileName: string, addCategory: any | boolean): strin
case "int":
case "inc":
case "mac":
case "dfi":
return fileExt;
default:
return "oth";
Expand All @@ -51,17 +52,26 @@ export const getFileName = (
const cat = addCategory ? getCategory(name, addCategory) : null;
return [folder, cat, ...nameArr].filter(notNull).join(path.sep);
} else {
// This is a class, routine or include file
if (map) {
for (const pattern of Object.keys(map)) {
if (new RegExp(`^${pattern}$`).test(name)) {
name = name.replace(new RegExp(`^${pattern}$`), map[pattern]);
break;
let fileNameArray: string[];
let fileExt: string;
if (/\.dfi$/i.test(name)) {
// This is a DFI file
fileNameArray = name.split("-");
fileNameArray.push(fileNameArray.pop().slice(0, -4));
fileExt = "dfi";
} else {
// This is a class, routine or include file
if (map) {
for (const pattern of Object.keys(map)) {
if (new RegExp(`^${pattern}$`).test(name)) {
name = name.replace(new RegExp(`^${pattern}$`), map[pattern]);
break;
}
}
}
fileNameArray = name.split(".");
fileExt = fileNameArray.pop().toLowerCase();
}
const fileNameArray: string[] = name.split(".");
const fileExt = fileNameArray.pop().toLowerCase();
const cat = addCategory ? getCategory(name, addCategory) : null;
if (split) {
const fileName = [folder, cat, ...fileNameArray].filter(notNull).join(path.sep);
Expand Down
47 changes: 41 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as url from "url";
import { exec } from "child_process";
import * as vscode from "vscode";
import { config, schemas, workspaceState, terminals } from "../extension";
import { getCategory } from "../commands/export";

let latestErrorMessage = "";
export const outputChannel: {
Expand Down Expand Up @@ -59,23 +60,57 @@ export interface ConnectionTarget {
* Determine the server name of a local non-ObjectScript file (any file that's not CLS,MAC,INT,INC).
* @param localPath The full path to the file on disk.
* @param workspace The workspace the file is in.
* @param fileExt The extension of the file.
*/
function getServerDocName(localPath: string, workspace: string): string {
function getServerDocName(localPath: string, workspace: string, fileExt: string): string {
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
const filePathNoWorkspaceArr = localPath.replace(workspacePath + path.sep, "").split(path.sep);
return filePathNoWorkspaceArr.slice(filePathNoWorkspaceArr.indexOf("csp")).join("/");
if (fileExt !== "dfi") {
return filePathNoWorkspaceArr.slice(filePathNoWorkspaceArr.indexOf("csp")).join("/");
}
const { atelier, folder, addCategory } = config("export", workspace);
const root = [
typeof folder === "string" && folder.length ? folder : null,
addCategory ? getCategory(localPath, addCategory) : null,
]
.filter(notNull)
.join(path.sep);
let filePath = filePathNoWorkspaceArr.join(path.sep).slice(root.length + path.sep.length);
if (atelier) {
filePath = filePath.replaceAll(path.sep, "-");
}
return filePath;
}

/**
* Determine if this non-InterSystems local file is importable
* (i.e. is part of a CSP application).
* Determine if this non-ObjectScript local file is importable
* (i.e. is part of a CSP application or is a DFI file).
* @param file The file to check.
*/
export function isImportableLocalFile(file: vscode.TextDocument): boolean {
const workspace = currentWorkspaceFolder(file);
const workspacePath = uriOfWorkspaceFolder(workspace).fsPath;
const filePathNoWorkspaceArr = file.fileName.replace(workspacePath + path.sep, "").split(path.sep);
return filePathNoWorkspaceArr.includes("csp");
if (filePathNoWorkspaceArr.includes("csp")) {
return true;
} else if (file.uri.path.toLowerCase().endsWith(".dfi")) {
// This is a DFI file, so make sure it matches our export settings
const { atelier, folder, addCategory } = config("export", workspace);
const expectedRoot = [
typeof folder === "string" && folder.length ? folder : null,
addCategory ? getCategory(file.fileName, addCategory) : null,
]
.filter(notNull)
.join(path.sep);
let filePath = filePathNoWorkspaceArr.join(path.sep);
if (filePath.startsWith(expectedRoot)) {
filePath = filePath.slice(expectedRoot.length + path.sep.length);
if ((atelier && !filePath.includes("-")) || !atelier) {
return true;
}
}
}
return false;
}

export function currentFile(document?: vscode.TextDocument): CurrentFile {
Expand Down Expand Up @@ -130,7 +165,7 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
// This is a csp or csr file that's not in a csp directory
return null;
}
name = getServerDocName(fileName, currentWorkspaceFolder(document));
name = getServerDocName(fileName, currentWorkspaceFolder(document), fileExt);
} else {
name = fileName;
}
Expand Down