@@ -5,6 +5,7 @@ import * as url from "url";
55import { exec } from "child_process" ;
66import * as vscode from "vscode" ;
77import { config , schemas , workspaceState , terminals } from "../extension" ;
8+ import { getCategory } from "../commands/export" ;
89
910let latestErrorMessage = "" ;
1011export 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 */
7490export 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
81116export 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