11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33'use strict' ;
4+ import { isEmpty , isNil } from 'lodash' ;
45import * as React from 'react' ;
6+ import { IDataScienceExtraSettings } from '../../client/datascience/types' ;
57import { Image , ImageName } from '../react-common/image' ;
68import { getLocString } from '../react-common/locReactSide' ;
79import { IFont , IServerState , ServerStatus } from './mainState' ;
@@ -14,6 +16,7 @@ export interface IJupyterInfoProps {
1416 kernel : IServerState ;
1517 isNotebookTrusted ?: boolean ;
1618 shouldShowTrustMessage : boolean ;
19+ settings ?: IDataScienceExtraSettings | undefined ;
1720 selectServer ( ) : void ;
1821 launchNotebookTrustPrompt ?( ) : void ; // Native editor-specific
1922 selectKernel ( ) : void ;
@@ -33,10 +36,16 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
3336 }
3437
3538 public render ( ) {
39+ let jupyterServerDisplayName : string = this . props . kernel . localizedUri ;
40+ if ( ! isNil ( this . props . settings ) && isEmpty ( jupyterServerDisplayName ) ) {
41+ const jupyterServerUriSetting : string = this . props . settings . jupyterServerURI ;
42+ if ( this . isUriOfComputeInstance ( jupyterServerUriSetting ) ) {
43+ jupyterServerDisplayName = this . getComputeInstanceNameFromId ( jupyterServerUriSetting ) ;
44+ }
45+ }
46+
3647 const serverTextSize =
37- getLocString ( 'DataScience.jupyterServer' , 'Jupyter Server' ) . length +
38- this . props . kernel . localizedUri . length +
39- 4 ; // plus 4 for the icon
48+ getLocString ( 'DataScience.jupyterServer' , 'Jupyter Server' ) . length + jupyterServerDisplayName . length + 4 ; // plus 4 for the icon
4049 const displayNameTextSize = this . props . kernel . displayName . length + this . props . kernel . jupyterServerStatus . length ;
4150 const dynamicFont : React . CSSProperties = {
4251 fontSize : 'var(--vscode-font-size)' , // Use the same font and size as the menu
@@ -54,8 +63,8 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
5463 < div className = "kernel-status" style = { dynamicFont } >
5564 { this . renderTrustMessage ( ) }
5665 < div className = "kernel-status-section kernel-status-server" style = { serverTextWidth } role = "button" >
57- < div className = "kernel-status-text" title = { this . props . kernel . localizedUri } >
58- { getLocString ( 'DataScience.jupyterServer' , 'Jupyter Server' ) } : { this . props . kernel . localizedUri }
66+ < div className = "kernel-status-text" title = { jupyterServerDisplayName } >
67+ { getLocString ( 'DataScience.jupyterServer' , 'Jupyter Server' ) } : { jupyterServerDisplayName }
5968 </ div >
6069 < Image
6170 baseTheme = { this . props . baseTheme }
@@ -120,4 +129,24 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
120129 ? getLocString ( 'DataScience.disconnected' , 'Disconnected' )
121130 : getLocString ( 'DataScience.connected' , 'Connected' ) ;
122131 }
132+
133+ private isUriOfComputeInstance ( uri : string ) : boolean {
134+ const parsedUrl : URL = new URL ( uri ) ;
135+ return parsedUrl . searchParams . get ( 'id' ) === 'azureml_compute_instances' ;
136+ }
137+
138+ private getComputeInstanceNameFromId ( id : string | undefined ) : string {
139+ if ( isNil ( id ) ) {
140+ return '' ;
141+ }
142+
143+ const res : string [ ] | null = id . match (
144+ / \/ p r o v i d e r s \/ M i c r o s o f t .M a c h i n e L e a r n i n g S e r v i c e s \/ w o r k s p a c e s \/ [ ^ \/ ] + \/ c o m p u t e s \/ ( [ ^ \/ ] + ) ( \/ ) ? /
145+ ) ;
146+ if ( isNil ( res ) || res . length < 2 ) {
147+ return '' ;
148+ }
149+
150+ return res [ 1 ] ;
151+ }
123152}
0 commit comments