org.eclipse.lsp4j.ResourceOperationKind Java Examples

The following examples show how to use org.eclipse.lsp4j.ResourceOperationKind. 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: ResourceOperationTypeAdapter.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ResourceOperation read(JsonReader in) throws IOException {
	JsonObject objectJson = new JsonParser().parse(in).getAsJsonObject();
	JsonElement value = objectJson.get("kind");
	if (value != null && value.isJsonPrimitive()) {
		String kindValue = value.getAsString();

		if (ResourceOperationKind.Create.equals(kindValue)) {
			return createFileAdapter.fromJsonTree(objectJson);
		} else if (ResourceOperationKind.Delete.equals(kindValue)) {
			return deleteFileAdapter.fromJsonTree(objectJson);
		} else if (ResourceOperationKind.Rename.equals(kindValue)) {
			return renameFileAdapter.fromJsonTree(objectJson);
		}
	}

	throw new JsonParseException(
			"The ResourceOperation object either has null \"kind\" value or the \"kind\" value is not valid.");
}
 
Example #2
Source File: XMLSchemaDiagnosticsTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void localSchemaFileMissingCodeAction() throws Exception {
	String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //
			"<invoice xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + //
			"  xsi:noNamespaceSchemaLocation=\"/salad.xsd\">\n" + //
			"</invoice>";
	Diagnostic missingSchemaDiagnostic = d(2, 32, 44, XMLSchemaErrorCode.schema_reference_4);
	missingSchemaDiagnostic.setMessage("schema_reference.4: Failed to read schema document "
			+ "'file:///salad.xsd',"
			+ " because 1) could not find the document; 2) the document could not be read;"
			+ " 3) the root element of the document is not <xsd:schema>.");
	Diagnostic eltDiagnostic = d(1, 1, 8, XMLSchemaErrorCode.cvc_elt_1_a);
	eltDiagnostic.setMessage("cvc-elt.1.a: Cannot find the declaration of element 'invoice'.");
	XMLAssert.testDiagnosticsFor(xml, missingSchemaDiagnostic, eltDiagnostic);

	SharedSettings settings = new SharedSettings();
	WorkspaceClientCapabilities workspace = new WorkspaceClientCapabilities();
	WorkspaceEditCapabilities workspaceEdit = new WorkspaceEditCapabilities();
	workspaceEdit.setResourceOperations(Arrays.asList(ResourceOperationKind.Create));
	workspace.setWorkspaceEdit(workspaceEdit);
	settings.getWorkspaceSettings().setCapabilities(workspace);

	XMLAssert.testCodeActionsFor(xml, //
			missingSchemaDiagnostic, //
			settings, //
			ca(missingSchemaDiagnostic, //
					createFile("file:///salad.xsd", false), //
					teOp("file:///salad.xsd", 0, 0, 0, 0, //
							"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + lineSeparator() + //
									"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">" + lineSeparator() + //
									"  <xs:element name=\"invoice\" type=\"xs:string\" />" + lineSeparator() + //
									"</xs:schema>")));
}
 
Example #3
Source File: LSPBindings.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static InitializeResult initServer(Process p, LanguageServer server, FileObject root) throws InterruptedException, ExecutionException {
   InitializeParams initParams = new InitializeParams();
   initParams.setRootUri(Utils.toURI(root));
   initParams.setRootPath(FileUtil.toFile(root).getAbsolutePath()); //some servers still expect root path
   initParams.setProcessId(0);
   TextDocumentClientCapabilities tdcc = new TextDocumentClientCapabilities();
   DocumentSymbolCapabilities dsc = new DocumentSymbolCapabilities();
   dsc.setHierarchicalDocumentSymbolSupport(true);
   dsc.setSymbolKind(new SymbolKindCapabilities(Arrays.asList(SymbolKind.values())));
   tdcc.setDocumentSymbol(dsc);
   WorkspaceClientCapabilities wcc = new WorkspaceClientCapabilities();
   wcc.setWorkspaceEdit(new WorkspaceEditCapabilities());
   wcc.getWorkspaceEdit().setDocumentChanges(true);
   wcc.getWorkspaceEdit().setResourceOperations(Arrays.asList(ResourceOperationKind.Create, ResourceOperationKind.Delete, ResourceOperationKind.Rename));
   initParams.setCapabilities(new ClientCapabilities(wcc, tdcc, null));
   CompletableFuture<InitializeResult> initResult = server.initialize(initParams);
   while (true) {
       try {
           return initResult.get(100, TimeUnit.MILLISECONDS);
       } catch (TimeoutException ex) {
           if (p != null && !p.isAlive()) {
               InitializeResult emptyResult = new InitializeResult();
               emptyResult.setCapabilities(new ServerCapabilities());
               return emptyResult;
           }
       }
   }
}
 
Example #4
Source File: ClientPreferences.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public boolean isResourceOperationSupported() {
	//@formatter:off
	return capabilities.getWorkspace() != null
			&& capabilities.getWorkspace().getWorkspaceEdit() != null
			&& capabilities.getWorkspace().getWorkspaceEdit().getResourceOperations() != null
			&& capabilities.getWorkspace().getWorkspaceEdit().getResourceOperations().contains(ResourceOperationKind.Create)
			&& capabilities.getWorkspace().getWorkspaceEdit().getResourceOperations().contains(ResourceOperationKind.Rename)
			&& capabilities.getWorkspace().getWorkspaceEdit().getResourceOperations().contains(ResourceOperationKind.Delete);
	//@formatter:on
}
 
Example #5
Source File: CreateFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public CreateFile() {
  super(ResourceOperationKind.Create);
}
 
Example #6
Source File: CreateFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public CreateFile(@NonNull final String uri) {
  super(ResourceOperationKind.Create);
  this.uri = Preconditions.<String>checkNotNull(uri, "uri");
}
 
Example #7
Source File: CreateFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public CreateFile(@NonNull final String uri, final CreateFileOptions options) {
  super(ResourceOperationKind.Create);
  this.uri = Preconditions.<String>checkNotNull(uri, "uri");
  this.options = options;
}
 
Example #8
Source File: RenameFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public RenameFile() {
  super(ResourceOperationKind.Rename);
}
 
Example #9
Source File: RenameFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public RenameFile(@NonNull final String oldUri, @NonNull final String newUri) {
  super(ResourceOperationKind.Rename);
  this.oldUri = Preconditions.<String>checkNotNull(oldUri, "oldUri");
  this.newUri = Preconditions.<String>checkNotNull(newUri, "newUri");
}
 
Example #10
Source File: RenameFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public RenameFile(@NonNull final String oldUri, @NonNull final String newUri, final RenameFileOptions options) {
  super(ResourceOperationKind.Rename);
  this.oldUri = Preconditions.<String>checkNotNull(oldUri, "oldUri");
  this.newUri = Preconditions.<String>checkNotNull(newUri, "newUri");
  this.options = options;
}
 
Example #11
Source File: DeleteFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public DeleteFile() {
  super(ResourceOperationKind.Delete);
}
 
Example #12
Source File: DeleteFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public DeleteFile(@NonNull final String uri) {
  super(ResourceOperationKind.Delete);
  this.uri = Preconditions.<String>checkNotNull(uri, "uri");
}
 
Example #13
Source File: DeleteFile.java    From lsp4j with Eclipse Public License 2.0 4 votes vote down vote up
public DeleteFile(@NonNull final String uri, final DeleteFileOptions options) {
  super(ResourceOperationKind.Delete);
  this.uri = Preconditions.<String>checkNotNull(uri, "uri");
  this.options = options;
}