@@ -7,15 +7,18 @@ import * as fs from 'fs-extra';
77import * as os from 'os' ;
88import * as path from 'path' ;
99import { inject , injectable } from 'inversify' ;
10+ import { isEqual } from 'lodash' ;
1011import { IExtensionSingleActivationService } from '../../../activation/types' ;
11- import { ICommandManager , IWorkspaceService } from '../types' ;
12+ import { IApplicationEnvironment , ICommandManager , IWorkspaceService } from '../types' ;
1213import { EXTENSION_ROOT_DIR } from '../../../constants' ;
1314import { IInterpreterService } from '../../../interpreter/contracts' ;
1415import { Commands } from '../../constants' ;
1516import { IConfigurationService , IPythonSettings } from '../../types' ;
1617import { sendTelemetryEvent } from '../../../telemetry' ;
1718import { EventName } from '../../../telemetry/constants' ;
1819import { EnvironmentType } from '../../../pythonEnvironments/info' ;
20+ import { PythonSettings } from '../../configSettings' ;
21+ import { SystemVariables } from '../../variables/systemVariables' ;
1922
2023/**
2124 * Allows the user to report an issue related to the Python extension using our template.
@@ -24,12 +27,18 @@ import { EnvironmentType } from '../../../pythonEnvironments/info';
2427export class ReportIssueCommandHandler implements IExtensionSingleActivationService {
2528 public readonly supportedWorkspaceTypes = { untrustedWorkspace : false , virtualWorkspace : true } ;
2629
30+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31+ private readonly packageJSONSettings : any ;
32+
2733 constructor (
2834 @inject ( ICommandManager ) private readonly commandManager : ICommandManager ,
2935 @inject ( IWorkspaceService ) private readonly workspaceService : IWorkspaceService ,
3036 @inject ( IInterpreterService ) private readonly interpreterService : IInterpreterService ,
3137 @inject ( IConfigurationService ) protected readonly configurationService : IConfigurationService ,
32- ) { }
38+ @inject ( IApplicationEnvironment ) appEnvironment : IApplicationEnvironment ,
39+ ) {
40+ this . packageJSONSettings = appEnvironment . packageJson ?. contributes ?. configuration ?. properties ;
41+ }
3342
3443 public async activate ( ) : Promise < void > {
3544 this . commandManager . registerCommand ( Commands . ReportIssue , this . openReportIssue , this ) ;
@@ -48,20 +57,31 @@ export class ReportIssueCommandHandler implements IExtensionSingleActivationServ
4857 const argSetting = argSettings [ property ] ;
4958 if ( argSetting ) {
5059 if ( typeof argSetting === 'object' ) {
51- userSettings = userSettings . concat ( os . EOL , property , os . EOL ) ;
60+ let propertyHeaderAdded = false ;
5261 const argSettingsDict = ( settings [ property ] as unknown ) as Record < string , unknown > ;
5362 if ( typeof argSettingsDict === 'object' ) {
5463 Object . keys ( argSetting ) . forEach ( ( item ) => {
5564 const prop = argSetting [ item ] ;
5665 if ( prop ) {
57- const value = prop === true ? JSON . stringify ( argSettingsDict [ item ] ) : '"<placeholder>"' ;
58- userSettings = userSettings . concat ( '• ' , item , ': ' , value , os . EOL ) ;
66+ const defaultValue = this . getDefaultValue ( `${ property } .${ item } ` ) ;
67+ if ( defaultValue === undefined || ! isEqual ( defaultValue , argSettingsDict [ item ] ) ) {
68+ if ( ! propertyHeaderAdded ) {
69+ userSettings = userSettings . concat ( os . EOL , property , os . EOL ) ;
70+ propertyHeaderAdded = true ;
71+ }
72+ const value =
73+ prop === true ? JSON . stringify ( argSettingsDict [ item ] ) : '"<placeholder>"' ;
74+ userSettings = userSettings . concat ( '• ' , item , ': ' , value , os . EOL ) ;
75+ }
5976 }
6077 } ) ;
6178 }
6279 } else {
63- const value = argSetting === true ? JSON . stringify ( settings [ property ] ) : '"<placeholder>"' ;
64- userSettings = userSettings . concat ( os . EOL , property , ': ' , value , os . EOL ) ;
80+ const defaultValue = this . getDefaultValue ( property ) ;
81+ if ( defaultValue === undefined || ! isEqual ( defaultValue , settings [ property ] ) ) {
82+ const value = argSetting === true ? JSON . stringify ( settings [ property ] ) : '"<placeholder>"' ;
83+ userSettings = userSettings . concat ( os . EOL , property , ': ' , value , os . EOL ) ;
84+ }
6585 }
6686 }
6787 } ) ;
@@ -72,10 +92,30 @@ export class ReportIssueCommandHandler implements IExtensionSingleActivationServ
7292 this . workspaceService . getConfiguration ( 'python' ) . get < string > ( 'languageServer' ) || 'Not Found' ;
7393 const virtualEnvKind = interpreter ?. envType || EnvironmentType . Unknown ;
7494
95+ const hasMultipleFolders = ( this . workspaceService . workspaceFolders ?. length ?? 0 ) > 1 ;
96+ const hasMultipleFoldersText =
97+ hasMultipleFolders && userSettings !== ''
98+ ? `Multiroot scenario, following user settings may not apply:${ os . EOL } `
99+ : '' ;
75100 await this . commandManager . executeCommand ( 'workbench.action.openIssueReporter' , {
76101 extensionId : 'ms-python.python' ,
77- issueBody : template . format ( pythonVersion , virtualEnvKind , languageServer , userSettings ) ,
102+ issueBody : template . format (
103+ pythonVersion ,
104+ virtualEnvKind ,
105+ languageServer ,
106+ hasMultipleFoldersText ,
107+ userSettings ,
108+ ) ,
78109 } ) ;
79110 sendTelemetryEvent ( EventName . USE_REPORT_ISSUE_COMMAND , undefined , { } ) ;
80111 }
112+
113+ private getDefaultValue ( settingKey : string ) {
114+ if ( ! this . packageJSONSettings ) {
115+ return undefined ;
116+ }
117+ const resource = PythonSettings . getSettingsUriAndTarget ( undefined , this . workspaceService ) . uri ;
118+ const systemVariables = new SystemVariables ( resource , undefined , this . workspaceService ) ;
119+ return systemVariables . resolveAny ( this . packageJSONSettings [ `python.${ settingKey } ` ] ?. default ) ;
120+ }
81121}
0 commit comments