@@ -5,6 +5,7 @@ import * as url from "url";
5
5
import { exec } from "child_process" ;
6
6
import * as vscode from "vscode" ;
7
7
import { config , schemas , workspaceState , terminals } from "../extension" ;
8
+ import { getCategory } from "../commands/export" ;
8
9
9
10
let latestErrorMessage = "" ;
10
11
export const outputChannel : {
@@ -59,23 +60,57 @@ export interface ConnectionTarget {
59
60
* Determine the server name of a local non-ObjectScript file (any file that's not CLS,MAC,INT,INC).
60
61
* @param localPath The full path to the file on disk.
61
62
* @param workspace The workspace the file is in.
63
+ * @param fileExt The extension of the file.
62
64
*/
63
- function getServerDocName ( localPath : string , workspace : string ) : string {
65
+ function getServerDocName ( localPath : string , workspace : string , fileExt : string ) : string {
64
66
const workspacePath = uriOfWorkspaceFolder ( workspace ) . fsPath ;
65
67
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 ;
67
83
}
68
84
69
85
/**
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 ).
72
88
* @param file The file to check.
73
89
*/
74
90
export function isImportableLocalFile ( file : vscode . TextDocument ) : boolean {
75
91
const workspace = currentWorkspaceFolder ( file ) ;
76
92
const workspacePath = uriOfWorkspaceFolder ( workspace ) . fsPath ;
77
93
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 ;
79
114
}
80
115
81
116
export function currentFile ( document ?: vscode . TextDocument ) : CurrentFile {
@@ -130,7 +165,7 @@ export function currentFile(document?: vscode.TextDocument): CurrentFile {
130
165
// This is a csp or csr file that's not in a csp directory
131
166
return null ;
132
167
}
133
- name = getServerDocName ( fileName , currentWorkspaceFolder ( document ) ) ;
168
+ name = getServerDocName ( fileName , currentWorkspaceFolder ( document ) , fileExt ) ;
134
169
} else {
135
170
name = fileName ;
136
171
}
0 commit comments