-
-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add prettier.config setting #433
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some comments with change I'd like to see.
Could you also update the changelog file ?
README.md
Outdated
@@ -110,6 +110,9 @@ Require a 'prettierconfig' to format | |||
Supply the path to an ignore file such as `.gitignore` or `.prettierignore`. | |||
Files which match will not be formatted. Set to `null` to not read ignore files. Restart required. | |||
|
|||
#### prettier.configPath (default: not used) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we name this config
instead of configPath
.
prettier (cli) names this option --config
README.md
Outdated
@@ -110,6 +110,9 @@ Require a 'prettierconfig' to format | |||
Supply the path to an ignore file such as `.gitignore` or `.prettierignore`. | |||
Files which match will not be formatted. Set to `null` to not read ignore files. Restart required. | |||
|
|||
#### prettier.configPath (default: not used) | |||
Supply the path to a prettier config file such as `.prettierrc`. The path should be relative to the workspace folder. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could also be an absolute path?
src/PrettierEditProvider.ts
Outdated
const { config: fileOptions, error } = await resolveConfig(fileName, { | ||
editorconfig: true, | ||
config: workspaceFolder && configPath && join(workspaceFolder.name, configPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing absolute path handling
This relative to workspaceFolder / absolutePath handling could be extracted to a function. This is already used for prettierignore (others?)
src/configCacheHandler.ts
Outdated
@@ -15,6 +16,12 @@ const PRETTIER_CONFIG_FILES = [ | |||
'prettier.config.js', | |||
]; | |||
|
|||
const configPath = getConfig().configPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only handling User settings. And would need a restart in case the setting (not the file) is changed.
Did some changes. const prettierConfigPath = getConfig().config;
if (prettierConfigPath) {
PRETTIER_CONFIG_FILES.push(basename(prettierConfigPath));
} the intention is to watch for prettier config files, for setting files restart is required, same as for |
Sorry for the delay. Quickly went through (I will need a little more time to review), seems fine. |
Right, so for files like Another thing, if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your changes, still some changes to handle every possible config files.
It's a resource scope setting :-)
@@ -15,6 +17,12 @@ const PRETTIER_CONFIG_FILES = [ | |||
'prettier.config.js', | |||
]; | |||
|
|||
const prettierConfigPath = getConfig().config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may be multiple config files, one per workspace folder.
This is just reading one.
To do it correctly, we would need to set up file change hooks for every files. And remove them when needed.
When a workspace folder is added, check the config and register a hook for it if needed
When a workspace folder is removed, remove the file watcher if it exists
const prettierConfigPath = getConfig().config; | ||
|
||
if (prettierConfigPath) { | ||
PRETTIER_CONFIG_FILES.push(basename(prettierConfigPath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be in this array, see previous comment.
* Get absolute path for relative or absolute filePath. | ||
* Relative to uri's workspace folder in relative case. | ||
*/ | ||
export function getAbsolutePath(uri: Uri, filePath: string): string | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Closing as this is very outdated. |
For #254.