44 *--------------------------------------------------------------------------------------------*/
55
66import * as vscode from 'vscode' ;
7+ import path from 'path' ;
78import { getPageViewFactory , getPreviewFactory } from './export_command/wikimedia_function/view' ;
89import { loginFactory , logoutFactory } from './export_command/wikimedia_function/bot' ;
910import { closeEditorFactory , postPageFactory , pullPageFactory } from './export_command/wikimedia_function/page' ;
@@ -30,8 +31,52 @@ export function activate(context: vscode.ExtensionContext): void {
3031 commandRegistrar . register ( 'viewPage' , getPageViewFactory ) ;
3132 // Cite
3233 commandRegistrar . register ( 'citeWeb' , addWebCiteFactory ) ;
34+
35+ configureLuaLibrary ( "Scribunto" , true ) ;
3336}
3437
3538export function deactivate ( ) : void {
36- console . log ( "Extension is deactivate." ) ;
39+ console . log ( "Extension is inactive." ) ;
40+ configureLuaLibrary ( "Scribunto" , false ) ;
41+ }
42+
43+ export function configureLuaLibrary ( folder : string , enable : boolean ) {
44+ const extensionId = "rowewilsonfrederiskholme.wikitext" ;
45+ const extensionPath = vscode . extensions . getExtension ( extensionId ) ?. extensionPath ;
46+ if ( extensionPath === undefined ) {
47+ return ;
48+ }
49+
50+ // Use path.join to ensure the proper path seperators are used.
51+ const folderPath = path . join ( extensionPath , "EmmyLua" , folder ) ;
52+ const config = vscode . workspace . getConfiguration ( "Lua" ) ;
53+ const library : string [ ] | undefined = config . get ( "workspace.library" ) ;
54+ if ( library === undefined ) {
55+ return ;
56+ }
57+
58+ if ( library && extensionPath ) {
59+ // remove any older versions of our path
60+ for ( let i = library . length - 1 ; i >= 0 ; i -- ) {
61+ const item = library [ i ] ;
62+ const isSelfExtension = item . indexOf ( extensionId ) > - 1 ;
63+ const isCurrentVersion = item . indexOf ( extensionPath ) > - 1 ;
64+ if ( isSelfExtension && ! isCurrentVersion ) {
65+ library . splice ( i , 1 ) ;
66+ }
67+ }
68+
69+ const index = library . indexOf ( folderPath ) ;
70+ if ( enable ) {
71+ if ( index === - 1 ) {
72+ library . push ( folderPath ) ;
73+ }
74+ }
75+ else {
76+ if ( index > - 1 ) {
77+ library . splice ( index , 1 ) ;
78+ }
79+ }
80+ config . update ( "workspace.library" , library , true ) ;
81+ }
3782}
0 commit comments