Skip to content

Revert "Allow retrieval of the symbol provider kind for a source file" #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
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
30 changes: 1 addition & 29 deletions Sources/IndexStoreDB/IndexStoreDB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ public enum SymbolProviderKind {
case clang
case swift

init?(_ cKind: indexstoredb_symbol_provider_kind_t) {
init(_ cKind: indexstoredb_symbol_provider_kind_t) {
switch cKind {
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_SWIFT:
self = .swift
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_CLANG:
self = .clang
case INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN:
return nil
default:
preconditionFailure("Unknown enum case in indexstoredb_symbol_provider_kind_t")
}
Expand Down Expand Up @@ -313,32 +311,6 @@ public final class IndexStoreDB {
}
return result
}

public func symbolProvider(for sourceFilePath: String) -> SymbolProviderKind? {
var result: SymbolProviderKind? = nil
indexstoredb_index_units_containing_file(impl, sourceFilePath) { unit in
let providerKind = SymbolProviderKind(indexstoredb_unit_info_symbol_provider_kind(unit))

let mainFilePath = String(cString: indexstoredb_unit_info_main_file_path(unit))
if providerKind == .swift && mainFilePath != sourceFilePath {
// We have a unit that is "included" from Swift. This happens for header
// files that Swift files depend on. But Swift doesn't have includes and
// we shouldn't infer the header file's language to Swift based on this unit.
// Ignore it.
return true
}

if result == nil {
result = providerKind
} else if result != providerKind {
// Found two conflicting provider kinds. Return nil as we don't know the provider in this case.
result = nil
return false
}
return true
}
return result
}

@discardableResult
public func foreachFileIncludedByFile(path: String, body: (String) -> Bool) -> Bool {
Expand Down
3 changes: 1 addition & 2 deletions Sources/IndexStoreDB/SymbolOccurrence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ extension SymbolOccurrence {
symbol: Symbol(indexstoredb_symbol_occurrence_symbol(value)),
location: SymbolLocation(indexstoredb_symbol_occurrence_location(value)),
roles: SymbolRole(rawValue: indexstoredb_symbol_occurrence_roles(value)),
// Force unwrap is OK because `indexstoredb_symbol_occurrence_symbol_provider_kind` never returns `INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN`
symbolProvider: SymbolProviderKind(indexstoredb_symbol_occurrence_symbol_provider_kind(value))!,
symbolProvider: SymbolProviderKind(indexstoredb_symbol_occurrence_symbol_provider_kind(value)),
relations: relations)
}
}
Expand Down
3 changes: 0 additions & 3 deletions include/CIndexStoreDB/CIndexStoreDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ indexstoredb_unit_info_main_file_path(_Nonnull indexstoredb_unit_info_t);
INDEXSTOREDB_PUBLIC const char *_Nonnull
indexstoredb_unit_info_unit_name(_Nonnull indexstoredb_unit_info_t);

INDEXSTOREDB_PUBLIC indexstoredb_symbol_provider_kind_t
indexstoredb_unit_info_symbol_provider_kind(_Nonnull indexstoredb_unit_info_t info);

/// Iterates over the compilation units that contain \p path and return their units.
///
/// This can be used to find information for units that include a given header.
Expand Down
7 changes: 2 additions & 5 deletions include/IndexStoreDB/Index/StoreUnitInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#ifndef INDEXSTOREDB_INDEX_STOREUNITINFO_H
#define INDEXSTOREDB_INDEX_STOREUNITINFO_H

#include "IndexStoreDB/Core/Symbol.h"
#include "IndexStoreDB/Support/Path.h"
#include "llvm/Support/Chrono.h"
#include <string>
Expand All @@ -27,18 +26,16 @@ struct StoreUnitInfo {
std::string OutFileIdentifier;
bool HasTestSymbols = false;
llvm::sys::TimePoint<> ModTime;
Optional<SymbolProviderKind> SymProviderKind;

StoreUnitInfo() = default;
StoreUnitInfo(std::string unitName, CanonicalFilePath mainFilePath,
StringRef outFileIdentifier, bool hasTestSymbols,
llvm::sys::TimePoint<> modTime,
Optional<SymbolProviderKind> SymProviderKind)
llvm::sys::TimePoint<> modTime)
: UnitName(unitName),
MainFilePath(mainFilePath),
OutFileIdentifier(outFileIdentifier),
HasTestSymbols(hasTestSymbols),
ModTime(modTime), SymProviderKind(SymProviderKind) {}
ModTime(modTime) {}
};

} // namespace index
Expand Down
14 changes: 0 additions & 14 deletions lib/CIndexStoreDB/CIndexStoreDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,20 +589,6 @@ indexstoredb_unit_info_unit_name(indexstoredb_unit_info_t info) {
return obj->UnitName.c_str();
}

indexstoredb_symbol_provider_kind_t
indexstoredb_unit_info_symbol_provider_kind(_Nonnull indexstoredb_unit_info_t info) {
auto obj = (const StoreUnitInfo *)info;
if (!obj->SymProviderKind) {
return INDEXSTOREDB_SYMBOL_PROVIDER_KIND_UNKNOWN;
}
switch (*obj->SymProviderKind) {
case IndexStoreDB::SymbolProviderKind::Clang:
return INDEXSTOREDB_SYMBOL_PROVIDER_KIND_CLANG;
case IndexStoreDB::SymbolProviderKind::Swift:
return INDEXSTOREDB_SYMBOL_PROVIDER_KIND_SWIFT;
}
}

bool
indexstoredb_index_units_containing_file(
indexstoredb_index_t index,
Expand Down
1 change: 0 additions & 1 deletion lib/Index/FilePathIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ bool FileIndexImpl::foreachMainUnitContainingFile(CanonicalFilePathRef filePath,
currUnit.ModTime = unitInfo.ModTime;
currUnit.MainFilePath = reader.getFullFilePathFromCode(unitInfo.MainFileCode);
currUnit.OutFileIdentifier = reader.getUnitFileIdentifierFromCode(unitInfo.OutFileCode);
currUnit.SymProviderKind = unitInfo.SymProviderKind;
return true;
});
}
Expand Down
25 changes: 3 additions & 22 deletions lib/Index/IndexDatastore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ void StoreUnitRepo::registerUnit(StringRef unitName, bool isInitialScan, std::sh
bool needDatabaseUpdate;
Optional<bool> optIsSystem;
Optional<bool> PrevHasTestSymbols;
Optional<SymbolProviderKind> PrevSymProviderKind;
IDCode PrevMainFileCode;
IDCode PrevOutFileCode;
Optional<StoreUnitInfo> StoreUnitInfoOpt;
Expand All @@ -494,7 +493,6 @@ void StoreUnitRepo::registerUnit(StringRef unitName, bool isInitialScan, std::sh
PrevMainFileCode = unitImport.getPrevMainFileCode();
PrevOutFileCode = unitImport.getPrevOutFileCode();
PrevHasTestSymbols = unitImport.getHasTestSymbols();
PrevSymProviderKind = unitImport.getSymbolProviderKind();
return false;
}

Expand Down Expand Up @@ -592,14 +590,7 @@ void StoreUnitRepo::registerUnit(StringRef unitName, bool isInitialScan, std::sh
}

unitImport.commit();
StoreUnitInfoOpt = StoreUnitInfo{
unitName,
CanonMainFile,
OutFileIdentifier,
unitImport.getHasTestSymbols().getValue(),
unitModTime,
unitImport.getSymbolProviderKind()
};
StoreUnitInfoOpt = StoreUnitInfo{unitName, CanonMainFile, OutFileIdentifier, unitImport.getHasTestSymbols().getValue(), unitModTime};
import.commit();
return false;
};
Expand All @@ -612,14 +603,7 @@ void StoreUnitRepo::registerUnit(StringRef unitName, bool isInitialScan, std::sh
ReadTransaction reader(SymIndex->getDBase());
CanonicalFilePath mainFile = reader.getFullFilePathFromCode(PrevMainFileCode);
std::string outFileIdentifier = reader.getUnitFileIdentifierFromCode(PrevOutFileCode);
StoreUnitInfoOpt = StoreUnitInfo{
unitName,
mainFile,
outFileIdentifier,
PrevHasTestSymbols.getValue(),
unitModTime,
PrevSymProviderKind.getValue()
};
StoreUnitInfoOpt = StoreUnitInfo{unitName, mainFile, outFileIdentifier, PrevHasTestSymbols.getValue(), unitModTime};
}
Delegate->processedStoreUnit(StoreUnitInfoOpt.getValue());
}
Expand Down Expand Up @@ -826,7 +810,6 @@ void StoreUnitRepo::onUnitOutOfDate(IDCode unitCode, StringRef unitName,
CanonicalFilePath MainFilePath;
std::string OutFileIdentifier;
bool hasTestSymbols = false;
Optional<SymbolProviderKind> SymProviderKind;
llvm::sys::TimePoint<> CurrModTime;
SmallVector<IDCode, 8> dependentUnits;
{
Expand All @@ -838,7 +821,6 @@ void StoreUnitRepo::onUnitOutOfDate(IDCode unitCode, StringRef unitName,
}
OutFileIdentifier = reader.getUnitFileIdentifierFromCode(unitInfo.OutFileCode);
hasTestSymbols = unitInfo.HasTestSymbols;
SymProviderKind = unitInfo.SymProviderKind;
CurrModTime = unitInfo.ModTime;
}
reader.getDirectDependentUnits(unitCode, dependentUnits);
Expand All @@ -850,8 +832,7 @@ void StoreUnitRepo::onUnitOutOfDate(IDCode unitCode, StringRef unitName,
MainFilePath,
OutFileIdentifier,
hasTestSymbols,
CurrModTime,
SymProviderKind
CurrModTime
};
Delegate->unitIsOutOfDate(unitInfo, trigger, synchronous);
}
Expand Down