Skip to content

Commit 305d718

Browse files
committed
[mlir][NFC] Move the headers for lsp-server-support to include/
This makes it a bit easier to share the functionality for building language servers, and makes the API public. No real functional change, as the API was already intended for this anyways. Differential Revision: https://reviews.llvm.org/D142790
1 parent 90b60f9 commit 305d718

22 files changed

+76
-63
lines changed

mlir/lib/Tools/lsp-server-support/CompilationDatabase.h renamed to mlir/include/mlir/Tools/lsp-server-support/CompilationDatabase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16-
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H_
17-
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H_
16+
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
17+
#define MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H
1818

1919
#include "mlir/Support/LLVM.h"
2020
#include "llvm/ADT/StringMap.h"
@@ -67,4 +67,4 @@ class CompilationDatabase {
6767
} // namespace lsp
6868
} // namespace mlir
6969

70-
#endif // LIB_MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H_
70+
#endif // MLIR_TOOLS_LSPSERVERSUPPORT_COMPILATIONDATABASE_H

mlir/lib/Tools/lsp-server-support/Logging.h renamed to mlir/include/mlir/Tools/lsp-server-support/Logging.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

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

1212
#include "mlir/Support/LLVM.h"
1313
#include "llvm/Support/Debug.h"
@@ -62,4 +62,4 @@ class Logger {
6262
} // namespace lsp
6363
} // namespace mlir
6464

65-
#endif // LIB_MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H
65+
#endif // MLIR_TOOLS_LSPSERVERSUPPORT_LOGGING_H

mlir/lib/Tools/lsp-server-support/Protocol.h renamed to mlir/include/mlir/Tools/lsp-server-support/Protocol.h

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

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

2626
#include "mlir/Support/LLVM.h"
2727
#include "llvm/Support/JSON.h"
2828
#include "llvm/Support/SourceMgr.h"
2929
#include "llvm/Support/raw_ostream.h"
3030
#include <bitset>
3131
#include <memory>
32+
#include <optional>
3233
#include <string>
3334
#include <utility>
3435
#include <vector>
35-
#include <optional>
3636

3737
namespace mlir {
3838
struct LogicalResult;

mlir/lib/Tools/lsp-server-support/SourceMgrUtils.h renamed to mlir/include/mlir/Tools/lsp-server-support/SourceMgrUtils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
15-
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
14+
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
15+
#define MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
1616

17-
#include "Protocol.h"
17+
#include "mlir/Tools/lsp-server-support/Protocol.h"
1818
#include "llvm/Support/SourceMgr.h"
1919
#include <optional>
2020

@@ -27,7 +27,7 @@ namespace lsp {
2727
/// Returns the range of a lexical token given a SMLoc corresponding to the
2828
/// start of an token location. The range is computed heuristically, and
2929
/// supports identifier-like tokens, strings, etc.
30-
SMRange convertTokenLocToRange(SMLoc loc);
30+
SMRange convertTokenLocToRange(SMLoc loc, StringRef identifierChars = "");
3131

3232
/// Extract a documentation comment for the given location within the source
3333
/// manager. Returns std::nullopt if no comment could be computed.

mlir/lib/Tools/lsp-server-support/Transport.h renamed to mlir/include/mlir/Tools/lsp-server-support/Transport.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#ifndef LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
16-
#define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
15+
#ifndef MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
16+
#define MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H
1717

18-
#include "Logging.h"
19-
#include "Protocol.h"
2018
#include "mlir/Support/LLVM.h"
2119
#include "mlir/Support/LogicalResult.h"
20+
#include "mlir/Tools/lsp-server-support/Logging.h"
21+
#include "mlir/Tools/lsp-server-support/Protocol.h"
2222
#include "llvm/ADT/FunctionExtras.h"
2323
#include "llvm/ADT/StringMap.h"
2424
#include "llvm/ADT/StringRef.h"

mlir/lib/Tools/lsp-server-support/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_mlir_library(MLIRLspServerSupportLib
66
Transport.cpp
77

88
ADDITIONAL_HEADER_DIRS
9-
${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/lsp-server
9+
${MLIR_MAIN_INCLUDE_DIR}/mlir/Tools/lsp-server-support
1010

1111
LINK_LIBS PUBLIC
1212
MLIRSupport

mlir/lib/Tools/lsp-server-support/CompilationDatabase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "CompilationDatabase.h"
10-
#include "../lsp-server-support/Logging.h"
11-
#include "Protocol.h"
9+
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
1210
#include "mlir/Support/FileUtilities.h"
11+
#include "mlir/Tools/lsp-server-support/Logging.h"
12+
#include "mlir/Tools/lsp-server-support/Protocol.h"
1313
#include "llvm/ADT/SetVector.h"
1414
#include "llvm/ADT/StringRef.h"
1515
#include "llvm/Support/YAMLTraits.h"

mlir/lib/Tools/lsp-server-support/Logging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "Logging.h"
9+
#include "mlir/Tools/lsp-server-support/Logging.h"
1010
#include "llvm/Support/Chrono.h"
1111
#include "llvm/Support/ManagedStatic.h"
1212
#include "llvm/Support/raw_ostream.h"

mlir/lib/Tools/lsp-server-support/Protocol.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "Protocol.h"
14-
#include "Logging.h"
13+
#include "mlir/Tools/lsp-server-support/Protocol.h"
1514
#include "mlir/Support/LogicalResult.h"
15+
#include "mlir/Tools/lsp-server-support/Logging.h"
1616
#include "llvm/ADT/Hashing.h"
1717
#include "llvm/ADT/SmallString.h"
1818
#include "llvm/ADT/StringSet.h"

mlir/lib/Tools/lsp-server-support/SourceMgrUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "SourceMgrUtils.h"
9+
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
1010
#include "llvm/Support/Path.h"
1111
#include <optional>
1212

@@ -43,7 +43,7 @@ static const char *lexLocStringTok(const char *curPtr) {
4343
return curPtr - 1;
4444
}
4545

46-
SMRange lsp::convertTokenLocToRange(SMLoc loc) {
46+
SMRange lsp::convertTokenLocToRange(SMLoc loc, StringRef identifierChars) {
4747
if (!loc.isValid())
4848
return SMRange();
4949
const char *curPtr = loc.getPointer();
@@ -55,8 +55,8 @@ SMRange lsp::convertTokenLocToRange(SMLoc loc) {
5555
// Otherwise, default to handling an identifier.
5656
} else {
5757
// Return if the given character is a valid identifier character.
58-
auto isIdentifierChar = [](char c) {
59-
return isalnum(c) || c == '$' || c == '.' || c == '_' || c == '-';
58+
auto isIdentifierChar = [=](char c) {
59+
return isalnum(c) || c == '_' || identifierChars.contains(c);
6060
};
6161

6262
while (*curPtr && isIdentifierChar(*(++curPtr)))

mlir/lib/Tools/lsp-server-support/Transport.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "Transport.h"
10-
#include "Logging.h"
11-
#include "Protocol.h"
9+
#include "mlir/Tools/lsp-server-support/Transport.h"
10+
#include "mlir/Tools/lsp-server-support/Logging.h"
11+
#include "mlir/Tools/lsp-server-support/Protocol.h"
1212
#include "llvm/ADT/SmallString.h"
1313
#include "llvm/Support/Errno.h"
1414
#include "llvm/Support/Error.h"
15+
#include <optional>
1516
#include <system_error>
1617
#include <utility>
17-
#include <optional>
1818

1919
using namespace mlir;
2020
using namespace mlir::lsp;

mlir/lib/Tools/mlir-lsp-server/LSPServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "LSPServer.h"
10-
#include "../lsp-server-support/Logging.h"
11-
#include "../lsp-server-support/Transport.h"
1210
#include "MLIRServer.h"
1311
#include "Protocol.h"
12+
#include "mlir/Tools/lsp-server-support/Logging.h"
13+
#include "mlir/Tools/lsp-server-support/Transport.h"
1414
#include "llvm/ADT/FunctionExtras.h"
1515
#include "llvm/ADT/StringMap.h"
1616
#include <optional>

mlir/lib/Tools/mlir-lsp-server/MLIRServer.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "MLIRServer.h"
10-
#include "../lsp-server-support/Logging.h"
11-
#include "../lsp-server-support/SourceMgrUtils.h"
1210
#include "Protocol.h"
1311
#include "mlir/AsmParser/AsmParser.h"
1412
#include "mlir/AsmParser/AsmParserState.h"
@@ -17,12 +15,21 @@
1715
#include "mlir/IR/FunctionInterfaces.h"
1816
#include "mlir/IR/Operation.h"
1917
#include "mlir/Parser/Parser.h"
18+
#include "mlir/Tools/lsp-server-support/Logging.h"
19+
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
2020
#include "llvm/Support/Base64.h"
2121
#include "llvm/Support/SourceMgr.h"
2222
#include <optional>
2323

2424
using namespace mlir;
2525

26+
/// Returns the range of a lexical token given a SMLoc corresponding to the
27+
/// start of an token location. The range is computed heuristically, and
28+
/// supports identifier-like tokens, strings, etc.
29+
static SMRange convertTokenLocToRange(SMLoc loc) {
30+
return lsp::convertTokenLocToRange(loc, "$-.");
31+
}
32+
2633
/// Returns a language server location from the given MLIR file location.
2734
/// `uriScheme` is the scheme to use when building new uris.
2835
static std::optional<lsp::Location> getLocationFromLoc(StringRef uriScheme,
@@ -65,7 +72,7 @@ getLocationFromLoc(llvm::SourceMgr &sourceMgr, Location loc,
6572
// Use range of potential identifier starting at location, else length 1
6673
// range.
6774
location->range.end.character += 1;
68-
if (std::optional<SMRange> range = lsp::convertTokenLocToRange(loc)) {
75+
if (std::optional<SMRange> range = convertTokenLocToRange(loc)) {
6976
auto lineCol = sourceMgr.getLineAndColumn(range->End);
7077
location->range.end.character =
7178
std::max(fileLoc.getColumn() + 1, lineCol.second - 1);

mlir/lib/Tools/mlir-lsp-server/MlirLspServerMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h"
10-
#include "../lsp-server-support/Logging.h"
11-
#include "../lsp-server-support/Transport.h"
1210
#include "LSPServer.h"
1311
#include "MLIRServer.h"
1412
#include "mlir/IR/Dialect.h"
13+
#include "mlir/Tools/lsp-server-support/Logging.h"
14+
#include "mlir/Tools/lsp-server-support/Transport.h"
1515
#include "llvm/Support/CommandLine.h"
1616
#include "llvm/Support/Program.h"
1717

mlir/lib/Tools/mlir-lsp-server/Protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_PROTOCOL_H_
2121
#define LIB_MLIR_TOOLS_MLIRLSPSERVER_PROTOCOL_H_
2222

23-
#include "../lsp-server-support/Protocol.h"
23+
#include "mlir/Tools/lsp-server-support/Protocol.h"
2424

2525
namespace mlir {
2626
namespace lsp {

mlir/lib/Tools/mlir-pdll-lsp-server/LSPServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
#include "LSPServer.h"
1010

11-
#include "../lsp-server-support/Logging.h"
12-
#include "../lsp-server-support/Transport.h"
1311
#include "PDLLServer.h"
1412
#include "Protocol.h"
13+
#include "mlir/Tools/lsp-server-support/Logging.h"
14+
#include "mlir/Tools/lsp-server-support/Transport.h"
1515
#include "llvm/ADT/FunctionExtras.h"
1616
#include "llvm/ADT/StringMap.h"
1717
#include <optional>

mlir/lib/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "mlir/Tools/mlir-pdll-lsp-server/MlirPdllLspServerMain.h"
10-
#include "../lsp-server-support/Logging.h"
11-
#include "../lsp-server-support/Transport.h"
1210
#include "LSPServer.h"
1311
#include "PDLLServer.h"
12+
#include "mlir/Tools/lsp-server-support/Logging.h"
13+
#include "mlir/Tools/lsp-server-support/Transport.h"
1414
#include "llvm/Support/CommandLine.h"
1515
#include "llvm/Support/Program.h"
1616

mlir/lib/Tools/mlir-pdll-lsp-server/PDLLServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
#include "PDLLServer.h"
1010

11-
#include "../lsp-server-support/CompilationDatabase.h"
12-
#include "../lsp-server-support/Logging.h"
13-
#include "../lsp-server-support/SourceMgrUtils.h"
1411
#include "Protocol.h"
1512
#include "mlir/IR/BuiltinOps.h"
1613
#include "mlir/Tools/PDLL/AST/Context.h"
@@ -24,6 +21,9 @@
2421
#include "mlir/Tools/PDLL/ODS/Operation.h"
2522
#include "mlir/Tools/PDLL/Parser/CodeComplete.h"
2623
#include "mlir/Tools/PDLL/Parser/Parser.h"
24+
#include "mlir/Tools/lsp-server-support/CompilationDatabase.h"
25+
#include "mlir/Tools/lsp-server-support/Logging.h"
26+
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
2727
#include "llvm/ADT/IntervalMap.h"
2828
#include "llvm/ADT/StringMap.h"
2929
#include "llvm/ADT/StringSet.h"

mlir/lib/Tools/mlir-pdll-lsp-server/Protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#ifndef LIB_MLIR_TOOLS_MLIRPDLLLSPSERVER_PROTOCOL_H_
2121
#define LIB_MLIR_TOOLS_MLIRPDLLLSPSERVER_PROTOCOL_H_
2222

23-
#include "../lsp-server-support/Protocol.h"
23+
#include "mlir/Tools/lsp-server-support/Protocol.h"
2424

2525
namespace mlir {
2626
namespace lsp {

mlir/lib/Tools/tblgen-lsp-server/LSPServer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
#include "LSPServer.h"
1010

11-
#include "../lsp-server-support/Logging.h"
12-
#include "../lsp-server-support/Protocol.h"
13-
#include "../lsp-server-support/Transport.h"
1411
#include "TableGenServer.h"
12+
#include "mlir/Tools/lsp-server-support/Logging.h"
13+
#include "mlir/Tools/lsp-server-support/Protocol.h"
14+
#include "mlir/Tools/lsp-server-support/Transport.h"
1515
#include "llvm/ADT/FunctionExtras.h"
1616
#include "llvm/ADT/StringMap.h"
1717
#include <optional>

mlir/lib/Tools/tblgen-lsp-server/TableGenLspServerMain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "mlir/Tools/tblgen-lsp-server/TableGenLspServerMain.h"
10-
#include "../lsp-server-support/Logging.h"
11-
#include "../lsp-server-support/Transport.h"
1210
#include "LSPServer.h"
1311
#include "TableGenServer.h"
12+
#include "mlir/Tools/lsp-server-support/Logging.h"
13+
#include "mlir/Tools/lsp-server-support/Transport.h"
1414
#include "llvm/Support/CommandLine.h"
1515
#include "llvm/Support/Program.h"
1616

0 commit comments

Comments
 (0)