LCOV - code coverage report
Current view: top level - clang/tools/extra/clangd - URI.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 0 1 0.0 %
Date: 2018-02-23 05:02:05 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===--- URI.h - File URIs with schemes --------------------------*- C++-*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHURI_H
      11             : #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHURI_H
      12             : 
      13             : #include "llvm/ADT/StringRef.h"
      14             : #include "llvm/Support/Error.h"
      15             : #include "llvm/Support/Registry.h"
      16             : 
      17             : namespace clang {
      18             : namespace clangd {
      19             : 
      20             : /// A URI describes the location of a source file.
      21             : /// In the simplest case, this is a "file" URI that directly encodes the
      22             : /// absolute path to a file. More abstract cases are possible: a shared index
      23             : /// service might expose repo:// URIs that are relative to the source control
      24             : /// root.
      25             : ///
      26             : /// Clangd handles URIs of the form <scheme>:[//<authority>]<body>. It doesn't
      27             : /// further split the authority or body into constituent parts (e.g. query
      28             : /// strings is included in the body).
      29           0 : class URI {
      30             : public:
      31             :   URI(llvm::StringRef Scheme, llvm::StringRef Authority, llvm::StringRef Body);
      32             : 
      33             :   /// Returns decoded scheme e.g. "https"
      34             :   llvm::StringRef scheme() const { return Scheme; }
      35             :   /// Returns decoded authority e.g. "reviews.lvm.org"
      36             :   llvm::StringRef authority() const { return Authority; }
      37             :   /// Returns decoded body e.g. "/D41946"
      38             :   llvm::StringRef body() const { return Body; }
      39             : 
      40             :   /// Returns a string URI with all components percent-encoded.
      41             :   std::string toString() const;
      42             : 
      43             :   /// Creates a URI for a file in the given scheme. \p Scheme must be
      44             :   /// registered. The URI is percent-encoded.
      45             :   static llvm::Expected<URI> create(llvm::StringRef AbsolutePath,
      46             :                                     llvm::StringRef Scheme);
      47             : 
      48             :   /// This creates a file:// URI for \p AbsolutePath. The path must be absolute.
      49             :   static URI createFile(llvm::StringRef AbsolutePath);
      50             : 
      51             :   /// Parse a URI string "<scheme>:[//<authority>/]<path>". Percent-encoded
      52             :   /// characters in the URI will be decoded.
      53             :   static llvm::Expected<URI> parse(llvm::StringRef Uri);
      54             : 
      55             :   /// Resolves the absolute path of \p U. If there is no matching scheme, or the
      56             :   /// URI is invalid in the scheme, this returns an error.
      57             :   ///
      58             :   /// \p HintPath A related path, such as the current file or working directory,
      59             :   /// which can help disambiguate when the same file exists in many workspaces.
      60             :   static llvm::Expected<std::string> resolve(const URI &U,
      61             :                                              llvm::StringRef HintPath = "");
      62             : 
      63             :   friend bool operator==(const URI &LHS, const URI &RHS) {
      64             :     return std::tie(LHS.Scheme, LHS.Authority, LHS.Body) ==
      65             :            std::tie(RHS.Scheme, RHS.Authority, RHS.Body);
      66             :   }
      67             : 
      68             :   friend bool operator<(const URI &LHS, const URI &RHS) {
      69             :     return std::tie(LHS.Scheme, LHS.Authority, LHS.Body) <
      70             :            std::tie(RHS.Scheme, RHS.Authority, RHS.Body);
      71             :   }
      72             : 
      73             : private:
      74             :   URI() = default;
      75             : 
      76             :   std::string Scheme;
      77             :   std::string Authority;
      78             :   std::string Body;
      79             : };
      80             : 
      81             : /// URIScheme is an extension point for teaching clangd to recognize a custom
      82             : /// URI scheme. This is expected to be implemented and exposed via the
      83             : /// URISchemeRegistry.
      84             : class URIScheme {
      85             : public:
      86             :   virtual ~URIScheme() = default;
      87             : 
      88             :   /// Returns the absolute path of the file corresponding to the URI
      89             :   /// authority+body in the file system. See URI::resolve for semantics of
      90             :   /// \p HintPath.
      91             :   virtual llvm::Expected<std::string>
      92             :   getAbsolutePath(llvm::StringRef Authority, llvm::StringRef Body,
      93             :                   llvm::StringRef HintPath) const = 0;
      94             : 
      95             :   virtual llvm::Expected<URI>
      96             :   uriFromAbsolutePath(llvm::StringRef AbsolutePath) const = 0;
      97             : };
      98             : 
      99             : /// By default, a "file" scheme is supported where URI paths are always absolute
     100             : /// in the file system.
     101             : typedef llvm::Registry<URIScheme> URISchemeRegistry;
     102             : 
     103             : } // namespace clangd
     104             : } // namespace clang
     105             : 
     106             : #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHURI_H

Generated by: LCOV version 1.13