@@ -4,7 +4,6 @@ import vscode = require("vscode");
4
4
import * as semver from "semver" ;
5
5
6
6
import { AtelierJob } from "./api/atelier" ;
7
- const { workspace, window } = vscode ;
8
7
export const OBJECTSCRIPT_FILE_SCHEMA = "objectscript" ;
9
8
export const OBJECTSCRIPTXML_FILE_SCHEMA = "objectscriptxml" ;
10
9
export const FILESYSTEM_SCHEMA = "isfs" ;
@@ -549,136 +548,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
549
548
checkConnection ( true , uri ) . finally ( ) ;
550
549
}
551
550
552
- vscode . workspace . onDidChangeWorkspaceFolders ( async ( { added, removed } ) => {
553
- const folders = vscode . workspace . workspaceFolders ;
554
-
555
- // Make sure we have a resolved connection spec for the targets of all added folders
556
- const toCheck = new Map < string , vscode . Uri > ( ) ;
557
- added . map ( ( workspaceFolder ) => {
558
- const uri = workspaceFolder . uri ;
559
- const { configName } = connectionTarget ( uri ) ;
560
- toCheck . set ( configName , uri ) ;
561
- } ) ;
562
- for await ( const oneToCheck of toCheck ) {
563
- const configName = oneToCheck [ 0 ] ;
564
- const uri = oneToCheck [ 1 ] ;
565
- const serverName = uri . scheme === "file" ? config ( "conn" , configName ) . server : configName ;
566
- await resolveConnectionSpec ( serverName ) ;
567
- }
568
-
569
- // If it was just the addition of the first folder, and this is one of the isfs types, hide the ObjectScript Explorer for this workspace
570
- if (
571
- folders ?. length === 1 &&
572
- added ?. length === 1 &&
573
- removed ?. length === 0 &&
574
- filesystemSchemas . includes ( added [ 0 ] . uri . scheme )
575
- ) {
576
- vscode . workspace
577
- . getConfiguration ( "objectscript" )
578
- . update ( "showExplorer" , false , vscode . ConfigurationTarget . Workspace ) ;
579
- }
580
- } ) ;
581
-
582
- vscode . workspace . onDidChangeConfiguration ( async ( { affectsConfiguration } ) => {
583
- if ( affectsConfiguration ( "objectscript.conn" ) || affectsConfiguration ( "intersystems.servers" ) ) {
584
- if ( affectsConfiguration ( "intersystems.servers" ) ) {
585
- // Gather the server names previously resolved
586
- const resolvedServers : string [ ] = [ ] ;
587
- resolvedConnSpecs . forEach ( ( v , k ) => resolvedServers . push ( k ) ) ;
588
- // Clear the cache
589
- resolvedConnSpecs . clear ( ) ;
590
- // Resolve them again, sequentially in case user needs to be prompted for credentials
591
- for await ( const serverName of resolvedServers ) {
592
- await resolveConnectionSpec ( serverName ) ;
593
- }
594
- }
595
- // Check connections sequentially for each workspace folder
596
- let refreshFilesExplorer = false ;
597
- for await ( const folder of vscode . workspace . workspaceFolders ) {
598
- if ( schemas . includes ( folder . uri . scheme ) ) {
599
- refreshFilesExplorer = true ;
600
- }
601
- try {
602
- await checkConnection ( true , folder . uri ) ;
603
- } catch ( _ ) {
604
- continue ;
605
- }
606
- }
607
- explorerProvider . refresh ( ) ;
608
- projectsExplorerProvider . refresh ( ) ;
609
- if ( refreshFilesExplorer ) {
610
- // This unavoidably switches to the File Explorer view, so only do it if isfs folders were found
611
- vscode . commands . executeCommand ( "workbench.files.action.refreshFilesExplorer" ) ;
612
- }
613
- }
614
- } ) ;
615
- vscode . window . onDidCloseTerminal ( ( t ) => {
616
- const terminalIndex = terminals . findIndex ( ( terminal ) => terminal . name == t . name ) ;
617
- if ( terminalIndex > - 1 ) {
618
- terminals . splice ( terminalIndex , 1 ) ;
619
- }
620
- } ) ;
621
-
622
- workspace . onDidSaveTextDocument ( ( file ) => {
623
- if ( schemas . includes ( file . uri . scheme ) || languages . includes ( file . languageId ) ) {
624
- if ( documentBeingProcessed !== file ) {
625
- return importAndCompile ( false , file , config ( "compileOnSave" ) ) ;
626
- }
627
- } else if ( file . uri . scheme === "file" ) {
628
- if ( isImportableLocalFile ( file ) ) {
629
- // This local file is part of a CSP application
630
- // or matches our export settings, so import it on save
631
- return importFileOrFolder ( file . uri , true ) ;
632
- }
633
- }
634
- } ) ;
635
-
636
- vscode . window . onDidChangeActiveTextEditor ( async ( textEditor : vscode . TextEditor ) => {
637
- await checkConnection ( false , textEditor ?. document . uri ) ;
638
- posPanel . text = "" ;
639
- if ( textEditor ?. document . fileName . endsWith ( ".xml" ) && config ( "autoPreviewXML" ) ) {
640
- return xml2doc ( context , textEditor ) ;
641
- }
642
- } ) ;
643
- vscode . window . onDidChangeTextEditorSelection ( ( event : vscode . TextEditorSelectionChangeEvent ) => {
644
- posPanel . text = "" ;
645
- const document = event . textEditor . document ;
646
- if ( ! [ "objectscript" , "objectscript-int" ] . includes ( document . languageId ) ) {
647
- return ;
648
- }
649
- if ( event . selections . length > 1 || ! event . selections [ 0 ] . isEmpty ) {
650
- return ;
651
- }
652
-
653
- const file = currentFile ( document ) ;
654
- const nameMatch = file . name . match ( / ( .* ) \. ( i n t | m a c ) $ / i) ;
655
- if ( ! nameMatch ) {
656
- return ;
657
- }
658
- const [ , routine ] = nameMatch ;
659
- let label = "" ;
660
- let pos = 0 ;
661
- vscode . commands
662
- . executeCommand < vscode . DocumentSymbol [ ] > ( "vscode.executeDocumentSymbolProvider" , document . uri )
663
- . then ( ( symbols ) => {
664
- if ( symbols != undefined ) {
665
- const cursor = event . selections [ 0 ] . active ;
666
- if ( symbols . length == 0 || cursor . isBefore ( symbols [ 0 ] . range . start ) ) {
667
- pos = cursor . line - 1 ;
668
- } else {
669
- for ( const symbol of symbols ) {
670
- if ( symbol . range . contains ( cursor ) ) {
671
- label = symbol . name ;
672
- pos = cursor . line - symbol . range . start . line ;
673
- break ;
674
- }
675
- }
676
- }
677
- posPanel . text = `${ label } ${ pos > 0 ? "+" + pos : "" } ^${ routine } ` ;
678
- }
679
- } ) ;
680
- } ) ;
681
-
682
551
const documentSelector = ( ...list ) =>
683
552
[ "file" , ...schemas ] . reduce ( ( acc , scheme ) => acc . concat ( list . map ( ( language ) => ( { scheme, language } ) ) ) , [ ] ) ;
684
553
@@ -726,10 +595,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
726
595
diagnosticProvider . updateDiagnostics ( vscode . window . activeTextEditor . document ) ;
727
596
}
728
597
noLSsubscriptions . push (
729
- workspace . onDidChangeTextDocument ( ( event ) => {
598
+ vscode . workspace . onDidChangeTextDocument ( ( event ) => {
730
599
diagnosticProvider . updateDiagnostics ( event . document ) ;
731
600
} ) ,
732
- window . onDidChangeActiveTextEditor ( async ( editor ) => {
601
+ vscode . window . onDidChangeActiveTextEditor ( async ( editor ) => {
733
602
if ( editor ) {
734
603
diagnosticProvider . updateDiagnostics ( editor . document ) ;
735
604
}
@@ -799,7 +668,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
799
668
} ) ;
800
669
}
801
670
} ) ,
802
- workspace . onDidChangeTextDocument ( ( event ) => {
671
+ vscode . workspace . onDidChangeTextDocument ( ( event ) => {
803
672
if (
804
673
event . contentChanges . length !== 0 &&
805
674
event . document . uri . scheme === FILESYSTEM_SCHEMA &&
@@ -811,8 +680,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
811
680
checkChangedOnServer ( currentFile ( event . document ) ) ;
812
681
}
813
682
} ) ,
814
- window . onDidChangeActiveTextEditor ( async ( editor ) => {
815
- if ( workspace . workspaceFolders && workspace . workspaceFolders . length > 1 ) {
683
+ vscode . window . onDidChangeActiveTextEditor ( async ( editor ) => {
684
+ if ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 1 ) {
816
685
const workspaceFolder = currentWorkspaceFolder ( ) ;
817
686
if ( workspaceFolder && workspaceFolder !== workspaceState . get < string > ( "workspaceFolder" ) ) {
818
687
workspaceState . update ( "workspaceFolder" , workspaceFolder ) ;
@@ -939,7 +808,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
939
808
}
940
809
) ,
941
810
vscode . commands . registerCommand ( "vscode-objectscript.previewXml" , ( ) => {
942
- xml2doc ( context , window . activeTextEditor ) ;
811
+ xml2doc ( context , vscode . window . activeTextEditor ) ;
943
812
} ) ,
944
813
vscode . commands . registerCommand ( "vscode-objectscript.addServerNamespaceToWorkspace" , ( ) => {
945
814
addServerNamespaceToWorkspace ( ) ;
@@ -1082,6 +951,132 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
1082
951
vscode . commands . registerCommand ( "vscode-objectscript.explorer.project.addWorkspaceFolderForProject" , ( node ) =>
1083
952
addWorkspaceFolderForProject ( node )
1084
953
) ,
954
+ vscode . workspace . onDidChangeWorkspaceFolders ( async ( { added, removed } ) => {
955
+ const folders = vscode . workspace . workspaceFolders ;
956
+
957
+ // Make sure we have a resolved connection spec for the targets of all added folders
958
+ const toCheck = new Map < string , vscode . Uri > ( ) ;
959
+ added . map ( ( workspaceFolder ) => {
960
+ const uri = workspaceFolder . uri ;
961
+ const { configName } = connectionTarget ( uri ) ;
962
+ toCheck . set ( configName , uri ) ;
963
+ } ) ;
964
+ for await ( const oneToCheck of toCheck ) {
965
+ const configName = oneToCheck [ 0 ] ;
966
+ const uri = oneToCheck [ 1 ] ;
967
+ const serverName = uri . scheme === "file" ? config ( "conn" , configName ) . server : configName ;
968
+ await resolveConnectionSpec ( serverName ) ;
969
+ }
970
+
971
+ // If it was just the addition of the first folder, and this is one of the isfs types, hide the ObjectScript Explorer for this workspace
972
+ if (
973
+ folders ?. length === 1 &&
974
+ added ?. length === 1 &&
975
+ removed ?. length === 0 &&
976
+ filesystemSchemas . includes ( added [ 0 ] . uri . scheme )
977
+ ) {
978
+ vscode . workspace
979
+ . getConfiguration ( "objectscript" )
980
+ . update ( "showExplorer" , false , vscode . ConfigurationTarget . Workspace ) ;
981
+ }
982
+ } ) ,
983
+ vscode . workspace . onDidChangeConfiguration ( async ( { affectsConfiguration } ) => {
984
+ if ( affectsConfiguration ( "objectscript.conn" ) || affectsConfiguration ( "intersystems.servers" ) ) {
985
+ if ( affectsConfiguration ( "intersystems.servers" ) ) {
986
+ // Gather the server names previously resolved
987
+ const resolvedServers : string [ ] = [ ] ;
988
+ resolvedConnSpecs . forEach ( ( v , k ) => resolvedServers . push ( k ) ) ;
989
+ // Clear the cache
990
+ resolvedConnSpecs . clear ( ) ;
991
+ // Resolve them again, sequentially in case user needs to be prompted for credentials
992
+ for await ( const serverName of resolvedServers ) {
993
+ await resolveConnectionSpec ( serverName ) ;
994
+ }
995
+ }
996
+ // Check connections sequentially for each workspace folder
997
+ let refreshFilesExplorer = false ;
998
+ for await ( const folder of vscode . workspace . workspaceFolders ) {
999
+ if ( schemas . includes ( folder . uri . scheme ) ) {
1000
+ refreshFilesExplorer = true ;
1001
+ }
1002
+ try {
1003
+ await checkConnection ( true , folder . uri ) ;
1004
+ } catch ( _ ) {
1005
+ continue ;
1006
+ }
1007
+ }
1008
+ explorerProvider . refresh ( ) ;
1009
+ projectsExplorerProvider . refresh ( ) ;
1010
+ if ( refreshFilesExplorer ) {
1011
+ // This unavoidably switches to the File Explorer view, so only do it if isfs folders were found
1012
+ vscode . commands . executeCommand ( "workbench.files.action.refreshFilesExplorer" ) ;
1013
+ }
1014
+ }
1015
+ } ) ,
1016
+ vscode . window . onDidCloseTerminal ( ( t ) => {
1017
+ const terminalIndex = terminals . findIndex ( ( terminal ) => terminal . name == t . name ) ;
1018
+ if ( terminalIndex > - 1 ) {
1019
+ terminals . splice ( terminalIndex , 1 ) ;
1020
+ }
1021
+ } ) ,
1022
+ vscode . workspace . onDidSaveTextDocument ( ( file ) => {
1023
+ if ( schemas . includes ( file . uri . scheme ) || languages . includes ( file . languageId ) ) {
1024
+ if ( documentBeingProcessed !== file ) {
1025
+ return importAndCompile ( false , file , config ( "compileOnSave" ) ) ;
1026
+ }
1027
+ } else if ( file . uri . scheme === "file" ) {
1028
+ if ( isImportableLocalFile ( file ) ) {
1029
+ // This local file is part of a CSP application
1030
+ // or matches our export settings, so import it on save
1031
+ return importFileOrFolder ( file . uri , true ) ;
1032
+ }
1033
+ }
1034
+ } ) ,
1035
+ vscode . window . onDidChangeActiveTextEditor ( async ( textEditor : vscode . TextEditor ) => {
1036
+ await checkConnection ( false , textEditor ?. document . uri ) ;
1037
+ posPanel . text = "" ;
1038
+ if ( textEditor ?. document . fileName . endsWith ( ".xml" ) && config ( "autoPreviewXML" ) ) {
1039
+ return xml2doc ( context , textEditor ) ;
1040
+ }
1041
+ } ) ,
1042
+ vscode . window . onDidChangeTextEditorSelection ( ( event : vscode . TextEditorSelectionChangeEvent ) => {
1043
+ posPanel . text = "" ;
1044
+ const document = event . textEditor . document ;
1045
+ if ( ! [ "objectscript" , "objectscript-int" ] . includes ( document . languageId ) ) {
1046
+ return ;
1047
+ }
1048
+ if ( event . selections . length > 1 || ! event . selections [ 0 ] . isEmpty ) {
1049
+ return ;
1050
+ }
1051
+
1052
+ const file = currentFile ( document ) ;
1053
+ const nameMatch = file . name . match ( / ( .* ) \. ( i n t | m a c ) $ / i) ;
1054
+ if ( ! nameMatch ) {
1055
+ return ;
1056
+ }
1057
+ const [ , routine ] = nameMatch ;
1058
+ let label = "" ;
1059
+ let pos = 0 ;
1060
+ vscode . commands
1061
+ . executeCommand < vscode . DocumentSymbol [ ] > ( "vscode.executeDocumentSymbolProvider" , document . uri )
1062
+ . then ( ( symbols ) => {
1063
+ if ( symbols != undefined ) {
1064
+ const cursor = event . selections [ 0 ] . active ;
1065
+ if ( symbols . length == 0 || cursor . isBefore ( symbols [ 0 ] . range . start ) ) {
1066
+ pos = cursor . line - 1 ;
1067
+ } else {
1068
+ for ( const symbol of symbols ) {
1069
+ if ( symbol . range . contains ( cursor ) ) {
1070
+ label = symbol . name ;
1071
+ pos = cursor . line - symbol . range . start . line ;
1072
+ break ;
1073
+ }
1074
+ }
1075
+ }
1076
+ posPanel . text = `${ label } ${ pos > 0 ? "+" + pos : "" } ^${ routine } ` ;
1077
+ }
1078
+ } ) ;
1079
+ } ) ,
1085
1080
1086
1081
/* Anything we use from the VS Code proposed API */
1087
1082
...proposed
0 commit comments