@@ -4,8 +4,9 @@ import { R_OK } from "constants";
44import * as url from "url" ;
55import { exec } from "child_process" ;
66import * as vscode from "vscode" ;
7- import { config , schemas , workspaceState , terminals , extensionContext } from "../extension" ;
7+ import { config , schemas , workspaceState , terminals , extensionContext , cspApps } from "../extension" ;
88import { getCategory } from "../commands/export" ;
9+ import { AtelierAPI } from "../api" ;
910
1011let latestErrorMessage = "" ;
1112export const outputChannel : {
@@ -56,6 +57,19 @@ export interface ConnectionTarget {
5657 configName : string ;
5758}
5859
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+
5973/**
6074 * Determine the server name of a local non-ObjectScript file (any file that's not CLS,MAC,INT,INC).
6175 * @param localPath The full path to the file on disk.
@@ -66,7 +80,8 @@ function getServerDocName(localPath: string, workspace: string, fileExt: string)
6680 const workspacePath = uriOfWorkspaceFolder ( workspace ) . fsPath ;
6781 const filePathNoWorkspaceArr = localPath . replace ( workspacePath + path . sep , "" ) . split ( path . sep ) ;
6882 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 + "/" ) ) ) ) ;
7085 }
7186 const { atelier, folder, addCategory } = config ( "export" , workspace ) ;
7287 const root = [
@@ -91,9 +106,7 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
91106 const workspace = currentWorkspaceFolder ( file ) ;
92107 const workspacePath = uriOfWorkspaceFolder ( workspace ) . fsPath ;
93108 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" ) ) {
97110 // This is a DFI file, so make sure it matches our export settings
98111 const { atelier, folder, addCategory } = config ( "export" , workspace ) ;
99112 const expectedRoot = [
@@ -109,6 +122,8 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
109122 return true ;
110123 }
111124 }
125+ } else {
126+ return cspAppsForUri ( file . uri ) . findIndex ( ( cspApp ) => file . uri . path . includes ( cspApp + "/" ) ) != - 1 ;
112127 }
113128 return false ;
114129}
0 commit comments