Stabilize compilation interface (#117)
This commit is contained in:
@@ -45,53 +45,32 @@ struct CompletionPrefix {
|
||||
|
||||
class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
|
||||
public:
|
||||
CodeCompletionCollector(std::vector<CodeCompletionItem>& completions,
|
||||
uint32_t line,
|
||||
uint32_t column,
|
||||
llvm::StringRef content) :
|
||||
CodeCompletionCollector(std::vector<CodeCompletionItem>& completions) :
|
||||
clang::CodeCompleteConsumer({}), completions(completions),
|
||||
allocator(new clang::GlobalCodeCompletionAllocator()), info(allocator), line(line),
|
||||
column(column), content(content) {}
|
||||
allocator(new clang::GlobalCodeCompletionAllocator()), info(allocator) {}
|
||||
|
||||
void ProcessCodeCompleteResults(clang::Sema& sema,
|
||||
clang::CodeCompletionContext context,
|
||||
clang::CodeCompletionResult* results,
|
||||
clang::CodeCompletionResult* candidates,
|
||||
unsigned count) final {
|
||||
// auto loc = sema.getPreprocessor().getCodeCompletionLoc();
|
||||
// auto offset = sema.getSourceManager().getFileOffset(loc);
|
||||
// auto prefix = CompletionPrefix::from(content, offset);
|
||||
//
|
||||
// for(auto& result: llvm::make_range(results, results + count)) {
|
||||
// auto& item = completions.emplace_back();
|
||||
// item.kind = proto::CompletionItemKind::Text;
|
||||
// switch(result.Kind) {
|
||||
// case clang::CodeCompletionResult::RK_Declaration: {
|
||||
// item.label = getName(result.Declaration);
|
||||
// item.kind = kindForDecl(result.Declaration);
|
||||
// item.detail = result.Declaration->getNameAsString();
|
||||
// break;
|
||||
// }
|
||||
// case clang::CodeCompletionResult::RK_Keyword: {
|
||||
// item.label = result.Keyword;
|
||||
// item.kind = proto::CompletionItemKind::Keyword;
|
||||
// break;
|
||||
// }
|
||||
// case clang::CodeCompletionResult::RK_Macro: {
|
||||
// item.label = result.Macro->getName();
|
||||
// break;
|
||||
// }
|
||||
// case clang::CodeCompletionResult::RK_Pattern: {
|
||||
// item.kind = proto::CompletionItemKind::Snippet;
|
||||
// item.label = result.Pattern->getTypedText();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// item.textEdit.newText = item.label;
|
||||
// item.textEdit.range = {
|
||||
// .start = {line - 1, static_cast<uint32_t>(column - 1 - prefix.name.size())},
|
||||
// .end = {line - 1, static_cast<uint32_t>(column + item.label.size()) - 1 },
|
||||
// };
|
||||
//}
|
||||
for(auto& candidate: llvm::make_range(candidates, candidates + count)) {
|
||||
switch(candidate.Kind) {
|
||||
case clang::CodeCompletionResult::RK_Declaration: {
|
||||
break;
|
||||
}
|
||||
case clang::CodeCompletionResult::RK_Keyword: {
|
||||
break;
|
||||
}
|
||||
case clang::CodeCompletionResult::RK_Macro: {
|
||||
break;
|
||||
}
|
||||
case clang::CodeCompletionResult::RK_Pattern: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
println("{}", refl::enum_name(candidate.Kind));
|
||||
}
|
||||
}
|
||||
|
||||
clang::CodeCompletionAllocator& getAllocator() final {
|
||||
@@ -103,9 +82,6 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t line;
|
||||
uint32_t column;
|
||||
llvm::StringRef content;
|
||||
std::shared_ptr<clang::GlobalCodeCompletionAllocator> allocator;
|
||||
clang::CodeCompletionTUInfo info;
|
||||
std::vector<CodeCompletionItem>& completions;
|
||||
@@ -115,18 +91,12 @@ private:
|
||||
|
||||
std::vector<CodeCompletionItem> codeCompletion(CompilationParams& params,
|
||||
const config::CodeCompletionOption& option) {
|
||||
// std::vector<CodeCompletionItem> completions;
|
||||
// auto consumer =
|
||||
// new CodeCompletionCollector(completions, params.line, params.column, params.content);
|
||||
//
|
||||
// if(auto info = compile(params, consumer)) {
|
||||
// for(auto& item: completions) {}
|
||||
// return completions;
|
||||
//} else {
|
||||
// std::abort();
|
||||
//}
|
||||
|
||||
return std::vector<CodeCompletionItem>{};
|
||||
std::vector<CodeCompletionItem> completions;
|
||||
auto consumer = new CodeCompletionCollector(completions);
|
||||
if(auto info = compile(params, consumer)) {
|
||||
for(auto& item: completions) {}
|
||||
}
|
||||
return completions;
|
||||
}
|
||||
|
||||
} // namespace clice::feature
|
||||
|
||||
Reference in New Issue
Block a user