Commit bb1b538a authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque-ls] Fix crash when looking up definitions

This CL fixes a crash that happens on a goto definition lookup for a
file with no data attached to it.

Drive-by: Collect language server data even on compilation failures.

R=tebbi@chromium.org

Bug: v8:8880
Change-Id: Ia6323204391da3e64058e1fe47f87162186c15cd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1583721Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61012}
parent ff3a26af
...@@ -17,7 +17,12 @@ void LanguageServerData::AddDefinition(SourcePosition token, ...@@ -17,7 +17,12 @@ void LanguageServerData::AddDefinition(SourcePosition token,
base::Optional<SourcePosition> LanguageServerData::FindDefinition( base::Optional<SourcePosition> LanguageServerData::FindDefinition(
SourceId source, LineAndColumn pos) { SourceId source, LineAndColumn pos) {
for (const DefinitionMapping& mapping : Get().definitions_map_.at(source)) { if (!source.IsValid()) return base::nullopt;
auto iter = Get().definitions_map_.find(source);
if (iter == Get().definitions_map_.end()) return base::nullopt;
for (const DefinitionMapping& mapping : iter->second) {
SourcePosition current = mapping.first; SourcePosition current = mapping.first;
if (current.Contains(pos)) return mapping.second; if (current.Contains(pos)) return mapping.second;
} }
......
...@@ -94,8 +94,7 @@ TorqueCompilerResult CollectResultFromContextuals() { ...@@ -94,8 +94,7 @@ TorqueCompilerResult CollectResultFromContextuals() {
} }
TorqueCompilerResult ResultFromError(TorqueError& error) { TorqueCompilerResult ResultFromError(TorqueError& error) {
TorqueCompilerResult result; TorqueCompilerResult result = CollectResultFromContextuals();
result.source_file_map = SourceFileMap::Get();
result.error = error; result.error = error;
return result; return result;
} }
......
...@@ -70,6 +70,15 @@ TEST(LanguageServer, GotoTypeDefinitionExtends) { ...@@ -70,6 +70,15 @@ TEST(LanguageServer, GotoTypeDefinitionExtends) {
EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 7}})); EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 7}}));
} }
TEST(LanguageServer, GotoTypeDefinitionNoDataForFile) {
LanguageServerData::Scope server_data_scope;
SourceFileMap::Scope file_scope;
SourceId test_id = SourceFileMap::AddSource("test.tq");
// Regression test, this step should not crash.
EXPECT_FALSE(LanguageServerData::FindDefinition(test_id, {0, 0}));
}
} // namespace torque } // namespace torque
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment