MLIR
20.0.0git
|
#include "MLIRServer.h"
#include "Protocol.h"
#include "mlir/AsmParser/AsmParser.h"
#include "mlir/AsmParser/AsmParserState.h"
#include "mlir/AsmParser/CodeComplete.h"
#include "mlir/Bytecode/BytecodeWriter.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/FunctionInterfaces.h"
#include "mlir/Parser/Parser.h"
#include "mlir/Support/ToolUtilities.h"
#include "mlir/Tools/lsp-server-support/Logging.h"
#include "mlir/Tools/lsp-server-support/SourceMgrUtils.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Base64.h"
#include "llvm/Support/SourceMgr.h"
#include <optional>
Go to the source code of this file.
Classes | |
struct | mlir::lsp::MLIRServer::Impl |
Functions | |
static SMRange | convertTokenLocToRange (SMLoc loc) |
Returns the range of a lexical token given a SMLoc corresponding to the start of an token location. More... | |
static std::optional< lsp::Location > | getLocationFromLoc (StringRef uriScheme, FileLineColLoc loc) |
Returns a language server location from the given MLIR file location. More... | |
static std::optional< lsp::Location > | getLocationFromLoc (llvm::SourceMgr &sourceMgr, Location loc, StringRef uriScheme, const lsp::URIForFile *uri=nullptr) |
Returns a language server location from the given MLIR location, or std::nullopt if one couldn't be created. More... | |
static void | collectLocationsFromLoc (Location loc, std::vector< lsp::Location > &locations, const lsp::URIForFile &uri) |
Collect all of the locations from the given MLIR location that are not contained within the given URI. More... | |
static bool | contains (SMRange range, SMLoc loc) |
Returns true if the given range contains the given source location. More... | |
static bool | isDefOrUse (const AsmParserState::SMDefinition &def, SMLoc loc, SMRange *overlappedRange=nullptr) |
Returns true if the given location is contained by the definition or one of the uses of the given SMDefinition. More... | |
static std::optional< unsigned > | getResultNumberFromLoc (SMLoc loc) |
Given a location pointing to a result, return the result number it refers to or std::nullopt if it refers to all of the results. More... | |
static std::optional< StringRef > | getTextFromRange (SMRange range) |
Given a source location range, return the text covered by the given range. More... | |
static unsigned | getBlockNumber (Block *block) |
Given a block, return its position in its parent region. More... | |
static void | printDefBlockName (raw_ostream &os, Block *block, SMRange loc={}) |
Given a block and source location, print the source name of the block to the given output stream. More... | |
static void | printDefBlockName (raw_ostream &os, const AsmParserState::BlockDefinition &def) |
static lsp::Diagnostic | getLspDiagnoticFromDiag (llvm::SourceMgr &sourceMgr, Diagnostic &diag, const lsp::URIForFile &uri) |
Convert the given MLIR diagnostic to the LSP form. More... | |
|
static |
Collect all of the locations from the given MLIR location that are not contained within the given URI.
Definition at line 91 of file MLIRServer.cpp.
References mlir::WalkResult::advance(), getLocationFromLoc(), mlir::lsp::URIForFile::scheme(), and mlir::LocationAttr::walk().
|
static |
Returns true if the given range contains the given source location.
Note that this has slightly different behavior than SMRange because it is inclusive of the end location.
Definition at line 111 of file MLIRServer.cpp.
Referenced by isDefOrUse(), and lexLocStringTok().
|
static |
Returns the range of a lexical token given a SMLoc corresponding to the start of an token location.
The range is computed heuristically, and supports identifier-like tokens, strings, etc.
Definition at line 31 of file MLIRServer.cpp.
References mlir::lsp::convertTokenLocToRange().
Referenced by getLocationFromLoc().
|
static |
Given a block, return its position in its parent region.
Definition at line 176 of file MLIRServer.cpp.
References mlir::Region::begin(), and mlir::Block::getParent().
|
static |
Returns a language server location from the given MLIR location, or std::nullopt if one couldn't be created.
uriScheme
is the scheme to use when building new uris. uri
is an optional additional filter that, when present, is used to filter sub locations that do not share the same uri.
Definition at line 59 of file MLIRServer.cpp.
References mlir::WalkResult::advance(), convertTokenLocToRange(), mlir::FileLineColLoc::getColumn(), mlir::FileLineColLoc::getLine(), getLocationFromLoc(), mlir::WalkResult::interrupt(), max(), and mlir::LocationAttr::walk().
|
static |
Returns a language server location from the given MLIR file location.
uriScheme
is the scheme to use when building new uris.
Definition at line 37 of file MLIRServer.cpp.
References mlir::lsp::Position::character, mlir::lsp::Logger::error(), mlir::lsp::URIForFile::fromFile(), mlir::FileLineColLoc::getColumn(), mlir::FileLineColLoc::getFilename(), mlir::FileLineColLoc::getLine(), mlir::lsp::Position::line, and toString().
Referenced by collectLocationsFromLoc(), getLocationFromLoc(), and getLspDiagnoticFromDiag().
|
static |
Convert the given MLIR diagnostic to the LSP form.
Definition at line 199 of file MLIRServer.cpp.
References mlir::lsp::Diagnostic::category, diag(), mlir::Error, mlir::lsp::Error, getLocationFromLoc(), mlir::lsp::Information, mlir::lsp::Diagnostic::message, mlir::Note, mlir::lsp::Diagnostic::range, mlir::lsp::Diagnostic::relatedInformation, mlir::Remark, mlir::lsp::URIForFile::scheme(), mlir::lsp::Diagnostic::severity, mlir::lsp::Diagnostic::source, mlir::lsp::Location::uri, mlir::Warning, and mlir::lsp::Warning.
|
static |
Given a location pointing to a result, return the result number it refers to or std::nullopt if it refers to all of the results.
Definition at line 141 of file MLIRServer.cpp.
|
static |
Given a source location range, return the text covered by the given range.
If the range is invalid, returns std::nullopt.
Definition at line 168 of file MLIRServer.cpp.
|
static |
Returns true if the given location is contained by the definition or one of the uses of the given SMDefinition.
If provided, overlappedRange
is set to the range within def
that the provided loc
overlapped with.
Definition at line 119 of file MLIRServer.cpp.
References contains(), mlir::AsmParserState::SMDefinition::loc, and mlir::AsmParserState::SMDefinition::uses.
|
static |
Given a block and source location, print the source name of the block to the given output stream.
Definition at line 182 of file MLIRServer.cpp.
Referenced by printDefBlockName().
|
static |
Definition at line 193 of file MLIRServer.cpp.
References mlir::AsmParserState::BlockDefinition::block, mlir::AsmParserState::BlockDefinition::definition, mlir::AsmParserState::SMDefinition::loc, and printDefBlockName().