Skip to content

Commit

Permalink
Update createTester.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 6, 2023
1 parent 3eb634e commit fbfaa5d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/language-service/tests/utils/createTester.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TypeScriptProjectHost, createLanguageService, resolveCommonLanguageId } from '@volar/language-service';
import { createLanguage, createSys } from '@volar/typescript';
import { createLanguage } from '@volar/typescript';
import * as path from 'path';
import type * as ts from 'typescript/lib/tsserverlibrary';
import { URI } from 'vscode-uri';
Expand All @@ -9,18 +9,19 @@ import { createMockServiceEnv } from './mockEnv';
const testRoot = path.resolve(__dirname, '../../../../test-workspace/language-service').replace(/\\/g, '/');

export const rootUri = URI.file(testRoot);
export const tester = createTester(testRoot);
export const tester = createTester(rootUri);

function createTester(root: string) {
function createTester(rootUri: URI) {

const ts = require('typescript') as typeof import('typescript/lib/tsserverlibrary');
const realTsConfig = path.join(root, 'tsconfig.json').replace(/\\/g, '/');
const serviceEnv = createMockServiceEnv(rootUri, () => currentVSCodeSettings ?? defaultVSCodeSettings);
const rootPath = serviceEnv.uriToFileName(rootUri.toString());
const realTsConfig = path.join(rootPath, 'tsconfig.json').replace(/\\/g, '/');
const parsedCommandLine = createParsedCommandLine(ts, ts.sys, realTsConfig);
parsedCommandLine.fileNames = parsedCommandLine.fileNames.map(fileName => fileName.replace(/\\/g, '/'));
const scriptSnapshots = new Map<string, ts.IScriptSnapshot>();
const serviceEnv = createMockServiceEnv(rootUri, () => currentVSCodeSettings ?? defaultVSCodeSettings);
const languageHost: TypeScriptProjectHost = {
getCurrentDirectory: () => root,
getCurrentDirectory: () => rootPath,
getProjectVersion: () => '0',
getScriptFileNames: () => parsedCommandLine.fileNames,
getCompilationSettings: () => parsedCommandLine.options,
Expand All @@ -41,7 +42,7 @@ function createTester(root: string) {
let currentVSCodeSettings: any;
const language = createLanguage(
ts,
createSys(ts, serviceEnv, root),
ts.sys,
Object.values(languages),
realTsConfig,
languageHost,
Expand Down

0 comments on commit fbfaa5d

Please sign in to comment.