@@ -70,7 +70,8 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
70
70
extendedClientCapabilities :{
71
71
progressReportProvider : getJavaConfiguration ( ) . get ( 'progressReports.enabled' ) ,
72
72
classFileContentsSupport :true
73
- }
73
+ } ,
74
+ triggerFiles : getTriggerFiles ( )
74
75
} ,
75
76
revealOutputChannelOn : RevealOutputChannelOn . Never
76
77
} ;
@@ -690,3 +691,55 @@ async function executeRangeFormat(editor, startPosition, lineOffset) {
690
691
editor . selection = new Selection ( startPosition , endPosition ) ;
691
692
await commands . executeCommand ( 'editor.action.formatSelection' ) ;
692
693
}
694
+
695
+ function getTriggerFiles ( ) : string [ ] {
696
+ const openedJavaFiles = [ ] ;
697
+ const activeJavaFile = getJavaFilePathOfTextEditor ( window . activeTextEditor ) ;
698
+ if ( activeJavaFile ) {
699
+ openedJavaFiles . push ( Uri . file ( activeJavaFile ) . toString ( ) ) ;
700
+ }
701
+
702
+ if ( ! workspace . workspaceFolders ) {
703
+ return openedJavaFiles ;
704
+ }
705
+
706
+ for ( const rootFolder of workspace . workspaceFolders ) {
707
+ if ( rootFolder . uri . scheme !== "file" ) {
708
+ continue ;
709
+ }
710
+
711
+ const rootPath = path . normalize ( rootFolder . uri . fsPath ) ;
712
+ if ( isPrefix ( rootPath , activeJavaFile ) ) {
713
+ continue ;
714
+ }
715
+
716
+ for ( const textEditor of window . visibleTextEditors ) {
717
+ const javaFileInTextEditor = getJavaFilePathOfTextEditor ( textEditor ) ;
718
+ if ( isPrefix ( rootPath , javaFileInTextEditor ) ) {
719
+ openedJavaFiles . push ( Uri . file ( javaFileInTextEditor ) . toString ( ) ) ;
720
+ break ;
721
+ }
722
+ }
723
+ }
724
+
725
+ return openedJavaFiles ;
726
+ }
727
+
728
+ function getJavaFilePathOfTextEditor ( editor : TextEditor ) : string | undefined {
729
+ if ( editor ) {
730
+ const resource = editor . document . uri ;
731
+ if ( resource . scheme === "file" && resource . fsPath . endsWith ( ".java" ) ) {
732
+ return path . normalize ( resource . fsPath ) ;
733
+ }
734
+ }
735
+
736
+ return undefined ;
737
+ }
738
+
739
+ function isPrefix ( parentPath : string , childPath : string ) : boolean {
740
+ if ( ! childPath ) {
741
+ return false ;
742
+ }
743
+ const relative = path . relative ( parentPath , childPath ) ;
744
+ return ! ! relative && ! relative . startsWith ( '..' ) && ! path . isAbsolute ( relative ) ;
745
+ }
0 commit comments