v8/test/unittests/torque/ls-server-data-unittest.cc
Simon Zünd 1397697e24 [torque] Collect lint errors for later processing
This CL changes lint errors to not be printed directly to stderr.
Instead, they are collected in a list that gets surfaced via
the TorqueCompilerResult. This is done so they can be presented
to language server clients.

This change also removes the "abort_on_lint_errors" option.
API users can now decide for themselves what to do, depending on
the presence of lint errors in the returned list.

R=sigurds@chromium.org, tebbi@chromium.org

Bug: v8:8880
Change-Id: I44601010491aafcf4c8609fd8c115219317506a4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1581608
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60983}
2019-04-24 14:04:06 +00:00

76 lines
2.3 KiB
C++

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/torque/server-data.h"
#include "src/torque/torque-compiler.h"
#include "test/unittests/test-utils.h"
namespace v8 {
namespace internal {
namespace torque {
namespace {
struct TestCompiler {
SourceFileMap::Scope file_map_scope;
LanguageServerData::Scope server_data_scope;
void Compile(const std::string& source) {
TorqueCompilerOptions options;
options.output_directory = "";
options.verbose = false;
options.collect_language_server_data = true;
const TorqueCompilerResult result = CompileTorque(source, options);
SourceFileMap::Get() = result.source_file_map;
LanguageServerData::Get() = result.language_server_data;
}
};
} // namespace
TEST(LanguageServer, GotoTypeDefinition) {
const std::string source =
"type void;\n"
"type never;\n"
"type T1 generates 'TNode<Object>';\n"
"type T2 generates 'TNode<Object>';\n"
"macro SomeMacro(a: T1, b: T2): T1 { return a; }";
TestCompiler compiler;
compiler.Compile(source);
// Find the definition for type 'T1' of argument 'a' on line 4.
const SourceId id = SourceFileMap::GetSourceId("<torque>");
auto maybe_position = LanguageServerData::FindDefinition(id, {4, 19});
ASSERT_TRUE(maybe_position.has_value());
EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 7}}));
// Find the defintion for type 'T2' of argument 'b' on line 4.
maybe_position = LanguageServerData::FindDefinition(id, {4, 26});
ASSERT_TRUE(maybe_position.has_value());
EXPECT_EQ(*maybe_position, (SourcePosition{id, {3, 5}, {3, 7}}));
}
TEST(LanguageServer, GotoTypeDefinitionExtends) {
const std::string source =
"type void;\n"
"type never;\n"
"type T1 generates 'TNode<T1>';\n"
"type T2 extends T1 generates 'TNode<T2>';";
TestCompiler compiler;
compiler.Compile(source);
// Find the definition for 'T1' of the extends clause on line 3.
const SourceId id = SourceFileMap::GetSourceId("<torque>");
auto maybe_position = LanguageServerData::FindDefinition(id, {3, 16});
ASSERT_TRUE(maybe_position.has_value());
EXPECT_EQ(*maybe_position, (SourcePosition{id, {2, 5}, {2, 7}}));
}
} // namespace torque
} // namespace internal
} // namespace v8