102102@ Component
103103public class SpringSymbolIndex implements InitializingBean , SpringIndex {
104104
105+ private static final String QUERY_PARAM_LOCATION_PREFIX = "locationPrefix:" ;
106+ private static final String OUTLINE_SYMBOLS_FROM_INDEX_PROPERTY = "outlineSymbolsFromIndex" ;
107+
105108 @ Autowired SimpleLanguageServer server ;
106109 @ Autowired BootJavaConfig config ;
107110 @ Autowired BootLanguageServerParams params ;
@@ -112,8 +115,6 @@ public class SpringSymbolIndex implements InitializingBean, SpringIndex {
112115 @ Autowired JdtReconciler jdtReconciler ;
113116 @ Autowired CompilationUnitCache cuCache ;
114117
115- private static final String QUERY_PARAM_LOCATION_PREFIX = "locationPrefix:" ;
116-
117118 private final List <WorkspaceSymbol > symbols = new ArrayList <>();
118119
119120 private final ConcurrentMap <String , List <WorkspaceSymbol >> symbolsByDoc = new ConcurrentHashMap <>();
@@ -698,70 +699,28 @@ synchronized private CompletableFuture<IJavaProject> projectInitializedFuture(IJ
698699 }
699700
700701 public List <? extends WorkspaceSymbol > getSymbols (String docURI ) {
701- try {
702- TextDocument doc = server .getTextDocumentService ().getLatestSnapshot (docURI );
703- URI uri = URI .create (docURI );
704- CompletableFuture <IJavaProject > projectInitialized = futureProjectFinder .findFuture (uri ).thenCompose (project -> projectInitializedFuture (project ));
705- IJavaProject project = projectInitialized .get (15 , TimeUnit .SECONDS );
706- ImmutableList .Builder <WorkspaceSymbol > builder = ImmutableList .builder ();
707- if (project != null && doc != null ) {
708- // Collect symbols from the opened document
709- synchronized (this ) {
710- for (SpringIndexer indexer : this .indexers ) {
711- if (indexer .isInterestedIn (docURI )) {
712- try {
713- for (WorkspaceSymbol enhanced : indexer .computeSymbols (project , docURI ,
714- doc .get ())) {
715- builder .add (enhanced );
716- }
717- } catch (Exception e ) {
718- log .error ("{}" , e );
719- }
720- }
721- }
722- }
723- } else {
724- // Take symbols from the index if there is no opened document.
725- List <WorkspaceSymbol > docSymbols = this .symbolsByDoc .get (uri .toASCIIString ());
726- if (docSymbols != null ) {
727- synchronized (docSymbols ) {
728- for (WorkspaceSymbol symbol : docSymbols ) {
729- builder .add (symbol );
730- }
731- }
732- }
733- }
734- return builder .build ();
735- } catch (Exception e ) {
736- log .warn ("" , e );
737- return Collections .emptyList ();
702+ if (System .getProperty (OUTLINE_SYMBOLS_FROM_INDEX_PROPERTY ) != null ) {
703+ return getWorkspaceSymbolsFromMetamodelIndex (docURI );
704+ }
705+ else {
706+ return getWorkspaceSymbolsFromSymbolIndex (docURI );
738707 }
739708 }
740709
741710 public List <? extends DocumentSymbol > getDocumentSymbols (String docURI ) {
742- List <DocumentSymbol > result = new ArrayList <>();
743-
744- List <? extends WorkspaceSymbol > symbols = getSymbols (docURI );
745- for (WorkspaceSymbol symbol : symbols ) {
746- DocumentSymbol docSymbol = new DocumentSymbol ();
747- docSymbol .setName (symbol .getName ());
748- docSymbol .setKind (symbol .getKind ());
749- docSymbol .setRange (symbol .getLocation ().getLeft ().getRange ());
750- docSymbol .setSelectionRange (symbol .getLocation ().getLeft ().getRange ());
751- docSymbol .setTags (symbol .getTags ());
752-
753- result .add (docSymbol );
711+ if (System .getProperty (OUTLINE_SYMBOLS_FROM_INDEX_PROPERTY ) != null ) {
712+ return getDocumentSymbolsFromMetamodelIndex (docURI );
713+ }
714+ else {
715+ return getDocumentSymbolsFromSymbolsIndex (docURI );
754716 }
755-
756- return result ;
757717 }
758-
759- /*
760- public List<? extends WorkspaceSymbol> getSymbols(String docURI) {
718+
719+ public List <? extends WorkspaceSymbol > getWorkspaceSymbolsFromMetamodelIndex (String docURI ) {
761720 List <WorkspaceSymbol > result = new ArrayList <>();
762721
763722 Deque <DocumentSymbol > remainingSymbols = new ArrayDeque <>();
764- List<? extends DocumentSymbol> documentSymbols = getDocumentSymbols (docURI);
723+ List <? extends DocumentSymbol > documentSymbols = getDocumentSymbolsFromMetamodelIndex (docURI );
765724
766725 remainingSymbols .addAll (documentSymbols );
767726
@@ -786,7 +745,25 @@ public List<? extends WorkspaceSymbol> getSymbols(String docURI) {
786745 return result ;
787746 }
788747
789- public List<? extends DocumentSymbol> getDocumentSymbols(String docURI) {
748+ public List <? extends DocumentSymbol > getDocumentSymbolsFromSymbolsIndex (String docURI ) {
749+ List <DocumentSymbol > result = new ArrayList <>();
750+
751+ List <? extends WorkspaceSymbol > symbols = getWorkspaceSymbolsFromSymbolIndex (docURI );
752+ for (WorkspaceSymbol symbol : symbols ) {
753+ DocumentSymbol docSymbol = new DocumentSymbol ();
754+ docSymbol .setName (symbol .getName ());
755+ docSymbol .setKind (symbol .getKind ());
756+ docSymbol .setRange (symbol .getLocation ().getLeft ().getRange ());
757+ docSymbol .setSelectionRange (symbol .getLocation ().getLeft ().getRange ());
758+ docSymbol .setTags (symbol .getTags ());
759+
760+ result .add (docSymbol );
761+ }
762+
763+ return result ;
764+ }
765+
766+ public List <? extends DocumentSymbol > getDocumentSymbolsFromMetamodelIndex (String docURI ) {
790767 try {
791768 TextDocument doc = server .getTextDocumentService ().getLatestSnapshot (docURI );
792769 URI uri = URI .create (docURI );
@@ -828,7 +805,47 @@ public List<? extends DocumentSymbol> getDocumentSymbols(String docURI) {
828805 return Collections .emptyList ();
829806 }
830807 }
831- */
808+
809+ public List <? extends WorkspaceSymbol > getWorkspaceSymbolsFromSymbolIndex (String docURI ) {
810+ try {
811+ TextDocument doc = server .getTextDocumentService ().getLatestSnapshot (docURI );
812+ URI uri = URI .create (docURI );
813+ CompletableFuture <IJavaProject > projectInitialized = futureProjectFinder .findFuture (uri ).thenCompose (project -> projectInitializedFuture (project ));
814+ IJavaProject project = projectInitialized .get (15 , TimeUnit .SECONDS );
815+ ImmutableList .Builder <WorkspaceSymbol > builder = ImmutableList .builder ();
816+ if (project != null && doc != null ) {
817+ // Collect symbols from the opened document
818+ synchronized (this ) {
819+ for (SpringIndexer indexer : this .indexers ) {
820+ if (indexer .isInterestedIn (docURI )) {
821+ try {
822+ for (WorkspaceSymbol enhanced : indexer .computeSymbols (project , docURI ,
823+ doc .get ())) {
824+ builder .add (enhanced );
825+ }
826+ } catch (Exception e ) {
827+ log .error ("{}" , e );
828+ }
829+ }
830+ }
831+ }
832+ } else {
833+ // Take symbols from the index if there is no opened document.
834+ List <WorkspaceSymbol > docSymbols = this .symbolsByDoc .get (uri .toASCIIString ());
835+ if (docSymbols != null ) {
836+ synchronized (docSymbols ) {
837+ for (WorkspaceSymbol symbol : docSymbols ) {
838+ builder .add (symbol );
839+ }
840+ }
841+ }
842+ }
843+ return builder .build ();
844+ } catch (Exception e ) {
845+ log .warn ("" , e );
846+ return Collections .emptyList ();
847+ }
848+ }
832849
833850 @ Override
834851 public CompletableFuture <List <Bean >> beans (BeansParams params ) {
0 commit comments