Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions scip_indexer/SCIPIndexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,34 @@ class CFGTraversal final {

namespace sorbet::pipeline::semantic_extension {

struct IndexWriter {
scip::Index index;
ostream &outputStream;

~IndexWriter() {
this->write();
}

void writeDocument(scip::Document &&doc) {
*this->index.add_documents() = std::move(doc);
this->write();
}

void writeExternalSymbol(scip::SymbolInformation &&symbolInfo) {
*this->index.add_external_symbols() = std::move(symbolInfo);
if (this->index.external_symbols_size() % 1024 == 0) {
this->write();
}
}

private:
void write() {
this->index.SerializeToOstream(&this->outputStream);
this->index.clear_documents();
this->index.clear_external_symbols();
}
};

using LocalSymbolTable = UnorderedMap<core::LocalVariable, core::Loc>;

class SCIPSemanticExtension : public SemanticExtension {
Expand Down Expand Up @@ -1269,19 +1297,20 @@ class SCIPSemanticExtension : public SemanticExtension {
return s1.symbol() < s2.symbol();
});

// TODO: Is it OK to do I/O here? Or should it be elsewhere?
ofstream out(indexFilePath);

scip::Index index;
*index.mutable_metadata() = metadata;
index.SerializeToOstream(&out);

IndexWriter writer{scip::Index{}, out};
for (auto &document : allDocuments) {
*index.add_documents() = move(document);
writer.writeDocument(move(document));
}
for (auto &symbol : allExternalSymbols) {
*index.add_external_symbols() = move(symbol);
writer.writeExternalSymbol(move(symbol));
}

ofstream out(indexFilePath);
// TODO: Is it OK to do I/O here? Or should it be elsewhere?
index.SerializeToOstream(&out);
out.close();
};

virtual void typecheck(const core::GlobalState &gs, core::FileRef file, cfg::CFG &cfg,
Expand Down