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 //===----------------------------------------------------------------------===// 32 // SourceMgrInclude 33 //===----------------------------------------------------------------------===// 34 35 /// This class represents a single include within a root file. 36 struct SourceMgrInclude { SourceMgrIncludeSourceMgrInclude37 SourceMgrInclude(const lsp::URIForFile &uri, const lsp::Range &range) 38 : uri(uri), range(range) {} 39 40 /// Build a hover for the current include file. 41 Hover buildHover() const; 42 43 /// The URI of the file that is included. 44 lsp::URIForFile uri; 45 46 /// The range of the include directive. 47 lsp::Range range; 48 }; 49 50 /// Given a source manager, gather all of the processed include files. These are 51 /// assumed to be all of the files other than the main root file. 52 void gatherIncludeFiles(llvm::SourceMgr &sourceMgr, 53 SmallVectorImpl<SourceMgrInclude> &includes); 54 55 } // namespace lsp 56 } // namespace mlir 57 58 #endif 59