Skip to content

Commit

Permalink
fix: LS host's getCurrentDirectory implementation returns project r…
Browse files Browse the repository at this point in the history
…oot based on tsconfig location

Fixes #84.
  • Loading branch information
simonhaenisch committed Nov 25, 2022
1 parent 93b2ff2 commit b4a4da2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/service-host.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { dirname } = require('path');
const ts = require('typescript');
const { findTsconfig } = require('./find-tsconfig');

const { getCompilerOptions, getVueCompilerOptions } = require('./get-compiler-options');

Expand All @@ -11,16 +13,17 @@ const { getCompilerOptions, getVueCompilerOptions } = require('./get-compiler-op
* @returns {ts.LanguageServiceHost}
*/
function getTypeScriptLanguageServiceHost(path, content) {
const tsconfig = findTsconfig(path);
const compilerOptions = getCompilerOptions(path);

return {
directoryExists: ts.sys.directoryExists,
fileExists: ts.sys.fileExists,
getCurrentDirectory: ts.sys.getCurrentDirectory,
getDefaultLibFileName: ts.getDefaultLibFileName,
getDirectories: ts.sys.getDirectories,
readDirectory: ts.sys.readDirectory,
readFile: ts.sys.readFile,
getCurrentDirectory: () => (tsconfig ? dirname(tsconfig) : ts.sys.getCurrentDirectory()),
getCompilationSettings: () => compilerOptions,
getNewLine: () => ts.sys.newLine,
getScriptFileNames: () => [path],
Expand Down

0 comments on commit b4a4da2

Please sign in to comment.