@@ -17,19 +17,36 @@ import {
1717} from 'vscode-languageclient/node' ;
1818
1919let client : LanguageClient ;
20+ let languageServerRunning = false ;
21+ const ZSconfig = vscode . workspace . getConfiguration ( 'ZeroSyntax' ) ;
2022
2123export function activate ( context : vscode . ExtensionContext ) {
2224
2325 // const command = "extension.formatDocument";
2426
2527 // context.subscriptions.push(vscode.commands.registerCommand(command, formatDocument));
2628
29+ let languageServerRunning = ZSconfig . get < boolean > ( 'serverStartupSetting' , false ) ; // Default to 2 if not set
30+
2731 context . subscriptions . push ( vscode . languages . registerDocumentFormattingEditProvider ( 'ini' , {
2832 provideDocumentFormattingEdits : ( document : vscode . TextDocument ) : vscode . TextEdit [ ] => {
2933 return formatDocument ( document ) ;
3034 }
3135 } ) ) ;
3236
37+ context . subscriptions . push ( vscode . commands . registerCommand ( 'ZeroSyntax.stopLanguageServer' , ( ) => {
38+ if ( languageServerRunning ) {
39+ client . stop ( ) ;
40+ languageServerRunning = false ;
41+ }
42+ } ) ) ;
43+ context . subscriptions . push ( vscode . commands . registerCommand ( 'ZeroSyntax.startLanguageServer' , ( ) => {
44+ if ( ! languageServerRunning ) {
45+ client . start ( ) ;
46+ languageServerRunning = true ;
47+ }
48+ } ) ) ;
49+
3350 // The server is implemented in node
3451 const serverModule = context . asAbsolutePath (
3552 path . join ( 'server' , 'out' , 'server.js' )
@@ -66,15 +83,16 @@ export function activate(context: vscode.ExtensionContext) {
6683 ) ;
6784
6885 // Start the client. This will also launch the server
69- client . start ( ) ;
86+ if ( languageServerRunning ) {
87+ client . start ( ) ;
88+ }
7089}
7190
7291function formatDocument ( document : vscode . TextDocument ) : vscode . TextEdit [ ] {
7392 const edits : vscode . TextEdit [ ] = [ ] ;
7493 let indentlevel = 0 ;
7594
76- const config = vscode . workspace . getConfiguration ( 'ZeroSyntax' ) ;
77- const indentSize = config . get < number > ( 'indentNumber' , 2 ) ; // Default to 2 if not set
95+ const indentSize = ZSconfig . get < number > ( 'indentNumber' , 2 ) ; // Default to 2 if not set
7896
7997 let ObjectsRegex = [ "^\\b([Oo]bject)\\s+[a-zA-Z0-9_]" , "^\\b([Oo]bject[Rr]eskin)\\s+[a-zA-Z0-9_]" , "^\\b([Aa]dd[Mm]odule)$" , "^\\b([Rr]eplace[Mm]odule)$" , "^\\b([Dd]efault[Cc]ondition[Ss]tate)$" , "^\\b([Uu]nit[Ss]pecific[Ss]ounds)$" , "^\\b([Pp]rerequisites)$" , "^\\b([Aa]rmor[Ss]et)$" , "^\\b([Ww]eapon[Ss]et)$" , "^\\b([Dd]raw)\\s*=" , "^\\b([Cc]ondition[Ss]tate)\\s*=" , "^\\b([Tt]ransition[Ss]tate)\\s*=" , "^\\b([Bb]ody)\\s*=" , "^\\b([Bb]ehavior)\\s*=" , "^\\b([Cc]lient[Uu]pdate)\\s*=" , "^\\b(Turret)$" ] ;
8098 let SimpleClassesRegex = [ "^\\b([Mm]apped[Ii]mage)\\s+[a-zA-Z0-9_]" , "^\\b([Pp]article[Ss]ystem)\\s+[a-zA-Z0-9_]" , "^\\b([Ll]ocomotor)\\s+[a-zA-Z0-9_]" , "^\\b([Aa]udio[Ee]vent)\\s+[a-zA-Z0-9_]" , "^\\b([Dd]ialog[Ee]vent)\\s+[a-zA-Z0-9_]" , "^\\b([Aa]rmor)\\s+[a-zA-Z0-9_]" , "^\\b([Cc]ommand[Ss]et)\\s+[a-zA-Z0-9_]" , "^\\b([Cc]ommand[Bb]utton)\\s+[a-zA-Z0-9_]" , "^\\b([Ww]eapon)\\s+[a-zA-Z0-9_]" , "^\\b([Dd]amage[Ff][Xx])\\s+[A-Za-z0-9_]" , "^\\b([Uu]pgrade)\\s+[a-zA-Z0-9_]" , "^\\b([Pp]layer[Tt]emplate)\\s+[a-zA-Z0-9_]" , "^\\b(Rank)\\s+[1-8]$" , "^\\b([Ii]n[Gg]ame[Uu][Ii])$" , "^\\b(A10StrikeRadiusCursor)$" , "^\\b(AmbushRadiusCursor)$" , "^\\b(ClusterMinesRadiusCursor)$" , "^\\b(AnthraxBombRadiusCursor)$" ] ;
@@ -128,6 +146,23 @@ function checkLineWithRegex(line: string, regex: string) {
128146 return Regex . test ( line ) ;
129147}
130148
149+ vscode . workspace . onDidChangeConfiguration ( ( e ) => {
150+ if ( e . affectsConfiguration ( 'ZeroSyntax.serverStartupSetting' ) ) {
151+ languageServerRunning = ZSconfig . get < boolean > ( 'serverStartupSetting' , false ) ;
152+ toggleLanguageServer ( ) ;
153+ }
154+ } ) ;
155+
156+ function toggleLanguageServer ( ) {
157+ if ( languageServerRunning ) {
158+ client . stop ( ) ;
159+ languageServerRunning = false ;
160+ } else {
161+ client . start ( ) ;
162+ languageServerRunning = true ;
163+ }
164+ }
165+
131166export function deactivate ( ) : Thenable < void > | undefined {
132167 if ( ! client ) {
133168 return undefined ;
0 commit comments