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