@@ -28,6 +28,7 @@ import { activateTagClosing } from './html/autoClose';
2828import { EMPTY_ELEMENTS } from './html/htmlEmptyTagsShared' ;
2929import CompiledCodeContentProvider from './CompiledCodeContentProvider' ;
3030import * as path from 'path' ;
31+ import { readFileSync , writeFileSync } from 'fs' ;
3132
3233namespace TagCloseRequest {
3334 export const type : RequestType < TextDocumentPositionParams , string , any > = new RequestType (
@@ -172,6 +173,8 @@ export function activate(context: ExtensionContext) {
172173
173174 addExtracComponentCommand ( getLS , context ) ;
174175
176+ context . subscriptions . push ( commands . registerCommand ( 'svelte.toggleTsPlugin' , toggleTsPlugin ) ) ;
177+
175178 languages . setLanguageConfiguration ( 'svelte' , {
176179 indentationRules : {
177180 // Matches a valid opening tag that is:
@@ -384,6 +387,46 @@ function addExtracComponentCommand(getLS: () => LanguageClient, context: Extensi
384387 ) ;
385388}
386389
390+ function toggleTsPlugin ( ) {
391+ const extension = extensions . getExtension ( 'svelte.svelte-vscode' ) ;
392+ if ( ! extension ) {
393+ // This shouldn't be possible
394+ return ;
395+ }
396+
397+ const packageJson = path . join ( extension . extensionPath , 'package.json' ) ;
398+ const enabled = '"typescriptServerPlugins"' ;
399+ const disabled = '"typescriptServerPlugins-disabled"' ;
400+ try {
401+ const packageText = readFileSync ( packageJson , 'utf8' ) ;
402+ if ( packageText . includes ( disabled ) ) {
403+ const newText = packageText . replace ( disabled , enabled ) ;
404+ writeFileSync ( packageJson , newText , 'utf8' ) ;
405+ showReload ( true ) ;
406+ } else if ( packageText . includes ( enabled ) ) {
407+ const newText = packageText . replace ( enabled , disabled ) ;
408+ writeFileSync ( packageJson , newText , 'utf8' ) ;
409+ showReload ( false ) ;
410+ } else {
411+ window . showWarningMessage ( 'Unknown Svelte for VS Code package.json status.' ) ;
412+ }
413+ } catch ( err ) {
414+ window . showWarningMessage ( 'Svelte for VS Code package.json update failed.' ) ;
415+ }
416+
417+ async function showReload ( enabled : boolean ) {
418+ const reload = await window . showInformationMessage (
419+ ` TypeScript Svelte Plugin ${
420+ enabled ? 'enabled' : 'disabled'
421+ } , please reload VS Code to restart the TS Server.`,
422+ 'Reload Window'
423+ ) ;
424+ if ( reload ) {
425+ commands . executeCommand ( 'workbench.action.reloadWindow' ) ;
426+ }
427+ }
428+ }
429+
387430function createLanguageServer ( serverOptions : ServerOptions , clientOptions : LanguageClientOptions ) {
388431 return new LanguageClient ( 'svelte' , 'Svelte' , serverOptions , clientOptions ) ;
389432}
0 commit comments