1 //===- MLIRServer.h - MLIR General Language Server --------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_
10 #define LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_
12 #include "mlir/Support/LLVM.h"
13 #include "llvm/Support/Error.h"
18 class DialectRegistry
;
22 struct CodeActionContext
;
23 struct CompletionList
;
25 struct DocumentSymbol
;
28 struct MLIRConvertBytecodeResult
;
33 /// This class implements all of the MLIR related functionality necessary for a
34 /// language server. This class allows for keeping the MLIR specific logic
35 /// separate from the logic that involves LSP server/client communication.
38 /// Construct a new server with the given dialect regitstry.
39 MLIRServer(DialectRegistry
®istry
);
42 /// Add or update the document, with the provided `version`, at the given URI.
43 /// Any diagnostics emitted for this document should be added to
45 void addOrUpdateDocument(const URIForFile
&uri
, StringRef contents
,
47 std::vector
<Diagnostic
> &diagnostics
);
49 /// Remove the document with the given uri. Returns the version of the removed
50 /// document, or std::nullopt if the uri did not have a corresponding document
51 /// within the server.
52 std::optional
<int64_t> removeDocument(const URIForFile
&uri
);
54 /// Return the locations of the object pointed at by the given position.
55 void getLocationsOf(const URIForFile
&uri
, const Position
&defPos
,
56 std::vector
<Location
> &locations
);
58 /// Find all references of the object pointed at by the given position.
59 void findReferencesOf(const URIForFile
&uri
, const Position
&pos
,
60 std::vector
<Location
> &references
);
62 /// Find a hover description for the given hover position, or std::nullopt if
63 /// one couldn't be found.
64 std::optional
<Hover
> findHover(const URIForFile
&uri
,
65 const Position
&hoverPos
);
67 /// Find all of the document symbols within the given file.
68 void findDocumentSymbols(const URIForFile
&uri
,
69 std::vector
<DocumentSymbol
> &symbols
);
71 /// Get the code completion list for the position within the given file.
72 CompletionList
getCodeCompletion(const URIForFile
&uri
,
73 const Position
&completePos
);
75 /// Get the set of code actions within the file.
76 void getCodeActions(const URIForFile
&uri
, const Range
&pos
,
77 const CodeActionContext
&context
,
78 std::vector
<CodeAction
> &actions
);
80 /// Convert the given bytecode file to the textual format.
81 llvm::Expected
<MLIRConvertBytecodeResult
>
82 convertFromBytecode(const URIForFile
&uri
);
84 /// Convert the given textual file to the bytecode format.
85 llvm::Expected
<MLIRConvertBytecodeResult
>
86 convertToBytecode(const URIForFile
&uri
);
91 std::unique_ptr
<Impl
> impl
;
97 #endif // LIB_MLIR_TOOLS_MLIRLSPSERVER_SERVER_H_