-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Adam Wisniewski <awisniew@Adams-MacBook-Pro.local>
- Loading branch information
Adam Wisniewski
authored and
Adam Wisniewski
committed
Mar 18, 2024
1 parent
42e706d
commit 1d9730f
Showing
4 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...se.lsp4e/src/io/openliberty/tools/eclipse/liberty/languageserver/LibertyLSClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial implementation | ||
*******************************************************************************/ | ||
package io.openliberty.tools.eclipse.liberty.languageserver; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.resources.IResourceChangeEvent; | ||
import org.eclipse.core.resources.IResourceChangeListener; | ||
import org.eclipse.core.resources.IResourceDelta; | ||
import org.eclipse.core.resources.IResourceDeltaVisitor; | ||
import org.eclipse.core.resources.IWorkspace; | ||
import org.eclipse.core.resources.ResourcesPlugin; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.lsp4e.LanguageClientImpl; | ||
import org.eclipse.lsp4j.DidChangeWatchedFilesParams; | ||
import org.eclipse.lsp4j.FileChangeType; | ||
import org.eclipse.lsp4j.FileEvent; | ||
import org.eclipse.swt.widgets.Display; | ||
|
||
import io.openliberty.tools.eclipse.ls.plugin.LibertyToolsLSPlugin; | ||
|
||
/** | ||
* Liberty Config language client. | ||
* | ||
* @author | ||
*/ | ||
public class LibertyLSClientImpl extends LanguageClientImpl { | ||
|
||
public LibertyLSClientImpl() { | ||
super(); | ||
IWorkspace iWorkspace = ResourcesPlugin.getWorkspace(); | ||
LCLSListener resourceChangeListener = new LCLSListener(); | ||
iWorkspace.addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_BUILD); | ||
|
||
} | ||
|
||
public void fireUpdate(List<String> uris) { | ||
List<FileEvent> fileEvents = new ArrayList<FileEvent>(); | ||
for (String uri : uris) { | ||
fileEvents.add(new FileEvent(uri, FileChangeType.Changed)); | ||
} | ||
DidChangeWatchedFilesParams params = new DidChangeWatchedFilesParams(); | ||
params.setChanges(fileEvents); | ||
|
||
getLanguageServer().getWorkspaceService().didChangeWatchedFiles(params); | ||
} | ||
|
||
public class LCLSListener implements IResourceChangeListener { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void resourceChanged(IResourceChangeEvent event) { | ||
Display.getDefault().syncExec(new Runnable() { | ||
|
||
@Override | ||
public void run() { | ||
|
||
IResourceDelta delta = event.getDelta(); | ||
if (delta == null) { | ||
return; | ||
} | ||
|
||
final ArrayList<String> changed = new ArrayList<String>(); | ||
|
||
IResourceDeltaVisitor visitor = new IResourceDeltaVisitor() { | ||
public boolean visit(IResourceDelta delta) { | ||
IResource resource = delta.getResource(); | ||
if (resource.getType() == IResource.FILE) { | ||
|
||
// Look for changes to liberty-plugin-config.xml, *.properties, and *.env | ||
if ("liberty-plugin-config.xml".equalsIgnoreCase(resource.getName()) | ||
|| "properties".equalsIgnoreCase(resource.getFileExtension()) | ||
|| "env".equalsIgnoreCase(resource.getFileExtension())) { | ||
changed.add(resource.getLocationURI().toString()); | ||
} | ||
} | ||
return true; | ||
} | ||
}; | ||
|
||
try { | ||
delta.accept(visitor); | ||
} catch (CoreException e) { | ||
LibertyToolsLSPlugin.logException(e.getLocalizedMessage(), e); | ||
} | ||
|
||
if (!changed.isEmpty()) { | ||
fireUpdate(changed); | ||
} | ||
|
||
} | ||
}); | ||
} | ||
} | ||
|
||
} |