MLIR  20.0.0git
SourceMgrUtils.h
Go to the documentation of this file.
1 //===--- SourceMgrUtils.h - SourceMgr LSP Utils -----------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains an array of generally useful SourceMgr utilities for
10 // interacting with LSP components.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef MLIR_TOOLS_LSPSERVERSUPPORT_SOURCEMGRUTILS_H
15 #define MLIR_TOOLS_LSPSERVERSUPPORT_SOURCEMGRUTILS_H
16 
18 #include "llvm/Support/SourceMgr.h"
19 #include <optional>
20 
21 namespace mlir {
22 namespace lsp {
23 //===----------------------------------------------------------------------===//
24 // Utils
25 //===----------------------------------------------------------------------===//
26 
27 /// Returns the range of a lexical token given a SMLoc corresponding to the
28 /// start of an token location. The range is computed heuristically, and
29 /// supports identifier-like tokens, strings, etc.
30 SMRange convertTokenLocToRange(SMLoc loc, StringRef identifierChars = "");
31 
32 /// Extract a documentation comment for the given location within the source
33 /// manager. Returns std::nullopt if no comment could be computed.
34 std::optional<std::string> extractSourceDocComment(llvm::SourceMgr &sourceMgr,
35  SMLoc loc);
36 
37 /// Returns true if the given range contains the given source location. Note
38 /// that this has different behavior than SMRange because it is inclusive of the
39 /// end location.
40 bool contains(SMRange range, SMLoc loc);
41 
42 //===----------------------------------------------------------------------===//
43 // SourceMgrInclude
44 //===----------------------------------------------------------------------===//
45 
46 /// This class represents a single include within a root file.
49  : uri(uri), range(range) {}
50 
51  /// Build a hover for the current include file.
52  Hover buildHover() const;
53 
54  /// The URI of the file that is included.
56 
57  /// The range of the include directive.
59 };
60 
61 /// Given a source manager, gather all of the processed include files. These are
62 /// assumed to be all of the files other than the main root file.
63 void gatherIncludeFiles(llvm::SourceMgr &sourceMgr,
65 
66 } // namespace lsp
67 } // namespace mlir
68 
69 #endif
URI in "file" scheme for a file.
Definition: Protocol.h:97
void gatherIncludeFiles(llvm::SourceMgr &sourceMgr, SmallVectorImpl< SourceMgrInclude > &includes)
Given a source manager, gather all of the processed include files.
bool contains(SMRange range, SMLoc loc)
Returns true if the given range contains the given source location.
std::optional< std::string > extractSourceDocComment(llvm::SourceMgr &sourceMgr, SMLoc loc)
Extract a documentation comment for the given location within the source manager.
SMRange convertTokenLocToRange(SMLoc loc, StringRef identifierChars="")
Returns the range of a lexical token given a SMLoc corresponding to the start of an token location.
Include the generated interface declarations.
This class represents a single include within a root file.
Hover buildHover() const
Build a hover for the current include file.
lsp::Range range
The range of the include directive.
SourceMgrInclude(const lsp::URIForFile &uri, const lsp::Range &range)
lsp::URIForFile uri
The URI of the file that is included.