@@ -45,11 +45,6 @@ const (
4545 sshServerTaskKey = "start_ssh_server"
4646 serverlessEnvironmentKey = "ssh_tunnel_serverless"
4747 minEnvironmentVersion = 4
48-
49- VSCodeOption = "vscode"
50- VSCodeCommand = "code"
51- CursorOption = "cursor"
52- CursorCommand = "cursor"
5348)
5449
5550type ClientOptions struct {
@@ -117,8 +112,8 @@ func (o *ClientOptions) Validate() error {
117112 if o .ConnectionName != "" && ! connectionNameRegex .MatchString (o .ConnectionName ) {
118113 return fmt .Errorf ("connection name %q must consist of letters, numbers, dashes, and underscores" , o .ConnectionName )
119114 }
120- if o .IDE != "" && o .IDE != VSCodeOption && o .IDE != CursorOption {
121- return fmt .Errorf ("invalid IDE value: %q, expected %q or %q" , o .IDE , VSCodeOption , CursorOption )
115+ if o .IDE != "" && o .IDE != vscode . VSCodeOption && o .IDE != vscode . CursorOption {
116+ return fmt .Errorf ("invalid IDE value: %q, expected %q or %q" , o .IDE , vscode . VSCodeOption , vscode . CursorOption )
122117 }
123118 if o .EnvironmentVersion > 0 && o .EnvironmentVersion < minEnvironmentVersion {
124119 return fmt .Errorf ("environment version must be >= %d, got %d" , minEnvironmentVersion , o .EnvironmentVersion )
@@ -212,6 +207,32 @@ func Run(ctx context.Context, client *databricks.WorkspaceClient, opts ClientOpt
212207 return errors .New ("either --cluster or --name must be provided" )
213208 }
214209
210+ if opts .IDE != "" && ! opts .ProxyMode {
211+ if err := vscode .CheckIDECommand (opts .IDE ); err != nil {
212+ return err
213+ }
214+ }
215+
216+ // Check and update IDE settings for serverless mode, where we must set up
217+ // desired server ports (or socket connection mode) for the connection to go through
218+ // (as the majority of the localhost ports on the remote side are blocked by iptable rules).
219+ // Plus the platform (always linux), and extensions (python and jupyter), to make the initial experience smoother.
220+ if opts .IDE != "" && opts .IsServerlessMode () && ! opts .ProxyMode && ! opts .SkipSettingsCheck && cmdio .IsPromptSupported (ctx ) {
221+ err := vscode .CheckAndUpdateSettings (ctx , opts .IDE , opts .ConnectionName )
222+ if err != nil {
223+ cmdio .LogString (ctx , fmt .Sprintf ("Failed to update IDE settings: %v" , err ))
224+ cmdio .LogString (ctx , vscode .GetManualInstructions (opts .IDE , opts .ConnectionName ))
225+ cmdio .LogString (ctx , "Use --skip-settings-check to bypass IDE settings verification." )
226+ shouldProceed , promptErr := cmdio .AskYesOrNo (ctx , "Do you want to proceed with the connection?" )
227+ if promptErr != nil {
228+ return fmt .Errorf ("failed to prompt user: %w" , promptErr )
229+ }
230+ if ! shouldProceed {
231+ return errors .New ("aborted: IDE settings need to be updated manually, user declined to proceed" )
232+ }
233+ }
234+ }
235+
215236 // Only check cluster state for dedicated clusters
216237 if ! opts .IsServerlessMode () {
217238 err := checkClusterState (ctx , client , opts .ClusterID , opts .AutoStartCluster )
@@ -242,26 +263,6 @@ func Run(ctx context.Context, client *databricks.WorkspaceClient, opts ClientOpt
242263 cmdio .LogString (ctx , "Using SSH key: " + keyPath )
243264 cmdio .LogString (ctx , fmt .Sprintf ("Secrets scope: %s, key name: %s" , secretScopeName , opts .ClientPublicKeyName ))
244265
245- // Check and update IDE settings for serverless mode, where we must set up
246- // desired server ports (or socket connection mode) for the connection to go through
247- // (as the majority of the localhost ports on the remote side are blocked by iptable rules).
248- // Plus the platform (always linux), and extensions (python and jupyter), to make the initial experience smoother.
249- if opts .IDE != "" && opts .IsServerlessMode () && ! opts .ProxyMode && ! opts .SkipSettingsCheck && cmdio .IsPromptSupported (ctx ) {
250- err = vscode .CheckAndUpdateSettings (ctx , opts .IDE , opts .ConnectionName )
251- if err != nil {
252- cmdio .LogString (ctx , fmt .Sprintf ("Failed to update IDE settings: %v" , err ))
253- cmdio .LogString (ctx , vscode .GetManualInstructions (opts .IDE , opts .ConnectionName ))
254- cmdio .LogString (ctx , "Use --skip-settings-check to bypass IDE settings verification." )
255- shouldProceed , promptErr := cmdio .AskYesOrNo (ctx , "Do you want to proceed with the connection?" )
256- if promptErr != nil {
257- return fmt .Errorf ("failed to prompt user: %w" , promptErr )
258- }
259- if ! shouldProceed {
260- return errors .New ("aborted: IDE settings need to be updated manually, user declined to proceed" )
261- }
262- }
263- }
264-
265266 var userName string
266267 var serverPort int
267268 var clusterID string
@@ -330,7 +331,6 @@ func runIDE(ctx context.Context, client *databricks.WorkspaceClient, userName, k
330331 if err != nil {
331332 return fmt .Errorf ("failed to get current user: %w" , err )
332333 }
333- databricksUserName := currentUser .UserName
334334
335335 // Ensure SSH config entry exists
336336 configPath , err := sshconfig .GetMainConfigPath (ctx )
@@ -343,23 +343,7 @@ func runIDE(ctx context.Context, client *databricks.WorkspaceClient, userName, k
343343 return fmt .Errorf ("failed to ensure SSH config entry: %w" , err )
344344 }
345345
346- ideCommand := VSCodeCommand
347- if opts .IDE == CursorOption {
348- ideCommand = CursorCommand
349- }
350-
351- // Construct the remote SSH URI
352- // Format: ssh-remote+<server_user_name>@<connection_name> /Workspace/Users/<databricks_user_name>/
353- remoteURI := fmt .Sprintf ("ssh-remote+%s@%s" , userName , connectionName )
354- remotePath := fmt .Sprintf ("/Workspace/Users/%s/" , databricksUserName )
355-
356- cmdio .LogString (ctx , fmt .Sprintf ("Launching %s with remote URI: %s and path: %s" , opts .IDE , remoteURI , remotePath ))
357-
358- ideCmd := exec .CommandContext (ctx , ideCommand , "--remote" , remoteURI , remotePath )
359- ideCmd .Stdout = os .Stdout
360- ideCmd .Stderr = os .Stderr
361-
362- return ideCmd .Run ()
346+ return vscode .LaunchIDE (ctx , opts .IDE , connectionName , userName , currentUser .UserName )
363347}
364348
365349func ensureSSHConfigEntry (ctx context.Context , configPath , hostName , userName , keyPath string , serverPort int , clusterID string , opts ClientOptions ) error {
0 commit comments