From e8f2840966e9bee7ce3948ee4662136e78103862 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Tue, 22 Jan 2019 10:52:45 +0100 Subject: [PATCH] do not configure boot ls as server for general xml docs and instead use watch files mechanism to detect changes to XML files --- .../plugin.xml | 4 -- .../boot/java/utils/SpringSymbolIndex.java | 48 ++++++++++++++----- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/eclipse-language-servers/org.springframework.tooling.boot.ls/plugin.xml b/eclipse-language-servers/org.springframework.tooling.boot.ls/plugin.xml index 9a2ff4c42..6e01405b7 100644 --- a/eclipse-language-servers/org.springframework.tooling.boot.ls/plugin.xml +++ b/eclipse-language-servers/org.springframework.tooling.boot.ls/plugin.xml @@ -14,10 +14,6 @@ contentType="org.eclipse.jdt.core.javaSource" id="org.eclipse.languageserver.languages.springboot"> - - globPattern = Arrays.stream(this.indexer).map(indexer -> - indexer.getFileWatchPatterns()).flatMap(Arrays::stream).collect(Collectors.toList()); + List globPattern = Arrays.asList(springIndexerJava.getFileWatchPatterns()); getWorkspaceService().getFileObserver().onFileDeleted(globPattern, (file) -> { deleteDocument(new TextDocumentIdentifier(file).getUri()); @@ -157,6 +160,38 @@ public class SpringSymbolIndex { }); } + public void configureIndexer(boolean springXMLSupportEnabled) { + synchronized (this) { + if (springXMLSupportEnabled && !(Arrays.asList(this.indexer).contains(springIndexerXML))) { + this.indexer = new SpringIndexer[] {springIndexerJava, springIndexerXML}; + + List globPattern = Arrays.asList(springIndexerXML.getFileWatchPatterns()); + + watchXMLDeleteRegistration = getWorkspaceService().getFileObserver().onFileDeleted(globPattern, (file) -> { + deleteDocument(new TextDocumentIdentifier(file).getUri()); + }); + watchXMLCreatedRegistration = getWorkspaceService().getFileObserver().onFileCreated(globPattern, (file) -> { + createDocument(new TextDocumentIdentifier(file).getUri()); + }); + watchXMLChangedRegistration = getWorkspaceService().getFileObserver().onFileChanged(globPattern, (file) -> { + updateDocument(new TextDocumentIdentifier(file).getUri(), null); + }); + + } + else if (!springXMLSupportEnabled && Arrays.asList(this.indexer).contains(springIndexerXML)) { + this.indexer = new SpringIndexer[] {springIndexerJava}; + + getWorkspaceService().getFileObserver().unsubscribe(watchXMLChangedRegistration); + getWorkspaceService().getFileObserver().unsubscribe(watchXMLCreatedRegistration); + getWorkspaceService().getFileObserver().unsubscribe(watchXMLDeleteRegistration); + + watchXMLChangedRegistration = null; + watchXMLCreatedRegistration = null; + watchXMLDeleteRegistration = null; + } + } + } + public void shutdown() { try { synchronized(this) { @@ -173,15 +208,6 @@ public class SpringSymbolIndex { } } - public void configureIndexer(boolean springXMLSupportEnabled) { - if (springXMLSupportEnabled) { - this.indexer = new SpringIndexer[] {springIndexerJava, springIndexerXML}; - } - else { - this.indexer = new SpringIndexer[] {springIndexerJava}; - } - } - public CompletableFuture initializeProject(IJavaProject project) { try { if (SpringProjectUtil.isBootProject(project) || SpringProjectUtil.isSpringProject(project)) {