1
1
import * as vscode from "vscode" ;
2
+ import { JSONServerSpec } from "../extension" ;
2
3
import { getServerNames } from "./getServerNames" ;
3
4
4
- export async function addServer ( scope ?: vscode . ConfigurationScope ) : Promise < string | undefined > {
5
+ export async function addServer (
6
+ scope ?: vscode . ConfigurationScope
7
+ ) : Promise < string | undefined > {
5
8
const serverNames = getServerNames ( scope ) ;
6
- const spec = { webServer : { scheme : "" , host : "" , port : 0 } } ;
9
+ const spec : JSONServerSpec = { webServer : { scheme : "" , host : "" , port : 0 } } ;
7
10
return await vscode . window
8
11
. showInputBox ( {
9
12
placeHolder : "Name of new server definition" ,
@@ -26,11 +29,11 @@ export async function addServer(scope?: vscode.ConfigurationScope): Promise<stri
26
29
const host = await vscode . window . showInputBox ( {
27
30
placeHolder : "Hostname or IP address of web server" ,
28
31
validateInput : ( value ) => {
29
- return value . length ? undefined : "Required" ;
32
+ return value . trim ( ) . length ? undefined : "Required" ;
30
33
} ,
31
34
} ) ;
32
35
if ( host ) {
33
- spec . webServer . host = host ;
36
+ spec . webServer . host = host . trim ( ) ;
34
37
const portString = await vscode . window . showInputBox ( {
35
38
placeHolder : "Port of web server" ,
36
39
validateInput : ( value ) => {
@@ -45,28 +48,43 @@ export async function addServer(scope?: vscode.ConfigurationScope): Promise<stri
45
48
} ) ;
46
49
if ( portString ) {
47
50
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
+ }
70
88
}
71
89
}
72
90
}
0 commit comments