1//===--- Protocol.cpp - Language Server Protocol Implementation -----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains the serialization code for the PDLL specific LSP structs.
10//
11//===----------------------------------------------------------------------===//
12
13#include "Protocol.h"
14#include "mlir/Support/LLVM.h"
15#include "llvm/Support/ErrorHandling.h"
16#include "llvm/Support/JSON.h"
17
18using namespace mlir;
19using namespace mlir::lsp;
20
21//===----------------------------------------------------------------------===//
22// PDLLViewOutputParams
23//===----------------------------------------------------------------------===//
24
25bool mlir::lsp::fromJSON(const llvm::json::Value &value,
26 PDLLViewOutputKind &result, llvm::json::Path path) {
27 if (std::optional<StringRef> str = value.getAsString()) {
28 if (*str == "ast") {
29 result = PDLLViewOutputKind::AST;
30 return true;
31 }
32 if (*str == "mlir") {
33 result = PDLLViewOutputKind::MLIR;
34 return true;
35 }
36 if (*str == "cpp") {
37 result = PDLLViewOutputKind::CPP;
38 return true;
39 }
40 }
41 return false;
42}
43
44bool mlir::lsp::fromJSON(const llvm::json::Value &value,
45 PDLLViewOutputParams &result, llvm::json::Path path) {
46 llvm::json::ObjectMapper o(value, path);
47 return o && o.map(Prop: "uri", Out&: result.uri) && o.map(Prop: "kind", Out&: result.kind);
48}
49
50//===----------------------------------------------------------------------===//
51// PDLLViewOutputResult
52//===----------------------------------------------------------------------===//
53
54llvm::json::Value mlir::lsp::toJSON(const PDLLViewOutputResult &value) {
55 return llvm::json::Object{{.K: "output", .V: value.output}};
56}
57