org.eclipse.lsp4j.FileSystemWatcher Java Examples

The following examples show how to use org.eclipse.lsp4j.FileSystemWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvisibleProjectImporterTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public void automaticJarDetection() throws Exception {
	ClientPreferences mockCapabilies = mock(ClientPreferences.class);
	when(mockCapabilies.isWorkspaceChangeWatchedFilesDynamicRegistered()).thenReturn(Boolean.TRUE);
	when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);

	File projectFolder = createSourceFolderWithLibs("automaticJarDetection", "src", true);

	IProject invisibleProject = importRootFolder(projectFolder, "Test.java");
	assertNoErrors(invisibleProject);

	IJavaProject javaProject = JavaCore.create(invisibleProject);
	IClasspathEntry[] classpath = javaProject.getRawClasspath();
	assertEquals("Unexpected classpath:\n" + JavaProjectHelper.toString(classpath), 3, classpath.length);
	assertEquals("foo.jar", classpath[2].getPath().lastSegment());
	assertEquals("foo-sources.jar", classpath[2].getSourceAttachmentPath().lastSegment());

	List<FileSystemWatcher> watchers = projectsManager.registerWatchers();
	watchers.sort((a, b) -> a.getGlobPattern().compareTo(b.getGlobPattern()));
	assertEquals(10, watchers.size());
	String srcGlobPattern = watchers.get(7).getGlobPattern();
	assertTrue("Unexpected source glob pattern: " + srcGlobPattern, srcGlobPattern.equals("**/src/**"));
	String libGlobPattern = watchers.get(9).getGlobPattern();
	assertTrue("Unexpected lib glob pattern: " + libGlobPattern, libGlobPattern.endsWith(projectFolder.getName() + "/lib/**"));
}
 
Example #2
Source File: XMLCapabilityManager.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
private void registerWatchedFiles() {
	List<FileSystemWatcher> watchers = new ArrayList<>(2);
	watchers.add(new FileSystemWatcher("**/*.xsd"));
	watchers.add(new FileSystemWatcher("**/*.dtd"));
	DidChangeWatchedFilesRegistrationOptions options = new DidChangeWatchedFilesRegistrationOptions(watchers);
	registerCapability(WORKSPACE_WATCHED_FILES_ID, WORKSPACE_WATCHED_FILES, options);
}
 
Example #3
Source File: SyntaxProjectsManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<FileSystemWatcher> registerWatchers() {
	logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'");
	if (JavaLanguageServerPlugin.getPreferencesManager().getClientPreferences().isWorkspaceChangeWatchedFilesDynamicRegistered()) {
		IPath[] sources = new IPath[0];
		try {
			sources = listAllSourcePaths();
		} catch (JavaModelException e) {
			JavaLanguageServerPlugin.logException(e.getMessage(), e);
		}
		List<FileSystemWatcher> fileWatchers = new ArrayList<>();
		Set<String> patterns = new LinkedHashSet<>(basicWatchers);
		patterns.addAll(Stream.of(sources).map(ResourceUtils::toGlobPattern).collect(Collectors.toList()));

		for (String pattern : patterns) {
			FileSystemWatcher watcher = new FileSystemWatcher(pattern);
			fileWatchers.add(watcher);
		}

		if (!patterns.equals(watchers)) {
			JavaLanguageServerPlugin.logInfo(">> registerFeature 'workspace/didChangeWatchedFiles'");
			DidChangeWatchedFilesRegistrationOptions didChangeWatchedFilesRegistrationOptions = new DidChangeWatchedFilesRegistrationOptions(fileWatchers);
			JavaLanguageServerPlugin.getInstance().unregisterCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES);
			JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.WORKSPACE_WATCHED_FILES_ID, Preferences.WORKSPACE_WATCHED_FILES, didChangeWatchedFilesRegistrationOptions);
			watchers.clear();
			watchers.addAll(patterns);
		}

		return fileWatchers;
	}

	return Collections.emptyList();
}
 
Example #4
Source File: InvisibleProjectImporterTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void automaticJarDetectionLibUnderSource() throws Exception {
	ClientPreferences mockCapabilies = mock(ClientPreferences.class);
	when(mockCapabilies.isWorkspaceChangeWatchedFilesDynamicRegistered()).thenReturn(Boolean.TRUE);
	when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);

	File projectFolder = createSourceFolderWithLibs("automaticJarDetectionLibUnderSource");

	IProject invisibleProject = importRootFolder(projectFolder, "Test.java");
	assertNoErrors(invisibleProject);

	IJavaProject javaProject = JavaCore.create(invisibleProject);
	IClasspathEntry[] classpath = javaProject.getRawClasspath();
	assertEquals("Unexpected classpath:\n" + JavaProjectHelper.toString(classpath), 3, classpath.length);
	assertEquals("foo.jar", classpath[2].getPath().lastSegment());
	assertEquals("foo-sources.jar", classpath[2].getSourceAttachmentPath().lastSegment());

	List<FileSystemWatcher> watchers = projectsManager.registerWatchers();
	watchers.sort((a, b) -> a.getGlobPattern().compareTo(b.getGlobPattern()));
	assertEquals(10, watchers.size()); // basic(8) + project(1) + library(1)
	String srcGlobPattern = watchers.get(7).getGlobPattern();
	assertTrue("Unexpected source glob pattern: " + srcGlobPattern, srcGlobPattern.equals("**/src/**"));
	String projGlobPattern = watchers.get(8).getGlobPattern();
	assertTrue("Unexpected project glob pattern: " + projGlobPattern, projGlobPattern.endsWith(projectFolder.getName() + "/**"));
	String libGlobPattern = watchers.get(9).getGlobPattern();
	assertTrue("Unexpected library glob pattern: " + libGlobPattern, libGlobPattern.endsWith(projectFolder.getName() + "/lib/**"));
}
 
Example #5
Source File: ActionScriptLanguageServer.java    From vscode-as3mxml with Apache License 2.0 5 votes vote down vote up
@Override
public void initialized(InitializedParams params)
{
    boolean canRegisterDidChangeWatchedFiles = false;
    try
    {
        canRegisterDidChangeWatchedFiles = actionScriptServices.getClientCapabilities().getWorkspace().getDidChangeWatchedFiles().getDynamicRegistration();
    }
    catch(NullPointerException e)
    {
        canRegisterDidChangeWatchedFiles = false;
    }
    if(canRegisterDidChangeWatchedFiles)
    {
        List<FileSystemWatcher> watchers = new ArrayList<>();
        //ideally, we'd only check .as, .mxml, asconfig.json, and directories
        //but there's no way to target directories without *
        watchers.add(new FileSystemWatcher("**/*"));

        String id = "as3mxml-language-server-" + Math.random();
        DidChangeWatchedFilesRegistrationOptions options = new DidChangeWatchedFilesRegistrationOptions(watchers);
        Registration registration = new Registration(id, "workspace/didChangeWatchedFiles", options);
        List<Registration> registrations = new ArrayList<>();
        registrations.add(registration);

        RegistrationParams registrationParams = new RegistrationParams(registrations);
        languageClient.registerCapability(registrationParams);
    }

    //we can't notify the client about problems until we receive this
    //initialized notification. this is the first time that we'll start
    //checking for errors.
    actionScriptServices.setInitialized();
}
 
Example #6
Source File: InitHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private String toString(List<FileSystemWatcher> watchers) {
	return watchers.stream().map(FileSystemWatcher::getGlobPattern).collect(Collectors.joining("\n"));
}
 
Example #7
Source File: DidChangeWatchedFilesRegistrationOptions.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public DidChangeWatchedFilesRegistrationOptions(@NonNull final List<FileSystemWatcher> watchers) {
  this.watchers = Preconditions.<List<FileSystemWatcher>>checkNotNull(watchers, "watchers");
}
 
Example #8
Source File: DidChangeWatchedFilesRegistrationOptions.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The watchers to register.
 */
@Pure
@NonNull
public List<FileSystemWatcher> getWatchers() {
  return this.watchers;
}
 
Example #9
Source File: DidChangeWatchedFilesRegistrationOptions.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * The watchers to register.
 */
public void setWatchers(@NonNull final List<FileSystemWatcher> watchers) {
  this.watchers = Preconditions.checkNotNull(watchers, "watchers");
}
 
Example #10
Source File: IProjectsManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Update the watcher patterns.
 */
List<FileSystemWatcher> registerWatchers();