import { EXTENSION_TS_PLUGIN , TS_LANGUAGE_FEATURES_EXTENSION , } from "./constants" ; import type { PluginSettings , TsApi } from "./types" ; import { assert } from "./util" ; import * as vscode from "vscode" ; interface TsLanguageFeatures { getAPI ( version ) : TsLanguageFeaturesApiV0 | undefined ; } interface TsLanguageFeaturesApiV0 { configurePlugin ( pluginId , configuration ) : void ; } export function getTsApi ( getPluginSettings ) { let api ; ( async ( ) => { try { const extension = vscode . extensions . getExtension ( TS_LANGUAGE_FEATURES_EXTENSION ) ; const errorMessage = "The Deno extension cannot load the built in TypeScript Language Features. Please try restarting Visual Studio Code." ; assert ( extension , errorMessage ) ; const languageFeatures = await extension . activate ( ) ; api = languageFeatures . getAPI ( 0 ) ; assert ( api , errorMessage ) ; const pluginSettings = getPluginSettings ( ) ; api . configurePlugin ( EXTENSION_TS_PLUGIN , pluginSettings ) ; } catch ( e ) { const msg = `Cannot get internal TypeScript plugin configuration API.${ e instanceof Error ? ` (${ e . name }: ${ e . message })` : "" }` ; await vscode . window . showErrorMessage ( msg ) ; } } ) ( ) ; return { refresh ( ) { if ( api ) { const pluginSettings = getPluginSettings ( ) ; api . configurePlugin ( EXTENSION_TS_PLUGIN , pluginSettings ) ; } } , } ; }