23 #ifndef MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
24 #define MLIR_TOOLS_LSPSERVERSUPPORT_PROTOCOL_H
27 #include "llvm/Support/JSON.h"
28 #include "llvm/Support/SourceMgr.h"
29 #include "llvm/Support/raw_ostream.h"
75 class LSPError :
public llvm::ErrorInfo<LSPError> {
84 void log(raw_ostream &os)
const override {
88 return llvm::inconvertibleErrorCode();
107 StringRef
scheme =
"file");
110 StringRef
file()
const {
return filePath; }
113 StringRef
uri()
const {
return uriStr; }
118 explicit operator bool()
const {
return !filePath.empty(); }
121 return lhs.filePath == rhs.filePath;
124 return !(lhs == rhs);
127 return lhs.filePath < rhs.filePath;
136 explicit URIForFile(std::string &&filePath, std::string &&uriStr)
137 : filePath(std::move(filePath)), uriStr(uriStr) {}
139 std::string filePath;
144 llvm::json::Value
toJSON(
const URIForFile &value);
145 bool fromJSON(
const llvm::json::Value &value, URIForFile &result,
146 llvm::json::Path path);
147 raw_ostream &
operator<<(raw_ostream &os,
const URIForFile &value);
165 llvm::json::Path path);
181 llvm::json::Path path);
195 llvm::json::Path path);
210 llvm::json::Path path);
242 llvm::json::Path path);
256 llvm::json::Path path);
271 bool fromJSON(
const llvm::json::Value &value,
284 std::pair<unsigned, unsigned> lineAndCol = mgr.getLineAndColumn(loc);
285 line = lineAndCol.first - 1;
300 return !(lhs == rhs);
314 return mgr.FindLocForLineAndColumn(mgr.getMainFileID(),
line + 1,
320 bool fromJSON(
const llvm::json::Value &value, Position &result,
321 llvm::json::Path path);
322 llvm::json::Value
toJSON(
const Position &value);
323 raw_ostream &
operator<<(raw_ostream &os,
const Position &value);
335 Range(llvm::SourceMgr &mgr, SMRange range)
348 return !(lhs == rhs);
365 if (!startLoc.isValid() || !endLoc.isValid() ||
366 startLoc.getPointer() > endLoc.getPointer())
368 return SMRange(startLoc, endLoc);
374 llvm::json::Path path);
399 return !(lhs == rhs);
409 llvm::json::Path path);
426 bool fromJSON(
const llvm::json::Value &value,
440 llvm::json::Path path);
448 llvm::json::Path path);
461 llvm::json::Path path);
473 bool fromJSON(
const llvm::json::Value &value,
482 LogicalResult
applyTo(std::string &contents)
const;
485 std::string &contents);
498 bool fromJSON(
const llvm::json::Value &value,
510 bool fromJSON(
const llvm::json::Value &value,
638 llvm::json::Path path);
659 bool fromJSON(
const llvm::json::Value &value,
685 llvm::json::Path path);
707 std::vector<DiagnosticTag>
tags;
719 llvm::json::Path path);
758 bool fromJSON(
const llvm::json::Value &value, TextEdit &result,
759 llvm::json::Path path);
760 llvm::json::Value
toJSON(
const TextEdit &value);
761 raw_ostream &
operator<<(raw_ostream &os,
const TextEdit &value);
797 llvm::json::Path path);
805 llvm::json::Path path);
937 llvm::json::Path path);
949 llvm::json::Path path);
1022 llvm::json::Path path);
1053 return !(lhs == rhs);
1058 llvm::json::Value
toJSON(
const DocumentLink &value);
1075 llvm::json::Path path);
1162 llvm::json::Path path);
1181 llvm::json::Path path);
1189 std::map<std::string, std::vector<TextEdit>>
changes;
1197 llvm::json::Path path);
1242 struct format_provider<
mlir::lsp::Position> {
1245 assert(style.empty() &&
"style modifiers for this type are not supported");
static std::string diag(const llvm::Value &value)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
This class models an LSP error as an llvm::Error.
std::error_code convertToErrorCode() const override
LSPError(std::string message, ErrorCode code)
void log(raw_ostream &os) const override
URI in "file" scheme for a file.
StringRef uri() const
Returns the original uri of the file.
friend bool operator==(const URIForFile &lhs, const URIForFile &rhs)
static void registerSupportedScheme(StringRef scheme)
Register a supported URI scheme.
static llvm::Expected< URIForFile > fromFile(StringRef absoluteFilepath, StringRef scheme="file")
Try to build a URIForFile from the given absolute file path and optional scheme.
static llvm::Expected< URIForFile > fromURI(StringRef uri)
Try to build a URIForFile from the given URI string.
StringRef scheme() const
Return the scheme of the uri.
friend bool operator!=(const URIForFile &lhs, const URIForFile &rhs)
friend bool operator<(const URIForFile &lhs, const URIForFile &rhs)
StringRef file() const
Returns the absolute path to the file.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
llvm::json::Value toJSON(const URIForFile &value)
Add support for JSON serialization.
raw_ostream & operator<<(raw_ostream &os, const URIForFile &value)
@ Undetermined
It is up to the client to interpret diagnostics as error, warning, info or hint.
bool operator<(const CompletionItem &lhs, const CompletionItem &rhs)
constexpr auto kCompletionItemKindMin
TextDocumentSyncKind
Defines how the host (editor) should sync document changes to the language server.
@ Incremental
Documents are synced by sending the full content on open.
@ None
Documents should not be synced at all.
@ Full
Documents are synced by always sending the full content of the document.
MarkupKind
Describes the content type that a client supports in various result literals like Hover.
bool fromJSON(const llvm::json::Value &value, URIForFile &result, llvm::json::Path path)
CompletionItemKind adjustKindToCapability(CompletionItemKind kind, CompletionItemKindBitset &supportedCompletionItemKinds)
std::bitset< kCompletionItemKindMax+1 > CompletionItemKindBitset
constexpr auto kCompletionItemKindMax
InsertTextFormat
Defines whether the insert text in a completion item should be interpreted as plain text or a snippet...
@ PlainText
The primary text to be inserted is treated as a plain string.
@ Snippet
The primary text to be inserted is treated as a snippet.
@ Invoked
Completion was triggered by typing an identifier (24x7 code complete), manual invocation (e....
@ TriggerTriggerForIncompleteCompletions
Completion was re-triggered as the current completion list is incomplete.
@ TriggerCharacter
Completion was triggered by a trigger character specified by the triggerCharacters properties of the ...
InlayHintKind
Inlay hint kinds.
@ Parameter
An inlay hint that is for a parameter.
CompletionItemKind
The kind of a completion entry.
bool operator==(const TextEdit &lhs, const TextEdit &rhs)
Include the generated interface declarations.
Represents a range (offset, size, and stride) where each element of the triple may be dynamic or stat...
bool codeActionStructure
Client supports CodeAction return value for textDocument/codeAction.
bool hierarchicalDocumentSymbol
Client supports hierarchical document symbols.
std::string name
The name of the client as defined by the client.
std::optional< std::string > version
The client's version as defined by the client.
std::vector< std::string > only
Requested kind of actions to return.
std::vector< Diagnostic > diagnostics
An array of diagnostics known on the client side overlapping the range provided to the textDocument/c...
TextDocumentIdentifier textDocument
The document in which the command was invoked.
Range range
The range for which the command was invoked.
CodeActionContext context
Context carrying additional information.
A code action represents a change that can be performed in code, e.g.
bool isPreferred
Marks this as a preferred action.
std::optional< WorkspaceEdit > edit
The workspace edit this code action performs.
std::optional< std::string > kind
The kind of the code action.
static const llvm::StringLiteral kRefactor
static const llvm::StringLiteral kInfo
std::optional< std::vector< Diagnostic > > diagnostics
The diagnostics that this code action resolves.
static const llvm::StringLiteral kQuickFix
std::string title
A short, human-readable, title for this code action.
std::string triggerCharacter
The trigger character (a single character) that has trigger code complete.
CompletionTriggerKind triggerKind
How the completion was triggered.
std::string detail
A human-readable string with additional information about this item, like type or symbol information.
std::string filterText
A string that should be used when filtering a set of completion items.
std::optional< TextEdit > textEdit
An edit which is applied to a document when selecting this completion.
std::optional< MarkupContent > documentation
A human-readable string that represents a doc-comment.
std::string insertText
A string that should be inserted to a document when selecting this completion.
CompletionItem(const Twine &label, CompletionItemKind kind, StringRef sortText="")
std::string label
The label of this completion item.
bool deprecated
Indicates if this item is deprecated.
CompletionItemKind kind
The kind of this completion item.
std::vector< TextEdit > additionalTextEdits
An optional array of additional text edits that are applied when selecting this completion.
InsertTextFormat insertTextFormat
The format of the insert text.
std::string sortText
A string that should be used when comparing this item with other items.
Represents a collection of completion items to be presented in the editor.
std::vector< CompletionItem > items
The completion items.
bool isIncomplete
The list is not complete.
CompletionContext context
std::vector< DiagnosticTag > tags
Additional metadata about the diagnostic.
std::string source
A human-readable string describing the source of this diagnostic, e.g.
DiagnosticSeverity severity
The diagnostic's severity.
Range range
The source range where the message applies.
std::optional< std::vector< DiagnosticRelatedInformation > > relatedInformation
An array of related diagnostic information, e.g.
std::string message
The diagnostic's message.
std::optional< std::string > category
The diagnostic's category.
VersionedTextDocumentIdentifier textDocument
The document that changed.
std::vector< TextDocumentContentChangeEvent > contentChanges
The actual content changes.
TextDocumentIdentifier textDocument
The document that was closed.
TextDocumentItem textDocument
The document that was opened.
Parameters for the document link request.
TextDocumentIdentifier textDocument
The document to provide document links for.
A range in a text document that links to an internal or external resource, like another text document...
friend bool operator!=(const DocumentLink &lhs, const DocumentLink &rhs)
Range range
The range this link applies to.
DocumentLink(Range range, URIForFile target)
URIForFile target
The uri this link points to. If missing a resolve request is sent later.
friend bool operator==(const DocumentLink &lhs, const DocumentLink &rhs)
TextDocumentIdentifier textDocument
Represents programming constructs like variables, classes, interfaces etc.
std::string detail
More detail for this symbol, e.g the signature of a function.
Range range
The range enclosing this symbol not including leading/trailing whitespace but everything else like co...
Range selectionRange
The range that should be selected and revealed when this symbol is being picked, e....
DocumentSymbol(const Twine &name, SymbolKind kind, Range range, Range selectionRange)
std::vector< DocumentSymbol > children
Children of this symbol, e.g. properties of a class.
DocumentSymbol(DocumentSymbol &&)=default
SymbolKind kind
The kind of this symbol.
std::string name
The name of this symbol.
std::optional< Range > range
An optional range is a range inside a text document that is used to visualize a hover,...
MarkupContent contents
The hover's content.
Hover(Range range)
Construct a default hover with the given range that uses Markdown content.
std::optional< ClientInfo > clientInfo
Information about the client.
ClientCapabilities capabilities
The capabilities provided by the client (editor or tool).
std::optional< TraceLevel > trace
The initial trace setting. If omitted trace is disabled ('off').
bool paddingLeft
Render padding before the hint.
InlayHintKind kind
The kind of this hint.
Position position
The position of this hint.
bool paddingRight
Render padding after the hint.
std::string label
The label of this hint.
InlayHint(InlayHintKind kind, Position pos)
A parameter literal used in inlay hint requests.
Range range
The visible document range for which inlay hints should be computed.
TextDocumentIdentifier textDocument
The text document.
URIForFile uri
The text document's URI.
Location(const URIForFile &uri, Range range)
friend bool operator<(const Location &lhs, const Location &rhs)
Location(const URIForFile &uri, llvm::SourceMgr &mgr, SMRange range)
Construct a Location from the given source range.
friend bool operator!=(const Location &lhs, const Location &rhs)
friend bool operator==(const Location &lhs, const Location &rhs)
int line
Line position in a document (zero-based).
Position(llvm::SourceMgr &mgr, SMLoc loc)
Construct a position from the given source location.
int character
Character offset on a line in a document (zero-based).
friend bool operator==(const Position &lhs, const Position &rhs)
Position(int line=0, int character=0)
friend bool operator<(const Position &lhs, const Position &rhs)
friend bool operator<=(const Position &lhs, const Position &rhs)
SMLoc getAsSMLoc(llvm::SourceMgr &mgr) const
Convert this position into a source location in the main file of the given source manager.
friend bool operator!=(const Position &lhs, const Position &rhs)
std::vector< Diagnostic > diagnostics
The list of reported diagnostics.
URIForFile uri
The URI for which diagnostic information is reported.
PublishDiagnosticsParams(URIForFile uri, int64_t version)
int64_t version
The version number of the document the diagnostics are published for.
Position end
The range's end position.
Range(llvm::SourceMgr &mgr, SMRange range)
Construct a range from the given source range.
friend bool operator!=(const Range &lhs, const Range &rhs)
Range(Position start, Position end)
friend bool operator<(const Range &lhs, const Range &rhs)
bool contains(Position pos) const
bool contains(Range range) const
friend bool operator==(const Range &lhs, const Range &rhs)
Position start
The range's start position.
SMRange getAsSMRange(llvm::SourceMgr &mgr) const
Convert this range into a source range in the main file of the given source manager.
bool includeDeclaration
Include the declaration of the current symbol.
Represents the signature of a callable.
int activeSignature
The active signature.
int activeParameter
The active parameter of the active signature.
std::vector< SignatureInformation > signatures
The resulting signatures.
std::string text
The new text of the range/document.
LogicalResult applyTo(std::string &contents) const
Try to apply this change to the given contents string.
std::optional< Range > range
The range of the document that changed.
std::optional< int > rangeLength
The length of the range that got replaced.
URIForFile uri
The text document's URI.
std::string languageId
The text document's language identifier.
int64_t version
The version number of this document.
std::string text
The content of the opened text document.
URIForFile uri
The text document's URI.
TextDocumentIdentifier textDocument
The text document.
Position position
The position inside the text document.
std::string newText
The string to be inserted.
Range range
The range of the text document to be manipulated.
int64_t version
The version number of this document.
URIForFile uri
The text document's URI.
std::map< std::string, std::vector< TextEdit > > changes
Holds changes to existing resources.