MLIR  20.0.0git
Functions
Protocol.cpp File Reference
#include "mlir/Tools/lsp-server-support/Protocol.h"
#include "mlir/Tools/lsp-server-support/Logging.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"

Go to the source code of this file.

Functions

template<typename T >
static bool mapOptOrNull (const llvm::json::Value &params, llvm::StringLiteral prop, T &out, llvm::json::Path path)
 
static bool isWindowsPath (StringRef path)
 
static bool isNetworkPath (StringRef path)
 
static bool shouldEscapeInURI (unsigned char c)
 
static void percentEncode (StringRef content, std::string &out)
 Encodes a string according to percent-encoding. More...
 
static std::string percentDecode (StringRef content)
 Decodes a string according to percent-encoding. More...
 
static StringSetgetSupportedSchemes ()
 Return the set containing the supported URI schemes. More...
 
static bool isStructurallyValidScheme (StringRef scheme)
 Returns true if the given scheme is structurally valid, i.e. More...
 
static llvm::Expected< std::string > uriFromAbsolutePath (StringRef absolutePath, StringRef scheme)
 
static llvm::Expected< std::string > getAbsolutePath (StringRef authority, StringRef body)
 
static llvm::Expected< std::string > parseFilePathFromURI (StringRef origUri)
 
static llvm::StringRef toTextKind (MarkupKind kind)
 

Function Documentation

◆ getAbsolutePath()

static llvm::Expected<std::string> getAbsolutePath ( StringRef  authority,
StringRef  body 
)
static

Definition at line 167 of file Protocol.cpp.

References isWindowsPath().

Referenced by parseFilePathFromURI().

◆ getSupportedSchemes()

static StringSet& getSupportedSchemes ( )
static

Return the set containing the supported URI schemes.

Definition at line 120 of file Protocol.cpp.

Referenced by parseFilePathFromURI(), and mlir::lsp::URIForFile::registerSupportedScheme().

◆ isNetworkPath()

static bool isNetworkPath ( StringRef  path)
static

Definition at line 59 of file Protocol.cpp.

Referenced by uriFromAbsolutePath().

◆ isStructurallyValidScheme()

static bool isStructurallyValidScheme ( StringRef  scheme)
static

Returns true if the given scheme is structurally valid, i.e.

it does not contain any invalid scheme characters. This does not check that the scheme is actually supported.

Definition at line 128 of file Protocol.cpp.

Referenced by parseFilePathFromURI().

◆ isWindowsPath()

static bool isWindowsPath ( StringRef  path)
static

Definition at line 55 of file Protocol.cpp.

Referenced by getAbsolutePath(), and uriFromAbsolutePath().

◆ mapOptOrNull()

template<typename T >
static bool mapOptOrNull ( const llvm::json::Value &  params,
llvm::StringLiteral  prop,
T &  out,
llvm::json::Path  path 
)
static

Definition at line 32 of file Protocol.cpp.

References mlir::lsp::fromJSON().

Referenced by mlir::lsp::fromJSON().

◆ parseFilePathFromURI()

static llvm::Expected<std::string> parseFilePathFromURI ( StringRef  origUri)
static

◆ percentDecode()

static std::string percentDecode ( StringRef  content)
static

Decodes a string according to percent-encoding.

Definition at line 101 of file Protocol.cpp.

Referenced by parseFilePathFromURI().

◆ percentEncode()

static void percentEncode ( StringRef  content,
std::string &  out 
)
static

Encodes a string according to percent-encoding.

  • Unreserved characters are not escaped.
  • Reserved characters always escaped with exceptions like '/'.
  • All other characters are escaped.

Definition at line 88 of file Protocol.cpp.

References shouldEscapeInURI().

Referenced by uriFromAbsolutePath().

◆ shouldEscapeInURI()

static bool shouldEscapeInURI ( unsigned char  c)
static

Definition at line 64 of file Protocol.cpp.

Referenced by percentEncode().

◆ toTextKind()

static llvm::StringRef toTextKind ( MarkupKind  kind)
static

Definition at line 563 of file Protocol.cpp.

References mlir::lsp::Markdown, and mlir::lsp::PlainText.

Referenced by mlir::lsp::operator<<(), and mlir::lsp::toJSON().

◆ uriFromAbsolutePath()

static llvm::Expected<std::string> uriFromAbsolutePath ( StringRef  absolutePath,
StringRef  scheme 
)
static

Definition at line 138 of file Protocol.cpp.

References isNetworkPath(), isWindowsPath(), and percentEncode().

Referenced by mlir::lsp::URIForFile::fromFile().