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);
}
}
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));
}
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));
}
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));
}
}
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));
}
Aggregations