@@ -16,12 +16,10 @@ import { localize } from '../shared/utilities/vsCodeUtils'
16
16
import { RedshiftWarehouseNode } from './explorer/redshiftWarehouseNode'
17
17
import { ToolkitError } from '../shared/errors'
18
18
import { deleteConnection , updateConnectionParamsState } from './explorer/redshiftState'
19
- import globals from '../shared/extensionGlobals'
20
19
import { showViewLogsMessage } from '../shared/utilities/messages'
20
+ import { showConnectionMessage } from './messageUtils'
21
21
22
22
export async function activate ( ctx : ExtContext ) : Promise < void > {
23
- const outputChannel = globals . outputChannel
24
-
25
23
if ( 'NotebookEdit' in vscode ) {
26
24
ctx . extensionContext . subscriptions . push (
27
25
vscode . workspace . registerNotebookSerializer ( 'aws-redshift-sql-notebook' , new RedshiftNotebookSerializer ( ) )
@@ -34,7 +32,7 @@ export async function activate(ctx: ExtContext): Promise<void> {
34
32
ctx . extensionContext . subscriptions . push (
35
33
Commands . register (
36
34
'aws.redshift.notebookConnectClicked' ,
37
- getNotebookConnectClickedHandler ( ctx , redshiftNotebookController , outputChannel )
35
+ getNotebookConnectClickedHandler ( ctx , redshiftNotebookController )
38
36
)
39
37
)
40
38
@@ -46,7 +44,7 @@ export async function activate(ctx: ExtContext): Promise<void> {
46
44
)
47
45
48
46
ctx . extensionContext . subscriptions . push (
49
- Commands . register ( 'aws.redshift.editConnection' , getEditConnectionHandler ( outputChannel ) )
47
+ Commands . register ( 'aws.redshift.editConnection' , getEditConnectionHandler ( ) )
50
48
)
51
49
52
50
ctx . extensionContext . subscriptions . push (
@@ -73,19 +71,14 @@ function getCreateNotebookClickedHandler(redshiftNotebookController: RedshiftNot
73
71
}
74
72
}
75
73
76
- function getNotebookConnectClickedHandler (
77
- ctx : ExtContext ,
78
- redshiftNotebookController : RedshiftNotebookController ,
79
- outputChannel : vscode . OutputChannel
80
- ) {
74
+ function getNotebookConnectClickedHandler ( ctx : ExtContext , redshiftNotebookController : RedshiftNotebookController ) {
81
75
return async ( cell : vscode . NotebookCell , refreshCellStatusBar : ( ) => void ) => {
82
76
const warehouseConnectionWizard = new NotebookConnectionWizard ( ctx . regionProvider )
83
77
let connectionParams : ConnectionParams | undefined = await warehouseConnectionWizard . run ( )
84
78
if ( ! connectionParams ) {
85
79
return
86
80
}
87
81
redshiftNotebookController . redshiftClient = new DefaultRedshiftClient ( connectionParams . region ! . id )
88
- outputChannel . show ( true )
89
82
try {
90
83
const redshiftClient = ( redshiftNotebookController . redshiftClient = new DefaultRedshiftClient (
91
84
connectionParams . region ! . id
@@ -98,11 +91,9 @@ function getNotebookConnectClickedHandler(
98
91
connectionParams . secret = secretArnFetched
99
92
}
100
93
await redshiftNotebookController . redshiftClient . listDatabases ( connectionParams ! )
101
- outputChannel . appendLine ( `Redshift: connected to: ${ connectionParams . warehouseIdentifier } ` )
94
+ showConnectionMessage ( connectionParams . warehouseIdentifier , undefined )
102
95
} catch ( error ) {
103
- outputChannel . appendLine (
104
- `Redshift: failed to connect to: ${ connectionParams . warehouseIdentifier } - ${ ( error as Error ) . message } `
105
- )
96
+ showConnectionMessage ( connectionParams . warehouseIdentifier , error as Error )
106
97
connectionParams = undefined
107
98
}
108
99
const edit = new vscode . WorkspaceEdit ( )
@@ -116,7 +107,7 @@ function getNotebookConnectClickedHandler(
116
107
}
117
108
}
118
109
119
- function getEditConnectionHandler ( outputChannel : vscode . OutputChannel ) {
110
+ function getEditConnectionHandler ( ) {
120
111
return async ( redshiftWarehouseNode : RedshiftWarehouseNode ) => {
121
112
try {
122
113
const connectionParams = await new RedshiftNodeConnectionWizard ( redshiftWarehouseNode ) . run ( )
@@ -134,12 +125,7 @@ function getEditConnectionHandler(outputChannel: vscode.OutputChannel) {
134
125
await vscode . commands . executeCommand ( 'aws.refreshAwsExplorerNode' , redshiftWarehouseNode )
135
126
}
136
127
} catch ( error ) {
137
- outputChannel . show ( true )
138
- outputChannel . appendLine (
139
- `Redshift: Failed to fetch databases for warehouse ${ redshiftWarehouseNode . name } - ${
140
- ( error as Error ) . message
141
- } `
142
- )
128
+ showConnectionMessage ( redshiftWarehouseNode . name , error as Error )
143
129
}
144
130
}
145
131
}
0 commit comments