@@ -4,8 +4,9 @@ import { R_OK } from "constants";
4
4
import * as url from "url" ;
5
5
import { exec } from "child_process" ;
6
6
import * as vscode from "vscode" ;
7
- import { config , schemas , workspaceState , terminals , extensionContext } from "../extension" ;
7
+ import { config , schemas , workspaceState , terminals , extensionContext , cspApps } from "../extension" ;
8
8
import { getCategory } from "../commands/export" ;
9
+ import { AtelierAPI } from "../api" ;
9
10
10
11
let latestErrorMessage = "" ;
11
12
export const outputChannel : {
@@ -56,6 +57,19 @@ export interface ConnectionTarget {
56
57
configName : string ;
57
58
}
58
59
60
+ /**
61
+ * Get a list of all CSP web apps in the server-namespace that `uri` is connected to.
62
+ */
63
+ export function cspAppsForUri ( uri : vscode . Uri ) : string [ ] {
64
+ const api = new AtelierAPI ( uri ) ;
65
+ const key = (
66
+ api . config . serverName && api . config . serverName != ""
67
+ ? `${ api . config . serverName } :${ api . config . ns } `
68
+ : `${ api . config . host } :${ api . config . port } ${ api . config . pathPrefix } :${ api . config . ns } `
69
+ ) . toLowerCase ( ) ;
70
+ return cspApps . get ( key ) ?? [ ] ;
71
+ }
72
+
59
73
/**
60
74
* Determine the server name of a local non-ObjectScript file (any file that's not CLS,MAC,INT,INC).
61
75
* @param localPath The full path to the file on disk.
@@ -66,7 +80,8 @@ function getServerDocName(localPath: string, workspace: string, fileExt: string)
66
80
const workspacePath = uriOfWorkspaceFolder ( workspace ) . fsPath ;
67
81
const filePathNoWorkspaceArr = localPath . replace ( workspacePath + path . sep , "" ) . split ( path . sep ) ;
68
82
if ( fileExt !== "dfi" ) {
69
- return filePathNoWorkspaceArr . slice ( filePathNoWorkspaceArr . indexOf ( "csp" ) ) . join ( "/" ) ;
83
+ const uri = vscode . Uri . file ( localPath ) ;
84
+ return uri . path . slice ( uri . path . indexOf ( cspAppsForUri ( uri ) . find ( ( cspApp ) => uri . path . includes ( cspApp + "/" ) ) ) ) ;
70
85
}
71
86
const { atelier, folder, addCategory } = config ( "export" , workspace ) ;
72
87
const root = [
@@ -91,9 +106,7 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
91
106
const workspace = currentWorkspaceFolder ( file ) ;
92
107
const workspacePath = uriOfWorkspaceFolder ( workspace ) . fsPath ;
93
108
const filePathNoWorkspaceArr = file . fileName . replace ( workspacePath + path . sep , "" ) . split ( path . sep ) ;
94
- if ( filePathNoWorkspaceArr . includes ( "csp" ) ) {
95
- return true ;
96
- } else if ( file . uri . path . toLowerCase ( ) . endsWith ( ".dfi" ) ) {
109
+ if ( file . uri . path . toLowerCase ( ) . endsWith ( ".dfi" ) ) {
97
110
// This is a DFI file, so make sure it matches our export settings
98
111
const { atelier, folder, addCategory } = config ( "export" , workspace ) ;
99
112
const expectedRoot = [
@@ -109,6 +122,8 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
109
122
return true ;
110
123
}
111
124
}
125
+ } else {
126
+ return cspAppsForUri ( file . uri ) . findIndex ( ( cspApp ) => file . uri . path . includes ( cspApp + "/" ) ) != - 1 ;
112
127
}
113
128
return false ;
114
129
}
0 commit comments