1 | //===- mlir-lsp-server.cpp - MLIR Language Server -------------------------===// |
---|---|
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 | #include "mlir/IR/MLIRContext.h" |
10 | #include "mlir/InitAllDialects.h" |
11 | #include "mlir/InitAllExtensions.h" |
12 | #include "mlir/Tools/lsp-server-support/Protocol.h" |
13 | #include "mlir/Tools/mlir-lsp-server/MlirLspServerMain.h" |
14 | |
15 | using namespace mlir; |
16 | |
17 | #ifdef MLIR_INCLUDE_TESTS |
18 | namespace test { |
19 | void registerTestDialect(DialectRegistry &); |
20 | void registerTestDynDialect(DialectRegistry &); |
21 | void registerTestTransformDialectExtension(DialectRegistry &); |
22 | } // namespace test |
23 | #endif |
24 | |
25 | int main(int argc, char **argv) { |
26 | DialectRegistry registry, empty; |
27 | registerAllDialects(registry); |
28 | registerAllExtensions(registry); |
29 | |
30 | #ifdef MLIR_INCLUDE_TESTS |
31 | ::test::registerTestDialect(registry); |
32 | ::test::registerTestTransformDialectExtension(registry); |
33 | ::test::registerTestDynDialect(registry); |
34 | #endif |
35 | |
36 | // Returns the registry, except in testing mode when the URI contains |
37 | // "-disable-lsp-registration". Testing for/example of registering dialects |
38 | // based on URI. |
39 | auto registryFn = [®istry, |
40 | &empty](const lsp::URIForFile &uri) -> DialectRegistry & { |
41 | (void)empty; |
42 | #ifdef MLIR_INCLUDE_TESTS |
43 | if (uri.uri().contains(Other: "-disable-lsp-registration")) |
44 | return empty; |
45 | #endif |
46 | return registry; |
47 | }; |
48 | return failed(Result: MlirLspServerMain(argc, argv, registry_fn: registryFn)); |
49 | } |
50 |