@@ -137,8 +137,39 @@ export function activate(context: vscode.ExtensionContext) {
137
137
) ;
138
138
context . subscriptions . push (
139
139
vscode . commands . registerCommand ( `${ extensionId } .editSettings` , ( server ?: ServerTreeItem ) => {
140
- // Until there's a dedicated settings editor the best we can do is jump to the right section
141
- vscode . commands . executeCommand ( "workbench.action.openSettings" , `@ext:${ extensionId } ` ) ;
140
+ // Attempt to open the correct JSON file
141
+ server = server instanceof ServerTreeItem ? server : undefined ;
142
+ const servers = vscode . workspace . getConfiguration ( "intersystems" ) . inspect < { [ key : string ] : any } > ( "servers" ) ;
143
+ const openJSONArg = { revealSetting : { key : "intersystems.servers" } } ;
144
+ const revealServer = ( ) : void => {
145
+ // Find the start of the server's settings block
146
+ const editor = vscode . window . activeTextEditor ;
147
+ const regex = new RegExp ( `"${ server ?. name } "\\s*:` ) ;
148
+ if ( editor && ( editor . document . uri . path . endsWith ( "/settings.json" ) || editor . document . uri . path . endsWith ( ".code-workspace" ) ) ) {
149
+ // The cursor is currently at "|intersystems.servers", so start our scan from there
150
+ for ( let i = editor . selection . start . line ; i < editor . document . lineCount ; i ++ ) {
151
+ const line = editor . document . lineAt ( i ) . text ;
152
+ const match = regex . exec ( line ) ;
153
+ const commentStart = line . indexOf ( "//" ) ;
154
+ if ( match && ( commentStart == - 1 || match . index < commentStart ) ) {
155
+ const cursorPos = new vscode . Position ( i , match . index + 1 ) ;
156
+ editor . revealRange ( new vscode . Range ( cursorPos , cursorPos ) , vscode . TextEditorRevealType . InCenter ) ;
157
+ editor . selection = new vscode . Selection ( cursorPos , cursorPos ) ;
158
+ break ;
159
+ }
160
+ }
161
+ }
162
+ } ;
163
+ if ( server && servers ?. workspaceValue ?. hasOwnProperty ( server . name ) ) {
164
+ // Open the workspace settings file
165
+ vscode . commands . executeCommand ( "workbench.action.openWorkspaceSettingsFile" , openJSONArg ) . then ( revealServer ) ;
166
+ } else if ( server && servers ?. globalValue ?. hasOwnProperty ( server . name ) ) {
167
+ // Open the user settings.json
168
+ vscode . commands . executeCommand ( "workbench.action.openSettingsJson" , openJSONArg ) . then ( revealServer ) ;
169
+ } else {
170
+ // Just show the UI
171
+ vscode . commands . executeCommand ( "workbench.action.openSettings" , `@ext:${ extensionId } ` ) ;
172
+ }
142
173
} ) ,
143
174
) ;
144
175
context . subscriptions . push (
0 commit comments