@@ -4,8 +4,15 @@ import {
44 fromConfigFile ,
55 ScimService ,
66} from "@databricks/databricks-sdk" ;
7- import { commands , EventEmitter , window , workspace } from "vscode" ;
7+ import {
8+ commands ,
9+ EventEmitter ,
10+ Uri ,
11+ window ,
12+ workspace as vscodeWorkspace ,
13+ } from "vscode" ;
814import { CliWrapper } from "../cli/CliWrapper" ;
15+ import { PathMapper } from "./PathMapper" ;
916import { ProjectConfigFile } from "./ProjectConfigFile" ;
1017import { selectProfile } from "./selectProfileWizard" ;
1118
@@ -21,6 +28,7 @@ export class ConnectionManager {
2128 private _state : ConnectionState = "DISCONNECTED" ;
2229 private _cluster ?: Cluster ;
2330 private _apiClient ?: ApiClient ;
31+ private _pathMapper ?: PathMapper ;
2432 private _projectConfigFile ?: ProjectConfigFile ;
2533 private _me ?: string ;
2634 private _profile ?: string ;
@@ -47,6 +55,10 @@ export class ConnectionManager {
4755 return this . _state ;
4856 }
4957
58+ get pathMapper ( ) : PathMapper | undefined {
59+ return this . _pathMapper ;
60+ }
61+
5062 /**
5163 * Get a pre-configured APIClient. Do not hold on to references to this class as
5264 * it might be invalidated as the configuration changes. If you have to store a reference
@@ -64,14 +76,14 @@ export class ConnectionManager {
6476 let profile ;
6577
6678 try {
67- if ( ! workspace . rootPath ) {
79+ if ( ! vscodeWorkspace . rootPath ) {
6880 throw new Error (
6981 "Can't login to Databricks: Not in a VSCode workspace"
7082 ) ;
7183 }
7284
7385 projectConfigFile = await ProjectConfigFile . load (
74- workspace . rootPath
86+ vscodeWorkspace . rootPath
7587 ) ;
7688
7789 profile = projectConfigFile . config . profile ;
@@ -106,6 +118,12 @@ export class ConnectionManager {
106118 if ( projectConfigFile . config . clusterId ) {
107119 await this . attachCluster ( projectConfigFile . config . clusterId ) ;
108120 }
121+
122+ if ( projectConfigFile . config . workspacePath ) {
123+ await this . attachWorkspace (
124+ Uri . file ( projectConfigFile . config . workspacePath )
125+ ) ;
126+ }
109127 }
110128
111129 async logout ( ) {
@@ -167,17 +185,20 @@ export class ConnectionManager {
167185 }
168186
169187 private async writeConfigFile ( profile : string ) {
170- if ( ! workspace . rootPath ) {
188+ if ( ! vscodeWorkspace . rootPath ) {
171189 throw new Error ( "Not in a VSCode workspace" ) ;
172190 }
173191
174192 let projectConfigFile ;
175193 try {
176194 projectConfigFile = await ProjectConfigFile . load (
177- workspace . rootPath
195+ vscodeWorkspace . rootPath
178196 ) ;
179197 } catch ( e ) {
180- projectConfigFile = new ProjectConfigFile ( { } , workspace . rootPath ) ;
198+ projectConfigFile = new ProjectConfigFile (
199+ { } ,
200+ vscodeWorkspace . rootPath
201+ ) ;
181202 }
182203
183204 projectConfigFile . profile = profile ;
@@ -224,6 +245,19 @@ export class ConnectionManager {
224245 this . updateCluster ( undefined ) ;
225246 }
226247
248+ async attachWorkspace ( workspacePath : Uri ) : Promise < void > {
249+ if (
250+ ! vscodeWorkspace . workspaceFolders ||
251+ ! vscodeWorkspace . workspaceFolders . length
252+ ) {
253+ // TODO how do we handle this?
254+ return ;
255+ }
256+
257+ const wsUri = vscodeWorkspace . workspaceFolders [ 0 ] . uri ;
258+ this . _pathMapper = new PathMapper ( workspacePath , wsUri ) ;
259+ }
260+
227261 private async getMe ( apiClient : ApiClient ) : Promise < string > {
228262 let scimApi = new ScimService ( apiClient ) ;
229263 let response = await scimApi . me ( { } ) ;
0 commit comments