"use strict" ; import vscode = require ( "coc.nvim" ) ; import utils = require ( "./utils" ) ; import { isWindowsOS } from 'coc-utils' ; enum CodeFormattingPreset { Custom , Allman , OTBS , Stroustrup } enum PipelineIndentationStyle { IncreaseIndentationForFirstPipeline , IncreaseIndentationAfterEveryPipeline , NoIndentation } export enum HelpCompletion { Disabled = "Disabled" , BlockComment = "BlockComment" , LineComment = "LineComment" } export interface IPowerShellAdditionalExePathSettings { versionName : string ; exePath : string ; } export interface IBugReportingSettings { project : string ; } export interface ICodeFoldingSettings { enable ? : boolean ; showLastLine ? : boolean ; } export interface ICodeFormattingSettings { autoCorrectAliases : boolean ; preset : CodeFormattingPreset ; openBraceOnSameLine : boolean ; newLineAfterOpenBrace : boolean ; newLineAfterCloseBrace : boolean ; pipelineIndentationStyle : PipelineIndentationStyle ; whitespaceBeforeOpenBrace : boolean ; whitespaceBeforeOpenParen : boolean ; whitespaceAroundOperator : boolean ; whitespaceAfterSeparator : boolean ; whitespaceBetweenParameters : boolean ; whitespaceInsideBrace : boolean ; addWhitespaceAroundPipe : boolean ; trimWhitespaceAroundPipe : boolean ; ignoreOneLineBlock : boolean ; alignPropertyValuePairs : boolean ; useConstantStrings : boolean ; useCorrectCasing : boolean ; } export interface IScriptAnalysisSettings { enable ? : boolean ; settingsPath : string ; } export interface IDebuggingSettings { createTemporaryIntegratedConsole ? : boolean ; } export interface IDeveloperSettings { featureFlags ? : string [ ] ; powerShellExePath ? : string ; bundledModulesPath ? : string ; editorServicesLogLevel ? : string ; editorServicesWaitForDebugger ? : boolean ; powerShellExeIsWindowsDevBuild ? : boolean ; } export interface ISettings { powerShellAdditionalExePaths ? : IPowerShellAdditionalExePathSettings [ ] ; powerShellDefaultVersion ? : string ; powerShellExePath ? : string ; bundledModulesPath ? : string ; startAutomatically ? : boolean ; useX86Host ? : boolean ; enableProfileLoading ? : boolean ; helpCompletion : string ; scriptAnalysis ? : IScriptAnalysisSettings ; debugging ? : IDebuggingSettings ; developer ? : IDeveloperSettings ; codeFolding ? : ICodeFoldingSettings ; codeFormatting ? : ICodeFormattingSettings ; integratedConsole ? : IIntegratedConsoleSettings ; bugReporting ? : IBugReportingSettings ; } export interface IIntegratedConsoleSettings { showOnStartup ? : boolean ; focusConsoleOnExecute ? : boolean ; executeInCurrentScope ? : boolean ; } export function load ( ) { const configuration = vscode . workspace . getConfiguration ( utils . PowerShellLanguageId ) ; const defaultBugReportingSettings = { project : "https://github.com/yatli/coc-powershell" , } ; const defaultScriptAnalysisSettings = { enable : true , settingsPath : "" , } ; const defaultDebuggingSettings = { createTemporaryIntegratedConsole : false , } ; const featureFlags = [ ] ; if ( isWindowsOS ( ) ) { featureFlags . push ( "PSReadLine" ) ; } const defaultDeveloperSettings = { featureFlags , powerShellExePath : undefined , bundledModulesPath : "../../../PowerShellEditorServices/module" , editorServicesLogLevel : "Normal" , editorServicesWaitForDebugger : false , powerShellExeIsWindowsDevBuild : false , } ; const defaultCodeFoldingSettings = { enable : true , showLastLine : false , } ; const defaultCodeFormattingSettings = { autoCorrectAliases : false , preset : CodeFormattingPreset . Custom , openBraceOnSameLine : true , newLineAfterOpenBrace : true , newLineAfterCloseBrace : true , pipelineIndentationStyle : PipelineIndentationStyle . NoIndentation , whitespaceBeforeOpenBrace : true , whitespaceBeforeOpenParen : true , whitespaceAroundOperator : true , whitespaceAfterSeparator : true , whitespaceBetweenParameters : false , whitespaceInsideBrace : true , addWhitespaceAroundPipe : true , trimWhitespaceAroundPipe : false , ignoreOneLineBlock : true , alignPropertyValuePairs : true , useConstantStrings : false , useCorrectCasing : false , } ; const defaultIntegratedConsoleSettings = { showOnStartup : true , focusConsoleOnExecute : true , executeInCurrentScope : false , } ; return { startAutomatically : configuration . get < boolean > ( "startAutomatically" , true ) , powerShellAdditionalExePaths : configuration . get < IPowerShellAdditionalExePathSettings [ ] > ( "powerShellAdditionalExePaths" , undefined ) , powerShellDefaultVersion : configuration . get < string > ( "powerShellDefaultVersion" , undefined ) , powerShellExePath : configuration . get < string > ( "powerShellExePath" , undefined ) , bundledModulesPath : "../../modules" , useX86Host : configuration . get < boolean > ( "useX86Host" , false ) , enableProfileLoading : configuration . get < boolean > ( "enableProfileLoading" , false ) , helpCompletion : configuration . get < string > ( "helpCompletion" , HelpCompletion . BlockComment ) , scriptAnalysis : configuration . get < IScriptAnalysisSettings > ( "scriptAnalysis" , defaultScriptAnalysisSettings ) , debugging : configuration . get < IDebuggingSettings > ( "debugging" , defaultDebuggingSettings ) , developer : getWorkspaceSettingsWithDefaults < IDeveloperSettings > ( configuration , "developer" , defaultDeveloperSettings ) , codeFolding : configuration . get < ICodeFoldingSettings > ( "codeFolding" , defaultCodeFoldingSettings ) , codeFormatting : configuration . get < ICodeFormattingSettings > ( "codeFormatting" , defaultCodeFormattingSettings ) , integratedConsole : configuration . get < IIntegratedConsoleSettings > ( "integratedConsole" , defaultIntegratedConsoleSettings ) , bugReporting : configuration . get < IBugReportingSettings > ( "bugReporting" , defaultBugReportingSettings ) , } ; } export async function change ( settingName , newValue , global = false ) { const configuration = vscode . workspace . getConfiguration ( utils . PowerShellLanguageId ) ; await configuration . update ( settingName , newValue , global ) ; } function getWorkspaceSettingsWithDefaults < TSettings > ( workspaceConfiguration , settingName , defaultSettings ) { const importedSettings = workspaceConfiguration . get < TSettings > ( settingName , defaultSettings ) ; for ( const setting in importedSettings ) { if ( importedSettings [ setting ] ) { defaultSettings [ setting ] = importedSettings [ setting ] ; } } return defaultSettings ; }