11import * as vscode from "vscode" ;
2+ import { JSONServerSpec } from "../extension" ;
23import { getServerNames } from "./getServerNames" ;
34
4- export async function addServer ( scope ?: vscode . ConfigurationScope ) : Promise < string | undefined > {
5+ export async function addServer (
6+ scope ?: vscode . ConfigurationScope
7+ ) : Promise < string | undefined > {
58 const serverNames = getServerNames ( scope ) ;
6- const spec = { webServer : { scheme : "" , host : "" , port : 0 } } ;
9+ const spec : JSONServerSpec = { webServer : { scheme : "" , host : "" , port : 0 } } ;
710 return await vscode . window
811 . showInputBox ( {
912 placeHolder : "Name of new server definition" ,
@@ -26,11 +29,11 @@ export async function addServer(scope?: vscode.ConfigurationScope): Promise<stri
2629 const host = await vscode . window . showInputBox ( {
2730 placeHolder : "Hostname or IP address of web server" ,
2831 validateInput : ( value ) => {
29- return value . length ? undefined : "Required" ;
32+ return value . trim ( ) . length ? undefined : "Required" ;
3033 } ,
3134 } ) ;
3235 if ( host ) {
33- spec . webServer . host = host ;
36+ spec . webServer . host = host . trim ( ) ;
3437 const portString = await vscode . window . showInputBox ( {
3538 placeHolder : "Port of web server" ,
3639 validateInput : ( value ) => {
@@ -45,28 +48,43 @@ export async function addServer(scope?: vscode.ConfigurationScope): Promise<stri
4548 } ) ;
4649 if ( portString ) {
4750 spec . webServer . port = + portString ;
48- const scheme = await vscode . window . showQuickPick (
49- [ "http" , "https" ] ,
50- { placeHolder : "Confirm connection type, then definition will be stored in your User Settings. 'Escape' to cancel." , }
51- ) ;
52- if ( scheme ) {
53- spec . webServer . scheme = scheme ;
54- try {
55- const config = vscode . workspace . getConfiguration (
56- "intersystems" ,
57- scope
58- ) ;
59- // For simplicity we always add to the user-level (aka Global) settings
60- const servers : any =
61- config . inspect ( "servers" ) ?. globalValue || { } ;
62- servers [ name ] = spec ;
63- await config . update ( "servers" , servers , true ) ;
64- return name ;
65- } catch ( error ) {
66- vscode . window . showErrorMessage (
67- "Failed to store server definition"
68- ) ;
69- return undefined ;
51+ const username = await vscode . window . showInputBox ( {
52+ placeHolder :
53+ "Username" ,
54+ prompt :
55+ "Leave empty to be prompted when connecting."
56+ } ) ;
57+ if ( typeof username !== 'undefined' ) {
58+ const usernameTrimmed = username . trim ( ) ;
59+ if ( usernameTrimmed !== "" ) {
60+ spec . username = usernameTrimmed ;
61+ }
62+ const scheme = await vscode . window . showQuickPick (
63+ [ "http" , "https" ] ,
64+ {
65+ placeHolder :
66+ "Confirm connection type, then definition will be stored in your User Settings. 'Escape' to cancel." ,
67+ }
68+ ) ;
69+ if ( scheme ) {
70+ spec . webServer . scheme = scheme ;
71+ try {
72+ const config = vscode . workspace . getConfiguration (
73+ "intersystems" ,
74+ scope
75+ ) ;
76+ // For simplicity we always add to the user-level (aka Global) settings
77+ const servers : any =
78+ config . inspect ( "servers" ) ?. globalValue || { } ;
79+ servers [ name ] = spec ;
80+ await config . update ( "servers" , servers , true ) ;
81+ return name ;
82+ } catch ( error ) {
83+ vscode . window . showErrorMessage (
84+ "Failed to store server definition"
85+ ) ;
86+ return undefined ;
87+ }
7088 }
7189 }
7290 }
0 commit comments