Skip to content

Commit

Permalink
Merge pull request #66 from bradymholt/pass-config-with-file
Browse files Browse the repository at this point in the history
Revert not passing other config in with configFile set
  • Loading branch information
bradymholt authored May 9, 2023
2 parents a958330 + c8ed4ee commit 5252ac7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This extension has the following configuration settings:
* `pgFormatter.noSpaceFunction` - Remove the space character between a function call and the open parenthesis that follows (Default: `true`)
* `pgFormatter.pgFormatterPath` - Path to custom pg_format version
* `pgFormatter.perlBinPath` - The path to the perl executable (Default: `"perl"`)
* `pgFormatter.configFile` - The _absolute_ path to a [pg_format config file](https://github.com/darold/pgFormatter/blob/master/README). **If this is set, all other extension settings are ignored.** You can use a VS Code path variable to help resolve the absolute path (example: `${workspaceFolder}/pg_format.conf`).
* `pgFormatter.configFile` - The _absolute_ path to a [pg_format config file](https://github.com/darold/pgFormatter/blob/master/README). You can use a VS Code path variable to help resolve the absolute path (example: `${workspaceFolder}/pg_format.conf`). Note: The default settings for this extension may override some config in this file but you can specify a setting value to `null` to avoid this. For example, if you want to use `no-space-function` config in a pg_format.conf file and do not want the extension default to override it, you can specify `"pgFormatter.noSpaceFunction": null` in your VS Code settings.

### Ignoring Files

Expand Down
64 changes: 30 additions & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,43 @@ export function getFormattedText(
options: vscode.FormattingOptions
): string {
try {
let formattingOptions: IOptions = {};
let formattingOptions: IOptions = <any>Object.assign({}, config);

if (config.configFile != null) {
formattingOptions.configFile = substituteVariables(config.configFile);
addToOutput(`Note: Since the \`pgFormatter.configFile\` setting was specified, all other settings will be ignored.`);
} else {
formattingOptions = <any>Object.assign({}, config);
// maxLength support has been removed and the following prevents
// old settings from using it
formattingOptions.maxLength = null;

// maxLength support has been removed and the following prevents
// old settings from using it
formattingOptions.maxLength = null;
// Convert option strings to enums
if (config.functionCase != null) {
formattingOptions.functionCase = CaseOptionEnum[<keyof typeof CaseOptionEnum>config.functionCase];
}
if (config.keywordCase != null) {
formattingOptions.keywordCase = CaseOptionEnum[<keyof typeof CaseOptionEnum>config.keywordCase];
}

// Convert option strings to enums
if (config.functionCase != null) {
formattingOptions.functionCase = CaseOptionEnum[<keyof typeof CaseOptionEnum>config.functionCase];
}
if (config.keywordCase != null) {
formattingOptions.keywordCase = CaseOptionEnum[<keyof typeof CaseOptionEnum>config.keywordCase];
if (!formattingOptions.spaces) {
if (options.tabSize) {
// If spaces config not specified, use the FormattingOptions value from VSCode workspace
formattingOptions.spaces = Number(options.tabSize);
}

if (!formattingOptions.spaces) {
if (options.tabSize) {
// If spaces config not specified, use the FormattingOptions value from VSCode workspace
formattingOptions.spaces = Number(options.tabSize);
}

if (formattingOptions.tabs === undefined) {
// Neither spaces nor tabs option is configured; use insertSpaces to determine if we want to use tabs
formattingOptions.tabs = options.insertSpaces === false;
}
if (formattingOptions.tabs === undefined) {
// Neither spaces nor tabs option is configured; use insertSpaces to determine if we want to use tabs
formattingOptions.tabs = options.insertSpaces === false;
}
}

if (config.perlBinPath != null) {
formattingOptions.perlBinPath = substituteVariables(config.perlBinPath);
}
if (config.pgFormatterPath != null) {
formattingOptions.pgFormatterPath = substituteVariables(config.pgFormatterPath);
}
if (config.extraFunction != null) {
formattingOptions.extraFunction = substituteVariables(config.extraFunction);
}
if (config.perlBinPath != null) {
formattingOptions.perlBinPath = substituteVariables(config.perlBinPath);
}
if (config.pgFormatterPath != null) {
formattingOptions.pgFormatterPath = substituteVariables(config.pgFormatterPath);
}
if (config.extraFunction != null) {
formattingOptions.extraFunction = substituteVariables(config.extraFunction);
}
if (config.configFile != null) {
formattingOptions.configFile = substituteVariables(config.configFile);
}

addToOutput(`Formatting with options ${JSON.stringify(formattingOptions)}:`);
Expand Down

0 comments on commit 5252ac7

Please sign in to comment.