Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a0b8d54

Browse files
authored
[LLVM][MLIR] Move LSP server support library from MLIR into LLVM (#155572)
This PR moves the generic Language Server Protocol (LSP) server support code that was copied from clangd into MLIR, into the LLVM tree so it can be reused by multiple subprojects. Centralizing the generic LSP support in LLVM lowers the barrier to building new LSP servers across the LLVM ecosystem and avoids each subproject maintaining its own copy. The code originated in clangd and was copied into MLIR for its LSP server. MLIR had this code seperate to be reused by all of their LSP server. This PR relocates the MLIR copy into LLVM as a shared component into `LLVM/Support`. If this is not a suitable place, please suggest a better one. A follow up to this move could be deduplication with the original clangd implementation and converge on a single shared LSP support library used by clangd, MLIR, and future servers. ### What changes * `mlir/include/mlir/Tools/lsp-server-support/{Logging, Protocol, Transport}.h` moved to `llvm/include/llvm/Support/LSP` * `mlir/lib/Tools/lsp-server-support/{Logging, Protocol, Transport}.cpp` moved to `llvm/lib/Support/LSP` and their namespace was changed from `mlir` to `llvm` I ran clang-tidy --fix and clang-format on the whole moved files (last two commits), as they are basically new files and should hold up to the code style used by LLVM. MLIR LSP servers where updated to include these files from their new location and account for the namespace change. This PR is made as part of the LLVM IR LSP project ([RFC](https://discourse.llvm.org/t/rfc-ir-visualization-with-vs-code-extension-using-an-lsp-server/87773))
1 parent 7a58e77 commit a0b8d54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2408
-2231
lines changed
Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
//===- Logging.h - MLIR LSP Server Logging ----------------------*- C++ -*-===//
1+
//===- Logging.h - LSP Server Logging ----------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
10-
#define MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
9+
#ifndef LLVM_SUPPORT_LSP_LOGGING_H
10+
#define LLVM_SUPPORT_LSP_LOGGING_H
1111

12-
#include "mlir/Support/LLVM.h"
1312
#include "llvm/Support/Debug.h"
1413
#include "llvm/Support/FormatVariadic.h"
1514
#include <memory>
1615
#include <mutex>
1716

18-
namespace mlir {
17+
namespace llvm {
1918
namespace lsp {
2019

2120
/// This class represents the main interface for logging, and allows for
@@ -26,21 +25,18 @@ class Logger {
2625
enum class Level { Debug, Info, Error };
2726

2827
/// Set the severity level of the logger.
29-
static void setLogLevel(Level logLevel);
28+
static void setLogLevel(Level LogLevel);
3029

3130
/// Initiate a log message at various severity levels. These should be called
3231
/// after a call to `initialize`.
33-
template <typename... Ts>
34-
static void debug(const char *fmt, Ts &&...vals) {
35-
log(Level::Debug, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
32+
template <typename... Ts> static void debug(const char *Fmt, Ts &&...Vals) {
33+
log(Level::Debug, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
3634
}
37-
template <typename... Ts>
38-
static void info(const char *fmt, Ts &&...vals) {
39-
log(Level::Info, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
35+
template <typename... Ts> static void info(const char *Fmt, Ts &&...Vals) {
36+
log(Level::Info, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
4037
}
41-
template <typename... Ts>
42-
static void error(const char *fmt, Ts &&...vals) {
43-
log(Level::Error, fmt, llvm::formatv(fmt, std::forward<Ts>(vals)...));
38+
template <typename... Ts> static void error(const char *Fmt, Ts &&...Vals) {
39+
log(Level::Error, Fmt, llvm::formatv(Fmt, std::forward<Ts>(Vals)...));
4440
}
4541

4642
private:
@@ -50,16 +46,16 @@ class Logger {
5046
static Logger &get();
5147

5248
/// Start a log message with the given severity level.
53-
static void log(Level logLevel, const char *fmt,
54-
const llvm::formatv_object_base &message);
49+
static void log(Level LogLevel, const char *Fmt,
50+
const llvm::formatv_object_base &Message);
5551

5652
/// The minimum logging level. Messages with lower level are ignored.
57-
Level logLevel = Level::Error;
53+
Level LogLevel = Level::Error;
5854

5955
/// A mutex used to guard logging.
60-
std::mutex mutex;
56+
std::mutex Mutex;
6157
};
6258
} // namespace lsp
63-
} // namespace mlir
59+
} // namespace llvm
6460

65-
#endif // MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
61+
#endif // LLVM_SUPPORT_LSP_LOGGING_H

mlir/include/mlir/Tools/lsp-server-support/Protocol.h renamed to llvm/include/llvm/Support/LSP/Protocol.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,24 @@
2020
//
2121
//===----------------------------------------------------------------------===//
2222

23-
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
24-
#define MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
23+
#ifndef LLVM_SUPPORT_LSP_PROTOCOL_H
24+
#define LLVM_SUPPORT_LSP_PROTOCOL_H
2525

26-
#include "mlir/Support/LLVM.h"
2726
#include "llvm/Support/JSON.h"
27+
#include "llvm/Support/LogicalResult.h"
2828
#include "llvm/Support/SourceMgr.h"
2929
#include "llvm/Support/raw_ostream.h"
3030
#include <bitset>
3131
#include <optional>
3232
#include <string>
3333
#include <utility>
34-
#include <vector>
3534

36-
namespace mlir {
35+
// This file is using the LSP syntax for identifier names which is different
36+
// from the LLVM coding standard. To avoid the clang-tidy warnings, we're
37+
// disabling one check here.
38+
// NOLINTBEGIN(readability-identifier-naming)
39+
40+
namespace llvm {
3741
namespace lsp {
3842

3943
enum class ErrorCode {
@@ -1241,12 +1245,11 @@ struct CodeAction {
12411245
llvm::json::Value toJSON(const CodeAction &);
12421246

12431247
} // namespace lsp
1244-
} // namespace mlir
1248+
} // namespace llvm
12451249

12461250
namespace llvm {
1247-
template <>
1248-
struct format_provider<mlir::lsp::Position> {
1249-
static void format(const mlir::lsp::Position &pos, raw_ostream &os,
1251+
template <> struct format_provider<llvm::lsp::Position> {
1252+
static void format(const llvm::lsp::Position &pos, raw_ostream &os,
12501253
StringRef style) {
12511254
assert(style.empty() && "style modifiers for this type are not supported");
12521255
os << pos;
@@ -1255,3 +1258,5 @@ struct format_provider<mlir::lsp::Position> {
12551258
} // namespace llvm
12561259

12571260
#endif
1261+
1262+
// NOLINTEND(readability-identifier-naming)

0 commit comments

Comments
 (0)