Skip to content

Commit 3d87d8a

Browse files
poyabnbarham
authored andcommitted
[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 7440ec9 commit 3d87d8a

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"
@@ -1541,6 +1542,20 @@ void SwiftASTContext::ApplyWorkingDir(
15411542
clang_argument.append(joined_path.begin(), joined_path.end());
15421543
}
15431544

1545+
void SwiftASTContext::ApplyDiagnosticOptions() {
1546+
const auto &opts = GetCompilerInvocation().getDiagnosticOptions();
1547+
if (opts.PrintDiagnosticNames)
1548+
GetDiagnosticEngine().setPrintDiagnosticNames(true);
1549+
1550+
if (!opts.DiagnosticDocumentationPath.empty())
1551+
GetDiagnosticEngine().setDiagnosticDocumentationPath(
1552+
opts.DiagnosticDocumentationPath);
1553+
1554+
if (!opts.LocalizationCode.empty() && !opts.LocalizationPath.empty())
1555+
GetDiagnosticEngine().setLocalization(opts.LocalizationCode,
1556+
opts.LocalizationPath);
1557+
}
1558+
15441559
void SwiftASTContext::RemapClangImporterOptions(
15451560
const PathMappingList &path_map) {
15461561
auto &options = GetClangImporterOptions();
@@ -2324,6 +2339,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
23242339
swift_ast_sp->GetDiagnosticEngine());
23252340
}
23262341

2342+
swift_ast_sp->ApplyDiagnosticOptions();
2343+
23272344
// Apply source path remappings found in the target settings.
23282345
swift_ast_sp->RemapClangImporterOptions(target.GetSourcePathMap());
23292346

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

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

922922
friend class CompilerType;
923923

924+
void ApplyDiagnosticOptions();
925+
924926
/// Apply a PathMappingList dictionary on all search paths in the
925927
/// ClangImporterOptions.
926928
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)