51 lines · cpp
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-exception6//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_TESTS19namespace test {20void registerTestDialect(DialectRegistry &);21void registerTestDynDialect(DialectRegistry &);22void registerTestTransformDialectExtension(DialectRegistry &);23} // namespace test24#endif25 26int main(int argc, char **argv) {27 DialectRegistry registry, empty;28 registerAllDialects(registry);29 registerAllExtensions(registry);30 31#ifdef MLIR_INCLUDE_TESTS32 ::test::registerTestDialect(registry);33 ::test::registerTestTransformDialectExtension(registry);34 ::test::registerTestDynDialect(registry);35#endif36 37 // Returns the registry, except in testing mode when the URI contains38 // "-disable-lsp-registration". Testing for/example of registering dialects39 // based on URI.40 auto registryFn = [®istry, &empty](41 const llvm::lsp::URIForFile &uri) -> DialectRegistry & {42 (void)empty;43#ifdef MLIR_INCLUDE_TESTS44 if (uri.uri().contains("-disable-lsp-registration"))45 return empty;46#endif47 return registry;48 };49 return failed(MlirLspServerMain(argc, argv, registryFn));50}51