MLIR  16.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 LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
15 #define LIB_MLIR_TOOLS_LSPSERVERSUPPORT_TRANSPORT_H_
16 
17 #include "Protocol.h"
18 #include "llvm/Support/SourceMgr.h"
19 
20 namespace mlir {
21 namespace lsp {
22 //===----------------------------------------------------------------------===//
23 // Utils
24 //===----------------------------------------------------------------------===//
25 
26 /// Returns the range of a lexical token given a SMLoc corresponding to the
27 /// start of an token location. The range is computed heuristically, and
28 /// supports identifier-like tokens, strings, etc.
29 SMRange convertTokenLocToRange(SMLoc loc);
30 
31 /// Extract a documentation comment for the given location within the source
32 /// manager. Returns None if no comment could be computed.
33 Optional<std::string> extractSourceDocComment(llvm::SourceMgr &sourceMgr,
34  SMLoc loc);
35 
36 /// Returns true if the given range contains the given source location. Note
37 /// that this has different behavior than SMRange because it is inclusive of the
38 /// end location.
39 bool contains(SMRange range, SMLoc loc);
40 
41 //===----------------------------------------------------------------------===//
42 // SourceMgrInclude
43 //===----------------------------------------------------------------------===//
44 
45 /// This class represents a single include within a root file.
48  : uri(uri), range(range) {}
49 
50  /// Build a hover for the current include file.
51  Hover buildHover() const;
52 
53  /// The URI of the file that is included.
55 
56  /// The range of the include directive.
58 };
59 
60 /// Given a source manager, gather all of the processed include files. These are
61 /// assumed to be all of the files other than the main root file.
62 void gatherIncludeFiles(llvm::SourceMgr &sourceMgr,
64 
65 } // namespace lsp
66 } // namespace mlir
67 
68 #endif
Include the generated interface declarations.
lsp::Range range
The range of the include directive.
URI in "file" scheme for a file.
Definition: Protocol.h:100
This class represents a single include within a root file.
SourceMgrInclude(const lsp::URIForFile &uri, const lsp::Range &range)
SMRange convertTokenLocToRange(SMLoc loc)
Returns the range of a lexical token given a SMLoc corresponding to the start of an token location...
void gatherIncludeFiles(llvm::SourceMgr &sourceMgr, SmallVectorImpl< SourceMgrInclude > &includes)
Given a source manager, gather all of the processed include files.
Optional< std::string > extractSourceDocComment(llvm::SourceMgr &sourceMgr, SMLoc loc)
Extract a documentation comment for the given location within the source manager. ...
lsp::URIForFile uri
The URI of the file that is included.
Hover buildHover() const
Build a hover for the current include file.
bool contains(SMRange range, SMLoc loc)
Returns true if the given range contains the given source location.