15
15
import * as fs from "fs" ;
16
16
import * as path from "path" ;
17
17
import * as vscode from "vscode" ;
18
- import { SETTINGS_CPY_SECTION } from "../constants" ;
18
+ import { PATHS_LOCAL_KEY , PATHS_USS , PATHS_ZOWE , SERVER_PORT , SETTINGS_CPY_SECTION , SETTINGS_SUBROUTINE_LOCAL_KEY } from "../constants" ;
19
19
20
20
/**
21
21
* New file (e.g .gitignore) will be created or edited if exits, under project folder
@@ -49,3 +49,97 @@ export function createFileWithGivenPath(folderPath: string, fileName: string, pa
49
49
}
50
50
51
51
}
52
+
53
+ /**
54
+ * SettingsService provides read/write configurstion settings functionality
55
+ */
56
+ export class SettingsService {
57
+ /**
58
+ * Get list of local subroutine path
59
+ * @returns a list of local subroutine path
60
+ */
61
+ public static getSubroutineLocalPath ( ) : string [ ] {
62
+ return vscode . workspace . getConfiguration ( ) . get ( SETTINGS_SUBROUTINE_LOCAL_KEY ) ;
63
+ }
64
+
65
+ /**
66
+ * Get copybook local path based on program file name
67
+ * @param cobolProgramName is a program file name
68
+ * @returns a list of local path
69
+ */
70
+ public static getCopybookLocalPath ( cobolProgramName : string ) : string [ ] {
71
+ const pathList : string [ ] = vscode . workspace . getConfiguration ( SETTINGS_CPY_SECTION ) . get ( PATHS_LOCAL_KEY ) ;
72
+ return SettingsService . evaluateVariable ( pathList , "program_name" , cobolProgramName ) ;
73
+ }
74
+
75
+ /**
76
+ * Get Lsp Port from configuration
77
+ * @returns lsp port number
78
+ */
79
+ public static getLspPort ( ) : number | undefined {
80
+ return + vscode . workspace . getConfiguration ( ) . get ( SERVER_PORT ) ;
81
+ }
82
+
83
+ /**
84
+ * Determine if dsn path exists in the configurstion
85
+ * @returns true if path exists and false otherwise
86
+ */
87
+ public static hasDsnPath ( ) : boolean {
88
+ return vscode . workspace . getConfiguration ( SETTINGS_CPY_SECTION ) . has ( PATHS_ZOWE )
89
+ }
90
+
91
+ /**
92
+ * Get list of dsn path
93
+ * @returns a list of dsn path
94
+ */
95
+ public static getDsnPath ( ) : string [ ] {
96
+ return vscode . workspace . getConfiguration ( SETTINGS_CPY_SECTION ) . get ( PATHS_ZOWE ) ;
97
+ }
98
+
99
+ /**
100
+ * Set list of dsn path to the configuration
101
+ * @param paths is a list of new values
102
+ */
103
+ public static setDsnPath ( paths : string [ ] ) {
104
+ vscode . workspace . getConfiguration ( SETTINGS_CPY_SECTION ) . update ( PATHS_ZOWE , paths ) ;
105
+ }
106
+
107
+ /**
108
+ * Determine if uss path exists in the configurstion
109
+ * @returns true if path exists and false otherwise
110
+ */
111
+ public static hasUssPath ( ) : boolean {
112
+ return vscode . workspace . getConfiguration ( SETTINGS_CPY_SECTION ) . has ( PATHS_USS )
113
+ }
114
+
115
+ /**
116
+ * Get list of uss path
117
+ * @returns a list of uss path
118
+ */
119
+ public static getUssPath ( ) : string [ ] {
120
+ return vscode . workspace . getConfiguration ( SETTINGS_CPY_SECTION ) . get ( PATHS_USS )
121
+ }
122
+
123
+ /**
124
+ * Get profile name
125
+ * @returns a profile name
126
+ */
127
+ public static getProfileName ( ) : string {
128
+ return vscode . workspace . getConfiguration ( SETTINGS_CPY_SECTION ) . get ( "profiles" )
129
+ }
130
+
131
+ /**
132
+ * Determine if confuguration is invalid
133
+ * @returns true if configurstion is invalid and false otherwise
134
+ */
135
+ public static isConfigurationInvalid ( ) {
136
+ return ! SettingsService . hasDsnPath ( ) &&
137
+ ! SettingsService . hasUssPath ( ) ;
138
+ }
139
+
140
+ private static evaluateVariable ( dataList : string [ ] , variable : string , value : string ) : string [ ] {
141
+ const result : string [ ] = [ ] ;
142
+ dataList . forEach ( d => result . push ( d . replace ( "$" + variable , value ) ) )
143
+ return result ;
144
+ }
145
+ }
0 commit comments