Update CodeCompletion and SignatureHelp.

This commit is contained in:
ykiko
2024-10-27 13:55:30 +08:00
parent e1afd40663
commit 2890873428
5 changed files with 101 additions and 28 deletions

View File

@@ -0,0 +1,67 @@
#include <Basic/SourceCode.h>
#include <Compiler/Compiler.h>
#include <Feature/CodeCompletion.h>
namespace clice::feature {
namespace {
class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
public:
CodeCompletionCollector(clang::CodeCompleteOptions options) :
clang::CodeCompleteConsumer(options), allocator(new clang::GlobalCodeCompletionAllocator()),
info(allocator) {
// TODO:
}
void ProcessCodeCompleteResults(clang::Sema& sema,
clang::CodeCompletionContext context,
clang::CodeCompletionResult* results,
unsigned count) final {
sema.getPreprocessor().getCodeCompletionLoc();
for(auto& result: llvm::make_range(results, results + count)) {
llvm::outs() << "Kind: " << result.Kind << " ";
switch(result.Kind) {
case clang::CodeCompletionResult::RK_Declaration: {
result.getDeclaration()->dump();
break;
}
case clang::CodeCompletionResult::RK_Keyword: {
llvm::outs() << result.Keyword << "\n";
break;
}
case clang::CodeCompletionResult::RK_Macro: {
llvm::outs() << result.Macro << "\n";
break;
}
case clang::CodeCompletionResult::RK_Pattern: {
llvm::outs() << result.Pattern->getAsString() << "\n";
break;
}
}
}
}
clang::CodeCompletionAllocator& getAllocator() final {
return *allocator;
}
clang::CodeCompletionTUInfo& getCodeCompletionTUInfo() final {
return info;
}
private:
std::shared_ptr<clang::GlobalCodeCompletionAllocator> allocator;
clang::CodeCompletionTUInfo info;
};
} // namespace
std::vector<proto::CompletionItem> codeCompletion(Compiler& compiler,
llvm::StringRef filepath,
proto::Position position,
const config::CodeCompletionOption& option) {
// TODO: decode here.
}
} // namespace clice::feature