Skip to content
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

feat: upgrade coc-prettier prettier version to 3.x.x #172

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/
joemckenney marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,6 @@
"typescript": "^4.6.4"
},
"dependencies": {
"prettier": "^2.6.2"
"prettier": "^3.1.1"
}
}
9 changes: 5 additions & 4 deletions src/PrettierEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ const PRETTIER_CONFIG_FILES = [
'.prettierrc.toml',
'.prettierrc.js',
'.prettierrc.cjs',
'package.json',
'.prettierrc.mjs',
'prettier.config.js',
'prettier.config.cjs',
'prettier.config.mjs',
'package.json',
'.editorconfig'
]

Expand Down Expand Up @@ -363,7 +365,6 @@ export default class PrettierEditService implements Disposable {
return TextEdit.replace(Range.create(pos0, pos1), newText)
}


/**
* Format the given text with user's configuration.
* @param text Text to format
Expand Down Expand Up @@ -445,7 +446,7 @@ export default class PrettierEditService implements Disposable {
// somebody has registered a custom file extension without properly
// configuring the parser in their prettier config.
this.loggingService.logWarning(`Parser not inferred, trying languageId.`)
const languages = prettierInstance.getSupportInfo().languages
const languages = (await prettierInstance.getSupportInfo()).languages
parser = getParserFromLanguageId(languages, Uri.parse(uri), languageId)
}

Expand All @@ -468,7 +469,7 @@ export default class PrettierEditService implements Disposable {
this.loggingService.logInfo('Prettier Options:', prettierOptions)

try {
const formattedText = prettierInstance.format(text, prettierOptions)
const formattedText = await prettierInstance.format(text, prettierOptions)
this.statusBar.update(FormatterStatus.Success)

return formattedText
Expand Down
4 changes: 2 additions & 2 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type PrettierOptions = prettier.Options
type PrettierFileInfoOptions = prettier.FileInfoOptions

type PrettierModule = {
format(source: string, options?: prettier.Options): string
getSupportInfo(): { languages: PrettierSupportLanguage[] }
format(source: string, options?: prettier.Options): Promise<string>
getSupportInfo(): Promise<{ languages: PrettierSupportLanguage[] }>
getFileInfo(
filePath: string,
options?: PrettierFileInfoOptions
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ path-parse@^1.0.7:
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==

prettier@^2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032"
integrity sha512-PkUpF+qoXTqhOeWL9fu7As8LXsIUZ1WYaJiY/a7McAQzxjk82OF0tibkFXVCDImZtWxbvojFjerkiLb0/q8mew==
prettier@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.1.1.tgz#6ba9f23165d690b6cbdaa88cb0807278f7019848"
integrity sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==

resolve@^1.22.0:
version "1.22.0"
Expand Down