Skip to content

Commit 691c3ed

Browse files
committed
fix: performance regression introduced by 290a1fd (PR #79)
There was an unintentional change to use the file path instead of tsconfig path for memoization, which changes for every file (whereas the tsconfig path is often the same for the whole project). Fixes #90.
1 parent 3cceaf4 commit 691c3ed

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

lib/get-compiler-options.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ const { findTsconfig } = require('./find-tsconfig');
44
const { memoize } = require('./memoize');
55

66
/**
7-
* Get the compiler options from a path to a file in the project.
7+
* Get the compiler options from the path to a tsconfig.
88
*
9-
* @param {string} path path to a file in the project
9+
* @param {string | undefined} tsconfig path to tsconfig
1010
*/
11-
function getCompilerOptions(path) {
12-
const tsconfig = findTsconfig(path);
13-
11+
function getCompilerOptions(tsconfig) {
1412
const compilerOptions = tsconfig
1513
? ts.parseJsonConfigFileContent(ts.readConfigFile(tsconfig, ts.sys.readFile).config, ts.sys, dirname(tsconfig))
1614
.options
@@ -24,15 +22,13 @@ function getCompilerOptions(path) {
2422
module.exports.getCompilerOptions = memoize(getCompilerOptions);
2523

2624
/**
27-
* Get the Vue compiler options from a path to a file in the project.
25+
* Get the Vue compiler options from the path to a tsconfig.
2826
*
2927
* Uses a dynamic require instead of top-level because this is only needed for Vue.
3028
*
31-
* @param {string} path path to a file in the project
29+
* @param {string | undefined} tsconfig path to tsconfig
3230
*/
33-
function getVueCompilerOptions(path) {
34-
const tsconfig = findTsconfig(path);
35-
31+
function getVueCompilerOptions(tsconfig) {
3632
return tsconfig
3733
? require('@volar/vue-language-core').createParsedCommandLine(
3834
// @ts-ignore

lib/service-host.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { getCompilerOptions, getVueCompilerOptions } = require('./get-compiler-op
1414
*/
1515
function getTypeScriptLanguageServiceHost(path, content) {
1616
const tsconfig = findTsconfig(path);
17-
const compilerOptions = getCompilerOptions(path);
17+
const compilerOptions = getCompilerOptions(tsconfig);
1818

1919
return {
2020
directoryExists: ts.sys.directoryExists,
@@ -47,7 +47,8 @@ function getTypeScriptLanguageServiceHost(path, content) {
4747
* @returns {VueLanguageServiceHost}
4848
*/
4949
function getVueLanguageServiceHost(path, content) {
50-
const vueCompilerOptions = getVueCompilerOptions(path);
50+
const tsconfig = findTsconfig(path);
51+
const vueCompilerOptions = getVueCompilerOptions(tsconfig);
5152

5253
return {
5354
...getTypeScriptLanguageServiceHost(path, content),

0 commit comments

Comments
 (0)