@@ -12,6 +12,9 @@ import { PythonManager } from "./pythonmanger";
1212import { LanguageStatusSeverity } from "vscode" ;
1313import { TestControllerManager } from "./testcontrollermanager" ;
1414
15+ import * as path from "path" ;
16+ import * as fs from "fs-extra" ;
17+
1518const NOT_INSTALLED = "not installed" ;
1619
1720type QuickPickActionItem = {
@@ -168,6 +171,12 @@ export class LanguageToolsManager {
168171 }
169172 } ,
170173 } ,
174+ {
175+ label : "Report Issue" ,
176+ action : async ( folder ?: vscode . WorkspaceFolder ) : Promise < void > => {
177+ vscode . commands . executeCommand ( "robotcode.reportIssue" , folder ) ;
178+ } ,
179+ } ,
171180 ] ;
172181
173182 constructor (
@@ -220,6 +229,87 @@ export class LanguageToolsManager {
220229 } ,
221230 ) ,
222231
232+ vscode . commands . registerCommand ( "robotcode.reportIssue" , async ( folder ?: vscode . WorkspaceFolder ) => {
233+ if ( folder === undefined ) {
234+ if ( vscode . window . activeTextEditor !== undefined ) {
235+ folder = vscode . workspace . getWorkspaceFolder ( vscode . window . activeTextEditor . document . uri ) ;
236+ }
237+ }
238+ if ( folder === undefined ) {
239+ if ( vscode . workspace . workspaceFolders !== undefined && vscode . workspace . workspaceFolders . length === 1 ) {
240+ folder = vscode . workspace . workspaceFolders [ 0 ] ;
241+ } else {
242+ if ( vscode . workspace . workspaceFolders !== undefined && vscode . workspace . workspaceFolders . length > 1 ) {
243+ folder = await vscode . window . showWorkspaceFolderPick ( {
244+ placeHolder : "Select a workspace folder to report an issue for" ,
245+ } ) ;
246+ }
247+ }
248+ }
249+ const folders = folder !== undefined ? [ folder ] : ( vscode . workspace . workspaceFolders ?? [ ] ) ;
250+
251+ const bodyTemplatePath = path . join (
252+ extensionContext . extensionPath ,
253+ "resources" ,
254+ "report_issue_body_template.md" ,
255+ ) ;
256+ const issueBody = ( await fs . readFile ( bodyTemplatePath , { encoding : "utf8" } ) ) . replaceAll ( "\r" , "" ) . trim ( ) ;
257+
258+ const dataTemplatePath = path . join (
259+ extensionContext . extensionPath ,
260+ "resources" ,
261+ "report_issue_data_template.md" ,
262+ ) ;
263+ let data = ( await fs . readFile ( dataTemplatePath , { encoding : "utf8" } ) ) . replaceAll ( "\r" , "" ) . trim ( ) ;
264+
265+ const pythonVersions : string [ ] = [ ] ;
266+ const robotFrameworkVersions : string [ ] = [ ] ;
267+ const robocopVersions : string [ ] = [ ] ;
268+ const tidyVersions : string [ ] = [ ] ;
269+
270+ for ( const folder of folders ) {
271+ const pythonInfo = await pythonManager . getPythonInfo ( folder ) ;
272+
273+ if ( pythonInfo !== undefined ) {
274+ const n = `${ pythonInfo . version } ${ pythonInfo . type !== undefined ? " " + pythonInfo . type : "" } ` ;
275+ if ( ! pythonVersions . includes ( n ) ) pythonVersions . push ( n ) ;
276+ }
277+
278+ const info = await this . languageClientsManager . getProjectInfo ( folder ) ;
279+ if ( info !== undefined ) {
280+ if ( info . robotVersionString && ! robotFrameworkVersions . includes ( info . robotVersionString ) )
281+ robotFrameworkVersions . push ( info . robotVersionString ) ;
282+
283+ if ( info . robocopVersionString && ! robocopVersions . includes ( info . robocopVersionString ) )
284+ robocopVersions . push ( info . robocopVersionString ) ;
285+
286+ if ( info . tidyVersionString && ! tidyVersions . includes ( info . tidyVersionString ) )
287+ tidyVersions . push ( info . tidyVersionString ) ;
288+ }
289+ }
290+
291+ data = data . replace ( "${{ PYTHON_VERSION }}" , pythonVersions . join ( ", " ) ) ;
292+ data = data . replace ( "${{ ROBOTFRAMEWORK_VERSION }}" , robotFrameworkVersions . join ( ", " ) ) ;
293+ data = data . replace (
294+ "${{ ADDITIONAL_TOOLS }}" ,
295+ robocopVersions . length > 0 || tidyVersions . length > 0
296+ ? [
297+ robocopVersions . map ( ( v ) => "robotframework-robocop==" + v ) . join ( ", " ) ,
298+ tidyVersions . map ( ( v ) => "robotframework-tidy==" + v ) . join ( ", " ) ,
299+ ] . join ( ", " )
300+ : "" ,
301+ ) ;
302+
303+ const args = {
304+ extensionId : "d-biehl.robotcode" ,
305+ // issueTitle: "Issue with RobotCode",
306+ issueBody,
307+ data,
308+ } ;
309+
310+ await vscode . commands . executeCommand ( "workbench.action.openIssueReporter" , args ) ;
311+ } ) ,
312+
223313 vscode . commands . registerCommand ( "robotcode.showToolMenu" , async ( folder ?: vscode . WorkspaceFolder ) => {
224314 let f = folder ;
225315
@@ -285,14 +375,15 @@ export class LanguageToolsManager {
285375 case ClientState . Starting :
286376 this . removeFolder ( folder ) ;
287377 this . robotVersion . busy = true ;
288- await this . updateItems ( ) ;
378+
289379 break ;
290380 default :
291381 this . removeFolder ( folder ) ;
292382 this . robotVersion . busy = false ;
293- await this . updateItems ( ) ;
383+
294384 break ;
295385 }
386+ await this . updateItems ( ) ;
296387 } ) ,
297388 pythonManager . onActivePythonEnvironmentChanged ( async ( event ) => {
298389 if ( event . resource !== undefined ) {
0 commit comments