Search in sources :

Example 1 with FileEvent

use of org.eclipse.lsp4j.FileEvent in project xtext-core by eclipse.

the class OpenDocumentTest method testOpenedDocumentShadowsPersistedFile.

@Test
public void testOpenedDocumentShadowsPersistedFile() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type Test {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("NonExisting foo");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String firstFile = this.writeFile("MyType1.testlang", _builder);
    this.initialize();
    this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("type Foo {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final String path = this.writeFile("MyType2.testlang", _builder_1);
    WorkspaceService _workspaceService = this.languageServer.getWorkspaceService();
    FileEvent _fileEvent = new FileEvent(path, FileChangeType.Created);
    DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(Collections.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent)));
    _workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams);
    this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
    StringConcatenation _builder_2 = new StringConcatenation();
    _builder_2.append("type NonExisting {");
    _builder_2.newLine();
    _builder_2.append("}");
    _builder_2.newLine();
    this.open(path, _builder_2.toString());
    Assert.assertNull(IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)));
    this.close(path);
    this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", IterableExtensions.<Diagnostic>head(this.getDiagnostics().get(firstFile)).getMessage());
}
Also used : FileEvent(org.eclipse.lsp4j.FileEvent) WorkspaceService(org.eclipse.lsp4j.services.WorkspaceService) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Diagnostic(org.eclipse.lsp4j.Diagnostic) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 2 with FileEvent

use of org.eclipse.lsp4j.FileEvent in project xtext-core by eclipse.

the class ServerTest method testIncrementalBuildWithError.

@Test
public void testIncrementalBuildWithError() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("type Test {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("NonExisting foo");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    this.writeFile("MyType1.testlang", _builder);
    this.initialize();
    this.assertEquals("Couldn\'t resolve reference to TypeDeclaration \'NonExisting\'.", IterableExtensions.<Diagnostic>head(IterableExtensions.<List<Diagnostic>>head(this.getDiagnostics().values())).getMessage());
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("type NonExisting {");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    final String path = this.writeFile("MyType2.testlang", _builder_1);
    WorkspaceService _workspaceService = this.languageServer.getWorkspaceService();
    FileEvent _fileEvent = new FileEvent(path, FileChangeType.Created);
    DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams(Collections.<FileEvent>unmodifiableList(CollectionLiterals.<FileEvent>newArrayList(_fileEvent)));
    _workspaceService.didChangeWatchedFiles(_didChangeWatchedFilesParams);
    Assert.assertNotNull(this.getDiagnostics().get(path));
    final Function1<List<Diagnostic>, Boolean> _function = (List<Diagnostic> it) -> {
        return Boolean.valueOf(it.isEmpty());
    };
    Assert.assertTrue(IterableExtensions.join(this.getDiagnostics().values(), ","), IterableExtensions.<List<Diagnostic>>forall(this.getDiagnostics().values(), _function));
}
Also used : FileEvent(org.eclipse.lsp4j.FileEvent) WorkspaceService(org.eclipse.lsp4j.services.WorkspaceService) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Diagnostic(org.eclipse.lsp4j.Diagnostic) List(java.util.List) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams) Test(org.junit.Test) AbstractTestLangLanguageServerTest(org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)

Example 3 with FileEvent

use of org.eclipse.lsp4j.FileEvent in project xtext-core by eclipse.

the class AbstractLanguageServerTest method didCreateWatchedFiles.

protected void didCreateWatchedFiles(final String... fileUris) {
    DidChangeWatchedFilesParams _didChangeWatchedFilesParams = new DidChangeWatchedFilesParams();
    final Procedure1<DidChangeWatchedFilesParams> _function = (DidChangeWatchedFilesParams it) -> {
        for (final String fileUri : fileUris) {
            List<FileEvent> _changes = it.getChanges();
            FileEvent _fileEvent = new FileEvent();
            final Procedure1<FileEvent> _function_1 = (FileEvent it_1) -> {
                it_1.setUri(fileUri);
                it_1.setType(FileChangeType.Created);
            };
            FileEvent _doubleArrow = ObjectExtensions.<FileEvent>operator_doubleArrow(_fileEvent, _function_1);
            _changes.add(_doubleArrow);
        }
    };
    DidChangeWatchedFilesParams _doubleArrow = ObjectExtensions.<DidChangeWatchedFilesParams>operator_doubleArrow(_didChangeWatchedFilesParams, _function);
    this.languageServer.didChangeWatchedFiles(_doubleArrow);
}
Also used : FileEvent(org.eclipse.lsp4j.FileEvent) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) DidChangeWatchedFilesParams(org.eclipse.lsp4j.DidChangeWatchedFilesParams)

Example 4 with FileEvent

use of org.eclipse.lsp4j.FileEvent in project vscode-nextgenas by BowlerHatLLC.

the class ActionScriptTextDocumentService method didChangeWatchedFiles.

/**
     * Called when certain files in the workspace are added, removed, or
     * changed, even if they are not considered open for editing. Also checks if
     * the project configuration strategy has changed. If it has, checks for
     * errors on the whole project.
     */
public void didChangeWatchedFiles(DidChangeWatchedFilesParams params) {
    boolean needsFullCheck = false;
    for (FileEvent event : params.getChanges()) {
        Path path = LanguageServerUtils.getPathFromLanguageServerURI(event.getUri());
        if (path == null) {
            continue;
        }
        File file = path.toFile();
        String fileName = file.getName();
        if ((fileName.endsWith(AS_EXTENSION) || fileName.endsWith(MXML_EXTENSION)) && currentWorkspace != null) {
            if (event.getType().equals(FileChangeType.Deleted)) {
                IFileSpecification fileSpec = fileSpecGetter.getFileSpecification(file.getAbsolutePath());
                currentWorkspace.fileRemoved(fileSpec);
                needsFullCheck = true;
            } else if (event.getType().equals(FileChangeType.Created)) {
                IFileSpecification fileSpec = fileSpecGetter.getFileSpecification(file.getAbsolutePath());
                currentWorkspace.fileAdded(fileSpec);
            } else if (event.getType().equals(FileChangeType.Changed)) {
                IFileSpecification fileSpec = fileSpecGetter.getFileSpecification(file.getAbsolutePath());
                currentWorkspace.fileChanged(fileSpec);
                checkFilePathForProblems(path, false);
            }
        }
    }
    if (needsFullCheck || projectConfigStrategy.getChanged()) {
        checkProjectForProblems();
    }
}
Also used : Path(java.nio.file.Path) FileEvent(org.eclipse.lsp4j.FileEvent) IFileSpecification(org.apache.flex.compiler.filespecs.IFileSpecification) File(java.io.File)

Example 5 with FileEvent

use of org.eclipse.lsp4j.FileEvent in project xtext-core by eclipse.

the class LanguageServerImpl method didChangeWatchedFiles.

@Override
public void didChangeWatchedFiles(final DidChangeWatchedFilesParams params) {
    final Function0<BuildManager.Buildable> _function = () -> {
        BuildManager.Buildable _xblockexpression = null;
        {
            final ArrayList<URI> dirtyFiles = CollectionLiterals.<URI>newArrayList();
            final ArrayList<URI> deletedFiles = CollectionLiterals.<URI>newArrayList();
            List<FileEvent> _changes = params.getChanges();
            for (final FileEvent fileEvent : _changes) {
                FileChangeType _type = fileEvent.getType();
                boolean _tripleEquals = (_type == FileChangeType.Deleted);
                if (_tripleEquals) {
                    URI _uri = this._uriExtensions.toUri(fileEvent.getUri());
                    deletedFiles.add(_uri);
                } else {
                    URI _uri_1 = this._uriExtensions.toUri(fileEvent.getUri());
                    dirtyFiles.add(_uri_1);
                }
            }
            _xblockexpression = this.workspaceManager.didChangeFiles(dirtyFiles, deletedFiles);
        }
        return _xblockexpression;
    };
    final Function2<CancelIndicator, BuildManager.Buildable, List<IResourceDescription.Delta>> _function_1 = (CancelIndicator cancelIndicator, BuildManager.Buildable buildable) -> {
        return buildable.build(cancelIndicator);
    };
    this.requestManager.<BuildManager.Buildable, List<IResourceDescription.Delta>>runWrite(_function, _function_1);
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) FileChangeType(org.eclipse.lsp4j.FileChangeType) URI(org.eclipse.emf.common.util.URI) FileEvent(org.eclipse.lsp4j.FileEvent) BuildManager(org.eclipse.xtext.ide.server.BuildManager) ArrayList(java.util.ArrayList) List(java.util.List) CompletionList(org.eclipse.lsp4j.CompletionList) CancelIndicator(org.eclipse.xtext.util.CancelIndicator)

Aggregations

FileEvent (org.eclipse.lsp4j.FileEvent)5 List (java.util.List)3 DidChangeWatchedFilesParams (org.eclipse.lsp4j.DidChangeWatchedFilesParams)3 CompletionList (org.eclipse.lsp4j.CompletionList)2 Diagnostic (org.eclipse.lsp4j.Diagnostic)2 WorkspaceService (org.eclipse.lsp4j.services.WorkspaceService)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 AbstractTestLangLanguageServerTest (org.eclipse.xtext.ide.tests.server.AbstractTestLangLanguageServerTest)2 Test (org.junit.Test)2 File (java.io.File)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 IFileSpecification (org.apache.flex.compiler.filespecs.IFileSpecification)1 URI (org.eclipse.emf.common.util.URI)1 FileChangeType (org.eclipse.lsp4j.FileChangeType)1 BuildManager (org.eclipse.xtext.ide.server.BuildManager)1 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)1 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)1 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)1