@@ -10,6 +10,7 @@ interface IDB2ChatResult extends vscode.ChatResult {
10
10
metadata : {
11
11
command : string ;
12
12
followUps : string [ ] ;
13
+ statement ?: string ;
13
14
} ;
14
15
}
15
16
@@ -93,15 +94,15 @@ export function activateChat(context: vscode.ExtensionContext) {
93
94
}
94
95
} ) ;
95
96
96
- await copilotRequest (
97
+ const result = await copilotRequest (
97
98
request . model . family ,
98
99
messages ,
99
100
{ } ,
100
101
token ,
101
102
stream
102
103
) ;
103
104
104
- return { metadata : { command : "build" , followUps : contextItems . followUps } } ;
105
+ return { metadata : { command : "build" , followUps : contextItems . followUps , statement : result . sqlCodeBlock } } ;
105
106
}
106
107
} else {
107
108
throw new Error (
@@ -132,20 +133,37 @@ export function activateChat(context: vscode.ExtensionContext) {
132
133
context . subscriptions . push ( chat ) ;
133
134
}
134
135
136
+ interface Result {
137
+ output : string ;
138
+ sqlCodeBlock ?: string ;
139
+ }
140
+
135
141
async function copilotRequest (
136
142
model : string ,
137
143
messages : vscode . LanguageModelChatMessage [ ] ,
138
144
options : vscode . LanguageModelChatRequestOptions ,
139
145
token : vscode . CancellationToken ,
140
146
stream : vscode . ChatResponseStream
141
- ) : Promise < void > {
147
+ ) : Promise < Result | undefined > {
142
148
const models = await vscode . lm . selectChatModels ( { family : model } ) ;
143
149
if ( models . length > 0 ) {
144
150
const [ first ] = models ;
145
151
const response = await first . sendRequest ( messages , options , token ) ;
152
+ let result : Result = {
153
+ output : "" ,
154
+ }
146
155
147
156
for await ( const fragment of response . text ) {
148
157
stream . markdown ( fragment ) ;
158
+ result . output += fragment ;
149
159
}
160
+
161
+ const codeBlockStart = result . output . indexOf ( "```sql" ) ;
162
+ const codeBlockEnd = result . output . indexOf ( "```" , codeBlockStart + 6 ) ;
163
+ if ( codeBlockStart !== - 1 && codeBlockEnd !== - 1 ) {
164
+ result . sqlCodeBlock = result . output . substring ( codeBlockStart + 6 , codeBlockEnd ) ;
165
+ }
166
+
167
+ return result ;
150
168
}
151
169
}
0 commit comments