Search in sources :

Example 91 with TextDocumentIdentifier

use of org.eclipse.lsp4j.TextDocumentIdentifier in project eclipse.jdt.ls by eclipse.

the class ProjectsManager method fileChanged.

public void fileChanged(String uriString, CHANGE_TYPE changeType) {
    if (uriString == null) {
        return;
    }
    IResource resource = JDTUtils.findFile(uriString);
    if (resource == null) {
        return;
    }
    try {
        if (changeType == CHANGE_TYPE.DELETED) {
            resource = resource.getParent();
        }
        if (resource != null) {
            resource.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        }
        if (isBuildFile(resource)) {
            FeatureStatus status = preferenceManager.getPreferences().getUpdateBuildConfigurationStatus();
            switch(status) {
                case automatic:
                    updateProject(resource.getProject());
                    break;
                case disabled:
                    break;
                default:
                    if (client != null) {
                        String cmd = "java.projectConfiguration.status";
                        TextDocumentIdentifier uri = new TextDocumentIdentifier(uriString);
                        ActionableNotification updateProjectConfigurationNotification = new ActionableNotification().withSeverity(MessageType.Info).withMessage("A build file was modified. Do you want to synchronize the Java classpath/configuration?").withCommands(asList(new Command("Never", cmd, asList(uri, FeatureStatus.disabled)), new Command("Now", cmd, asList(uri, FeatureStatus.interactive)), new Command("Always", cmd, asList(uri, FeatureStatus.automatic))));
                        client.sendActionableNotification(updateProjectConfigurationNotification);
                    }
            }
        }
    } catch (CoreException e) {
        JavaLanguageServerPlugin.logException("Problem refreshing workspace", e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) CoreException(org.eclipse.core.runtime.CoreException) FeatureStatus(org.eclipse.jdt.ls.core.internal.preferences.Preferences.FeatureStatus) Command(org.eclipse.lsp4j.Command) ActionableNotification(org.eclipse.jdt.ls.core.internal.ActionableNotification) IResource(org.eclipse.core.resources.IResource)

Example 92 with TextDocumentIdentifier

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

the class RenameTest method doTest.

protected void doTest(String fileName, Position position) throws Exception {
    RenameParams params = new RenameParams(new TextDocumentIdentifier(fileName), position, "Tescht");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expected = "changes :\n" + "	MyType1.testlang : Tescht [[0, 5] .. [0, 9]]\n" + "	Tescht [[1, 4] .. [1, 8]]\n" + "	MyType2.testlang : Tescht [[1, 4] .. [1, 8]]\n" + "documentChanges : \n";
    assertEquals(expected, toExpectation(workspaceEdit));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) RenameParams(org.eclipse.lsp4j.RenameParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit)

Example 93 with TextDocumentIdentifier

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

the class RenamePositionTest method renameWithSuccess.

protected void renameWithSuccess(String model, Position position) throws Exception {
    String modelFile = writeFile("MyType.testlang", model);
    initialize((InitializeParams params) -> {
        ClientCapabilities clientCapabilities = new ClientCapabilities();
        TextDocumentClientCapabilities textDocumentClientCapabilities = new TextDocumentClientCapabilities();
        textDocumentClientCapabilities.setRename(new RenameCapabilities(true, false));
        clientCapabilities.setTextDocument(textDocumentClientCapabilities);
        params.setCapabilities(clientCapabilities);
    });
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    Assert.assertNotNull(range);
    assertEquals(new Document(Integer.valueOf(0), model).getSubstring(range), "Test");
    RenameParams params = new RenameParams(identifier, position, "Tescht");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "	MyType.testlang : Tescht [[0, 5] .. [0, 9]]\n" + "documentChanges : \n";
    assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) RenameCapabilities(org.eclipse.lsp4j.RenameCapabilities) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) ClientCapabilities(org.eclipse.lsp4j.ClientCapabilities) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) InitializeParams(org.eclipse.lsp4j.InitializeParams) TextDocumentClientCapabilities(org.eclipse.lsp4j.TextDocumentClientCapabilities) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document)

Example 94 with TextDocumentIdentifier

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

the class RenamePositionTest method renameAndFail.

protected void renameAndFail(String model, Position position, String messageFragment) {
    String modelFile = writeFile("MyType.testlang", model);
    initialize();
    try {
        TextDocumentIdentifier identifier = new TextDocumentIdentifier(modelFile);
        Either<Range, PrepareRenameResult> prepareRenameResult = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get();
        Assert.assertNull("expected null result got " + prepareRenameResult + " instead", prepareRenameResult);
        RenameParams renameParams = new RenameParams(new TextDocumentIdentifier(modelFile), position, "Tescht");
        languageServer.rename(renameParams).get();
        Assert.fail("Rename should have failed");
    } catch (Exception exc) {
        Throwable rootCause = Throwables.getRootCause(exc);
        Assert.assertTrue(rootCause instanceof ResponseErrorException);
        ResponseError error = ((ResponseErrorException) rootCause).getResponseError();
        Assert.assertTrue(error.getData().toString().contains(messageFragment));
    }
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException) ResponseError(org.eclipse.lsp4j.jsonrpc.messages.ResponseError) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) PrepareRenameResult(org.eclipse.lsp4j.PrepareRenameResult) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) ResponseErrorException(org.eclipse.lsp4j.jsonrpc.ResponseErrorException)

Example 95 with TextDocumentIdentifier

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

the class RenameTest3 method testRenameAutoQuote.

@Test
public void testRenameAutoQuote() throws Exception {
    String model = "type Foo {\n" + "}\n" + "";
    String file = writeFile("foo/Foo.renametl", model);
    initialize();
    TextDocumentIdentifier identifier = new TextDocumentIdentifier(file);
    Position position = new Position(0, 6);
    Range range = languageServer.prepareRename(new PrepareRenameParams(identifier, position)).get().getLeft();
    assertEquals("Foo", new Document(0, model).getSubstring(range));
    RenameParams params = new RenameParams(identifier, position, "type");
    WorkspaceEdit workspaceEdit = languageServer.rename(params).get();
    String expectation = "changes :\n" + "documentChanges : \n" + "    Foo.renametl <1> : ^type [[0, 5] .. [0, 8]]\n" + "";
    assertEquals(expectation.toString(), toExpectation(workspaceEdit));
}
Also used : TextDocumentIdentifier(org.eclipse.lsp4j.TextDocumentIdentifier) Position(org.eclipse.lsp4j.Position) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) RenameParams(org.eclipse.lsp4j.RenameParams) WorkspaceEdit(org.eclipse.lsp4j.WorkspaceEdit) Range(org.eclipse.lsp4j.Range) PrepareRenameParams(org.eclipse.lsp4j.PrepareRenameParams) Document(org.eclipse.xtext.ide.server.Document) Test(org.junit.Test) AbstractLanguageServerTest(org.eclipse.xtext.testing.AbstractLanguageServerTest)

Aggregations

TextDocumentIdentifier (org.eclipse.lsp4j.TextDocumentIdentifier)172 Test (org.junit.Test)113 Position (org.eclipse.lsp4j.Position)102 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)56 Range (org.eclipse.lsp4j.Range)47 TextDocumentPositionParams (org.eclipse.lsp4j.TextDocumentPositionParams)37 Either (org.eclipse.lsp4j.jsonrpc.messages.Either)35 URI (java.net.URI)34 AbstractProjectsManagerBasedTest (org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest)33 CodeActionContext (org.eclipse.lsp4j.CodeActionContext)32 CodeActionParams (org.eclipse.lsp4j.CodeActionParams)32 List (java.util.List)26 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)25 Location (org.eclipse.lsp4j.Location)23 AbstractQuickFixTest (org.eclipse.jdt.ls.core.internal.correction.AbstractQuickFixTest)22 Command (org.eclipse.lsp4j.Command)22 PrepareRenameParams (org.eclipse.lsp4j.PrepareRenameParams)20 FormattingOptions (org.eclipse.lsp4j.FormattingOptions)19 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 CodeAction (org.eclipse.lsp4j.CodeAction)18