44 *--------------------------------------------------------------------------------------------*/
55
66import * as vscode from 'vscode' ;
7+ import path from 'path' ;
8+
79import { getPreview , getPageView } from './export_command/wikimedia_function/view' ;
810import { login , logout } from './export_command/wikimedia_function/bot' ;
911import { postPage , pullPage , closeEditor } from './export_command/wikimedia_function/page' ;
@@ -29,8 +31,52 @@ export function activate(context: vscode.ExtensionContext): void {
2931 context . subscriptions . push ( vscode . commands . registerCommand ( "wikitext.viewPage" , getPageView ) ) ;
3032 // Cite
3133 context . subscriptions . push ( vscode . commands . registerCommand ( "wikitext.citeWeb" , addWebCite ) ) ;
34+
35+ configureLuaLibrary ( "Scribunto" , true ) ;
3236}
3337
3438export function deactivate ( ) : void {
35- 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+ }
3682}
0 commit comments