Skip to content

Commit

Permalink
File completion in attribute value
Browse files Browse the repository at this point in the history
Provides file completion when the user starts typing a path in an attribute value

Displays all folders and files as of now.

Fixes eclipse#345

Signed-off-by: Nikolas Komonen <[email protected]>
  • Loading branch information
NikolasKomonen committed Jun 5, 2019
1 parent 46984c2 commit 5e67f74
Show file tree
Hide file tree
Showing 17 changed files with 833 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.lsp4xml.commons;

import static org.eclipse.lsp4xml.utils.OSUtils.isWindows;

import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -19,16 +21,17 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import com.google.common.io.Closeables;

import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.services.LanguageServer;

import com.google.common.io.Closeables;

/**
* Watches the parent process PID and invokes exit if it is no longer available.
* This implementation waits for periods of inactivity to start querying the PIDs.
* This implementation waits for periods of inactivity to start querying the
* PIDs.
*/
public final class ParentProcessWatcher implements Runnable, Function<MessageConsumer, MessageConsumer>{
public final class ParentProcessWatcher implements Runnable, Function<MessageConsumer, MessageConsumer> {

private static final Logger LOGGER = Logger.getLogger(ParentProcessWatcher.class.getName());
private static final boolean isJava1x = System.getProperty("java.version").startsWith("1.");
Expand All @@ -38,9 +41,7 @@ public final class ParentProcessWatcher implements Runnable, Function<MessageCon
*/
private static final int FORCED_EXIT_CODE = 1;

private static final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;

private static final long INACTIVITY_DELAY_SECS = 30 *1000;
private static final long INACTIVITY_DELAY_SECS = 30 * 1000;
private static final int POLL_DELAY_SECS = 10;
private volatile long lastActivityTime;
private final ProcessLanguageServer server;
Expand All @@ -50,14 +51,14 @@ public final class ParentProcessWatcher implements Runnable, Function<MessageCon
public interface ProcessLanguageServer extends LanguageServer {

long getParentProcessId();

void exit(int exitCode);
}
public ParentProcessWatcher(ProcessLanguageServer server ) {

public ParentProcessWatcher(ProcessLanguageServer server) {
this.server = server;
service = Executors.newScheduledThreadPool(1);
task = service.scheduleWithFixedDelay(this, POLL_DELAY_SECS, POLL_DELAY_SECS, TimeUnit.SECONDS);
task = service.scheduleWithFixedDelay(this, POLL_DELAY_SECS, POLL_DELAY_SECS, TimeUnit.SECONDS);
}

@Override
Expand All @@ -70,8 +71,8 @@ public void run() {
}

/**
* Checks whether the parent process is still running.
* If not, then we assume it has crashed, and we have to terminate the Java Language Server.
* Checks whether the parent process is still running. If not, then we assume it
* has crashed, and we have to terminate the Java Language Server.
*
* @return true if the parent process is still running
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/

package org.eclipse.lsp4xml.extensions.general;

import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4xml.extensions.general.completion.FilePathCompletionParticipant;
import org.eclipse.lsp4xml.services.extensions.IXMLExtension;
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.services.extensions.save.ISaveContext;

/**
* FilePathPlugin
*/
public class FilePathPlugin implements IXMLExtension {

private final FilePathCompletionParticipant completionParticipant;

public FilePathPlugin() {
completionParticipant = new FilePathCompletionParticipant();
}

@Override
public void start(InitializeParams params, XMLExtensionsRegistry registry) {
registry.registerCompletionParticipant(completionParticipant);
}

@Override
public void stop(XMLExtensionsRegistry registry) {
registry.unregisterCompletionParticipant(completionParticipant);
}

@Override
public void doSave(ISaveContext context) {

}


}
Loading

0 comments on commit 5e67f74

Please sign in to comment.