-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Can we use tsserver plugins with shiki-twoslash? #170
Comments
It doesn't seem massively outside of the scope for supporting it IMO, we do host a TSServer. If the diff is reasonable and well tested, I'd be open to support. |
As far as I understand Where should I look to start a PR? |
I think we might need to emulate some the commands sent from the language service to look like the ones sent from the tsserver process - I think they might be pretty much pass throughs in the tsc codebase |
diff --git a/packages/typescript-vfs/src/index.ts b/packages/typescript-vfs/src/index.ts
index 453dcf9b..e7c99c39 100755
--- a/packages/typescript-vfs/src/index.ts
+++ b/packages/typescript-vfs/src/index.ts
@@ -5,6 +5,7 @@ type LanguageServiceHost = import("typescript").LanguageServiceHost
type CompilerHost = import("typescript").CompilerHost
type SourceFile = import("typescript").SourceFile
type TS = typeof import("typescript")
+type PluginModuleFactory = import("typescript/lib/tsserverlibrary").server.PluginModuleFactory
let hasLocalStorage = false
try {
@@ -39,7 +40,8 @@ export function createVirtualTypeScriptEnvironment(
rootFiles: string[],
ts: TS,
compilerOptions: CompilerOptions = {},
- customTransformers?: CustomTransformers
+ customTransformers?: CustomTransformers,
+ plugins: PluginModuleFactory[] = []
): VirtualTypeScriptEnvironment {
const mergedCompilerOpts = { ...defaultCompilerOptions(ts), ...compilerOptions }
@@ -50,7 +52,16 @@ export function createVirtualTypeScriptEnvironment(
ts,
customTransformers
)
- const languageService = ts.createLanguageService(languageServiceHost)
+ const languageService = plugins.reduce((languageService, plugin) => {
+ return plugin({ typescript: ts }).create({
+ languageService,
+ languageServiceHost,
+ project: null as any, // ??
+ config: {},
+ serverHost: {} as any, // create severHost
+ })
+ }, ts.createLanguageService(languageServiceHost))
+ // TODO: Enable plugins
const diagnostics = languageService.getCompilerOptionsDiagnostics()
if (diagnostics.length) { |
No description provided.
The text was updated successfully, but these errors were encountered: