Skip to content

Commit de8c4e4

Browse files
committed
[lldb] Support diagnostic options in Swift REPL
Honor some previously ignored diagnostic options like '-debug-diagnostic-names' and '-locale' by applying them to the diagnostic engine in the SwiftASTContext. https://bugs.swift.org/browse/SR-14845
1 parent 52df6ad commit de8c4e4

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "swift/AST/Type.h"
3939
#include "swift/AST/Types.h"
4040
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
41+
#include "swift/Basic/DiagnosticOptions.h"
4142
#include "swift/Basic/Dwarf.h"
4243
#include "swift/Basic/LangOptions.h"
4344
#include "swift/Basic/Located.h"
@@ -1531,6 +1532,20 @@ void SwiftASTContext::ApplyWorkingDir(
15311532
clang_argument.append(joined_path.begin(), joined_path.end());
15321533
}
15331534

1535+
void SwiftASTContext::ApplyDiagnosticOptions() {
1536+
const auto &opts = GetCompilerInvocation().getDiagnosticOptions();
1537+
if (opts.PrintDiagnosticNames)
1538+
GetDiagnosticEngine().setPrintDiagnosticNames(true);
1539+
1540+
if (!opts.DiagnosticDocumentationPath.empty())
1541+
GetDiagnosticEngine().setDiagnosticDocumentationPath(
1542+
opts.DiagnosticDocumentationPath);
1543+
1544+
if (!opts.LocalizationCode.empty() && !opts.LocalizationPath.empty())
1545+
GetDiagnosticEngine().setLocalization(opts.LocalizationCode,
1546+
opts.LocalizationPath);
1547+
}
1548+
15341549
void SwiftASTContext::RemapClangImporterOptions(
15351550
const PathMappingList &path_map) {
15361551
auto &options = GetClangImporterOptions();
@@ -2301,6 +2316,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
23012316
swift_ast_sp->GetDiagnosticEngine());
23022317
}
23032318

2319+
swift_ast_sp->ApplyDiagnosticOptions();
2320+
23042321
// Apply source path remappings found in the target settings.
23052322
swift_ast_sp->RemapClangImporterOptions(target.GetSourcePathMap());
23062323

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,8 @@ class SwiftASTContext : public TypeSystemSwift {
936936

937937
friend class CompilerType;
938938

939+
void ApplyDiagnosticOptions();
940+
939941
/// Apply a PathMappingList dictionary on all search paths in the
940942
/// ClangImporterOptions.
941943
void RemapClangImporterOptions(const PathMappingList &path_map);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test diagnostic options in REPL
2+
// REQUIRES: swift
3+
4+
// RUN: %lldb --repl="-debug-diagnostic-names" < %s 2>&1 \
5+
// RUN: | FileCheck %s --check-prefix=DIAGNOSTIC
6+
7+
// RUN: split-file %s %t.dir
8+
// RUN: %lldb --repl="-localization-path %t.dir -locale fr" < %s 2>&1 \
9+
// RUN: | FileCheck %s --check-prefix=LOCALIZED
10+
11+
12+
_ = "An unterminated string
13+
// DIAGNOSTIC: error: unterminated string literal [lex_unterminated_string]{{$}}
14+
// LOCALIZED: error: chaîne non terminée littérale{{$}}
15+
:quit
16+
17+
18+
//--- fr.yaml
19+
- id: "lex_unterminated_string"
20+
msg: "chaîne non terminée littérale"

0 commit comments

Comments
 (0)