mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-16 05:01:56 +00:00
d75fb1ee79
Xcode uses `#pragma mark -` to draw a divider in the outline view and `#pragma mark Note` to add `Note` in the outline view. For more information, see https://nshipster.com/pragma/. Since the LSP spec doesn't contain dividers for the symbol outline, instead we treat `#pragma mark -` as a group with children - the decls that come after it, implicitly terminating when the symbol's parent ends. The following code: ``` @implementation MyClass - (id)init {} - (int)foo; @end ``` Would give an outline like ``` MyClass > Overrides > init > Public Accessors > foo ``` Differential Revision: https://reviews.llvm.org/D105904
63 lines
2.0 KiB
C++
63 lines
2.0 KiB
C++
//===--- CollectMacros.cpp ---------------------------------------*- C++-*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "CollectMacros.h"
|
|
#include "clang/Basic/SourceLocation.h"
|
|
#include "clang/Lex/Lexer.h"
|
|
|
|
namespace clang {
|
|
namespace clangd {
|
|
|
|
void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,
|
|
bool IsDefinition) {
|
|
if (!InMainFile)
|
|
return;
|
|
auto Loc = MacroNameTok.getLocation();
|
|
if (Loc.isInvalid() || Loc.isMacroID())
|
|
return;
|
|
|
|
auto Name = MacroNameTok.getIdentifierInfo()->getName();
|
|
Out.Names.insert(Name);
|
|
auto Range = halfOpenToRange(
|
|
SM, CharSourceRange::getCharRange(Loc, MacroNameTok.getEndLoc()));
|
|
if (auto SID = getSymbolID(Name, MI, SM))
|
|
Out.MacroRefs[SID].push_back({Range, IsDefinition});
|
|
else
|
|
Out.UnknownMacros.push_back({Range, IsDefinition});
|
|
}
|
|
|
|
class CollectPragmaMarks : public PPCallbacks {
|
|
public:
|
|
explicit CollectPragmaMarks(const SourceManager &SM,
|
|
std::vector<clangd::PragmaMark> &Out)
|
|
: SM(SM), Out(Out) {}
|
|
|
|
void PragmaMark(SourceLocation Loc, StringRef Trivia) override {
|
|
if (isInsideMainFile(Loc, SM)) {
|
|
// FIXME: This range should just cover `XX` in `#pragma mark XX` and
|
|
// `- XX` in `#pragma mark - XX`.
|
|
Position Start = sourceLocToPosition(SM, Loc);
|
|
Position End = {Start.line + 1, 0};
|
|
Out.emplace_back(clangd::PragmaMark{{Start, End}, Trivia.str()});
|
|
}
|
|
}
|
|
|
|
private:
|
|
const SourceManager &SM;
|
|
std::vector<clangd::PragmaMark> &Out;
|
|
};
|
|
|
|
std::unique_ptr<PPCallbacks>
|
|
collectPragmaMarksCallback(const SourceManager &SM,
|
|
std::vector<PragmaMark> &Out) {
|
|
return std::make_unique<CollectPragmaMarks>(SM, Out);
|
|
}
|
|
|
|
} // namespace clangd
|
|
} // namespace clang
|