From dfd41e13689c27ba1db2128339ef05d075965a39 Mon Sep 17 00:00:00 2001 From: Qiming Zhao Date: Wed, 20 Apr 2022 21:12:53 +0800 Subject: [PATCH] use cached format options --- package.json | 2 +- src/server/features/fileConfigurationManager.ts | 8 +++++++- yarn.lock | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index c8bd588..4a97f46 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/server/features/fileConfigurationManager.ts b/src/server/features/fileConfigurationManager.ts index 42d9acc..49184c0 100644 --- a/src/server/features/fileConfigurationManager.ts +++ b/src/server/features/fileConfigurationManager.ts @@ -87,7 +87,13 @@ export default class FileConfigurationManager { } public async ensureConfigurationForDocument(document: TextDocument, token: CancellationToken): Promise { - 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) } diff --git a/yarn.lock b/yarn.lock index d538c56..a37f5dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"