blob: 2bf5d0ec2f4abae4a50f0f77c995e5478ddb4fe1 [file] [log] [blame]
Sam McCallb536a2a2017-12-19 12:23:48 +00001//===--- SourceCode.h - Manipulating source code as strings -----*- 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// Various code that examines C++ source code without using heavy AST machinery
11// (and often not even the lexer). To be used sparingly!
12//
13//===----------------------------------------------------------------------===//
14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H
15#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SOURCECODE_H
16#include "Protocol.h"
Marc-Andre Laperle63a10982018-02-21 02:39:08 +000017#include "clang/Basic/SourceLocation.h"
Sam McCallb536a2a2017-12-19 12:23:48 +000018
19namespace clang {
Marc-Andre Laperle63a10982018-02-21 02:39:08 +000020class SourceManager;
21
Sam McCallb536a2a2017-12-19 12:23:48 +000022namespace clangd {
23
24/// Turn a [line, column] pair into an offset in Code.
25size_t positionToOffset(llvm::StringRef Code, Position P);
26
27/// Turn an offset in Code into a [line, column] pair.
28Position offsetToPosition(llvm::StringRef Code, size_t Offset);
29
Marc-Andre Laperle63a10982018-02-21 02:39:08 +000030/// Turn a SourceLocation into a [line, column] pair.
31Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc);
32
Ilya Biryukov71028b82018-03-12 15:28:22 +000033// Converts a half-open clang source range to an LSP range.
34// Note that clang also uses closed source ranges, which this can't handle!
35Range halfOpenToRange(const SourceManager &SM, CharSourceRange R);
36
Sam McCallb536a2a2017-12-19 12:23:48 +000037} // namespace clangd
38} // namespace clang
39#endif