Skip to content

Commit 426f138

Browse files
committed
[Parse] Pass LangOptions to ide::isSourceInputComplete
Ensure we account for things like the enablement of bare slash regex literals.
1 parent 3ea125f commit 426f138

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

include/swift/IDE/Utils.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ struct SourceCompleteResult {
8080
};
8181

8282
SourceCompleteResult
83-
isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf, SourceFileKind SFKind);
84-
SourceCompleteResult isSourceInputComplete(StringRef Text, SourceFileKind SFKind);
83+
isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf,
84+
SourceFileKind SFKind, const LangOptions &LangOpts);
85+
SourceCompleteResult isSourceInputComplete(StringRef Text,
86+
SourceFileKind SFKind,
87+
const LangOptions &LangOpts);
8588

8689
/// Visits all overridden declarations exhaustively from VD, including protocol
8790
/// conformances and clang declarations.

lib/IDE/Utils.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ static const char *skipStringInCode(const char *p, const char *End) {
9696

9797
SourceCompleteResult
9898
ide::isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf,
99-
SourceFileKind SFKind) {
99+
SourceFileKind SFKind, const LangOptions &LangOpts) {
100100
SourceManager SM;
101101
auto BufferID = SM.addNewSourceBuffer(std::move(MemBuf));
102-
ParserUnit Parse(SM, SFKind, BufferID);
102+
ParserUnit Parse(SM, SFKind, BufferID, LangOpts, "input");
103103
Parse.parse();
104104
SourceCompleteResult SCR;
105105
SCR.IsComplete = !Parse.getParser().isInputIncomplete();
@@ -177,10 +177,11 @@ ide::isSourceInputComplete(std::unique_ptr<llvm::MemoryBuffer> MemBuf,
177177
return SCR;
178178
}
179179

180-
SourceCompleteResult
181-
ide::isSourceInputComplete(StringRef Text,SourceFileKind SFKind) {
180+
SourceCompleteResult ide::isSourceInputComplete(StringRef Text,
181+
SourceFileKind SFKind,
182+
const LangOptions &LangOpts) {
182183
return ide::isSourceInputComplete(llvm::MemoryBuffer::getMemBufferCopy(Text),
183-
SFKind);
184+
SFKind, LangOpts);
184185
}
185186

186187
template <typename FnTy>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// Make sure we consider the below source complete.
5+
// RUN: %swift-ide-test -test-input-complete -enable-bare-slash-regex -source-filename %t/bare-slash.swift | %FileCheck %s -check-prefix=COMPLETE
6+
7+
// Bare slash is currently disabled by default.
8+
// RUN: %swift-ide-test -test-input-complete -source-filename %t/bare-slash.swift | %FileCheck %s -check-prefix=INCOMPLETE
9+
10+
// RUN: %swift-ide-test -test-input-complete -source-filename %t/extended.swift | %FileCheck %s -check-prefix=COMPLETE
11+
12+
// INCOMPLETE: IS_INCOMPLETE
13+
// COMPLETE: IS_COMPLETE
14+
15+
//--- bare-slash.swift
16+
/\(/
17+
18+
//--- extended.swift
19+
#/\(/#

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,15 +2508,17 @@ static int doSemanticAnnotation(const CompilerInvocation &InitInvok,
25082508
return 0;
25092509
}
25102510

2511-
static int doInputCompletenessTest(StringRef SourceFilename) {
2511+
static int doInputCompletenessTest(const CompilerInvocation &InitInvok,
2512+
StringRef SourceFilename) {
25122513
std::unique_ptr<llvm::MemoryBuffer> FileBuf;
25132514
if (setBufferForFile(SourceFilename, FileBuf))
25142515
return 1;
25152516

25162517
llvm::raw_ostream &OS = llvm::outs();
25172518
OS << SourceFilename << ": ";
2518-
if (isSourceInputComplete(std::move(FileBuf),
2519-
SourceFileKind::Main).IsComplete) {
2519+
if (isSourceInputComplete(std::move(FileBuf), SourceFileKind::Main,
2520+
InitInvok.getLangOptions())
2521+
.IsComplete) {
25202522
OS << "IS_COMPLETE\n";
25212523
} else {
25222524
OS << "IS_INCOMPLETE\n";
@@ -4744,7 +4746,7 @@ int main(int argc, char *argv[]) {
47444746
break;
47454747

47464748
case ActionType::TestInputCompleteness:
4747-
ExitCode = doInputCompletenessTest(options::SourceFilename);
4749+
ExitCode = doInputCompletenessTest(InitInvok, options::SourceFilename);
47484750
break;
47494751

47504752
case ActionType::PrintASTNotTypeChecked:

0 commit comments

Comments
 (0)