use cached format options

This commit is contained in:
Qiming Zhao 2022-04-20 21:12:53 +08:00
parent 2fd4948bd5
commit dfd41e1368
No known key found for this signature in database
GPG key ID: 9722CD0E8D4DCB8C
3 changed files with 12 additions and 6 deletions

View file

@ -913,7 +913,7 @@
"license": "MIT",
"devDependencies": {
"@types/node": "^12.12.12",
"coc.nvim": "^0.0.81-next.11",
"coc.nvim": "^0.0.81-next.23",
"esbuild": "^0.14.11",
"semver": "^7.3.5",
"vscode-languageserver-protocol": "^3.16.0",

View file

@ -87,7 +87,13 @@ export default class FileConfigurationManager {
}
public async ensureConfigurationForDocument(document: TextDocument, token: CancellationToken): Promise<void> {
let opts = await workspace.getFormatOptions(document.uri)
let opts: { insertSpaces: boolean, tabSize: number }
let cached = this.cachedMap.get(document.uri)
if (cached) {
opts = { insertSpaces: cached.formatOptions.convertTabsToSpaces, tabSize: cached.formatOptions.tabSize }
} else {
opts = await workspace.getFormatOptions(document.uri)
}
return this.ensureConfigurationOptions(document, opts.insertSpaces, opts.tabSize, token)
}

View file

@ -7,10 +7,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.41.tgz#81d7734c5257da9f04354bd9084a6ebbdd5198a5"
integrity sha512-f6xOqucbDirG7LOzedpvzjP3UTmHttRou3Mosx3vL9wr9AIQGhcPgVnqa8ihpZYnxyM1rxeNCvTyukPKZtq10Q==
coc.nvim@^0.0.81-next.11:
version "0.0.81-next.11"
resolved "https://registry.yarnpkg.com/coc.nvim/-/coc.nvim-0.0.81-next.11.tgz#2ac44f770da662adbaf30678edc837715016fe90"
integrity sha512-XxRRdpK67tVJH+zvwi4bHc9e/UJWBj2ZJdY8Q9/Twp0tgipDstoCqK3KeoszT79J7whPzS/1Y/8VG7dRNrMJ4w==
coc.nvim@^0.0.81-next.23:
version "0.0.81-next.23"
resolved "https://registry.yarnpkg.com/coc.nvim/-/coc.nvim-0.0.81-next.23.tgz#48d8238afaaa0738c6237d8c077ba1791e2f90c6"
integrity sha512-RxNx6iRz7UvdgDeMVLyNXP6xe8GU8aY0Qxl/sBI+m2RzAJDRKCPuyFU1uOSxZntLglWtzKd87k3Byymdm19uBQ==
esbuild-android-arm64@0.14.11:
version "0.14.11"