MLIR 24.0.0git
Protocol.cpp
Go to the documentation of this file.
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") {
30 return true;
31 }
32 if (*str == "mlir") {
34 return true;
35 }
36 if (*str == "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("uri", result.uri) && o.map("kind", result.kind);
48}
49
50//===----------------------------------------------------------------------===//
51// PDLLViewOutputResult
52//===----------------------------------------------------------------------===//
53
54llvm::json::Value mlir::lsp::toJSON(const PDLLViewOutputResult &value) {
55 return llvm::json::Object{{"output", value.output}};
56}
bool fromJSON(const llvm::json::Value &value, PDLLViewOutputKind &result, llvm::json::Path path)
Add support for JSON serialization.
Definition Protocol.cpp:25
PDLLViewOutputKind
The type of output to view from PDLL.
Definition Protocol.h:34
llvm::json::Value toJSON(const PDLLViewOutputResult &value)
Add support for JSON serialization.
Definition Protocol.cpp:54
Include the generated interface declarations.
Represents the parameters used when viewing the output of a PDLL file.
Definition Protocol.h:41
Represents the result of viewing the output of a PDLL file.
Definition Protocol.h:60
std::string output
The string representation of the output.
Definition Protocol.h:62