Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 12, 2023
1 parent c228f4b commit 26d12e1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './lib/documentRegistry';
export * from './lib/node/decorateLanguageService';
export * from './lib/node/decorateLanguageServiceHost';
export * from './lib/node/decorateProgram';
export * from './lib/node/proxyCreateProgram';
export * from './lib/protocol/createProject';
export * from './lib/protocol/createSys';
4 changes: 2 additions & 2 deletions packages/typescript/lib/node/proxyCreateProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function proxyCreateProgram(
ts: typeof import('typescript'),
original: typeof ts['createProgram'],
extensions: string[],
getLanguagePlugins: (options: ts.CreateProgramOptions) => LanguagePlugin[],
getLanguagePlugins: (ts: typeof import('typescript/lib/tsserverlibrary'), options: ts.CreateProgramOptions) => LanguagePlugin[],
) {
return new Proxy(original, {
apply: (target, thisArg, args) => {
Expand All @@ -21,7 +21,7 @@ export function proxyCreateProgram(

const sourceFileToSnapshotMap = new WeakMap<ts.SourceFile, ts.IScriptSnapshot>();
const files = createFileProvider(
getLanguagePlugins(options),
getLanguagePlugins(ts, options),
ts.sys.useCaseSensitiveFileNames,
fileName => {
let snapshot: ts.IScriptSnapshot | undefined;
Expand Down
8 changes: 4 additions & 4 deletions packages/typescript/lib/starters/runTsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import * as fs from 'fs';
import type * as ts from 'typescript/lib/tsserverlibrary';
import type { LanguagePlugin } from '@volar/language-core';

export let getLanguagePlugins: (options: ts.CreateProgramOptions) => LanguagePlugin[] = () => [];
export let getLanguagePlugins: (ts: typeof import('typescript/lib/tsserverlibrary'), options: ts.CreateProgramOptions) => LanguagePlugin[] = () => [];

export function runTsc(
tscPath: string,
extensions: string[],
_getLanguagePlugins: (options: ts.CreateProgramOptions) => LanguagePlugin[],
_getLanguagePlugins: typeof getLanguagePlugins,
) {

getLanguagePlugins = _getLanguagePlugins;

const proxyApiPath = require.resolve('../node/proxyCreateProgram');
const currentFilePath = require.resolve('./runTsc');
const tscPath = require.resolve('typescript/lib/tsc');
const readFileSync = fs.readFileSync;

(fs as any).readFileSync = (...args: any[]) => {
Expand All @@ -32,7 +32,7 @@ export function runTsc(
+ `new Proxy({}, { get(_target, p, _receiver) {return eval(p); } } ), `
+ `_createProgram, `
+ `[${extsText}], `
+ `require(${currentFilePath}).getLanguagePlugins`
+ `require(${JSON.stringify(currentFilePath)}).getLanguagePlugins`
+ `);\n`
+ s.replace('createProgram', '_createProgram')
);
Expand Down

0 comments on commit 26d12e1

Please sign in to comment.