Author: ibiryukov Date: Thu Aug 30 06:14:31 2018 New Revision: 341065 URL: http://llvm.org/viewvc/llvm-project?rev=341065&view=rev Log: [clangd] Report position of opening paren in singature help
Summary: Only accessible via the C++ API at the moment. Reviewers: sammccall Reviewed By: sammccall Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits Differential Revision: https://reviews.llvm.org/D51437 Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341065&r1=341064&r2=341065&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Aug 30 06:14:31 2018 @@ -794,7 +794,17 @@ public: void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, OverloadCandidate *Candidates, - unsigned NumCandidates) override { + unsigned NumCandidates, + SourceLocation OpenParLoc) override { + assert(!OpenParLoc.isInvalid()); + SourceManager &SrcMgr = S.getSourceManager(); + OpenParLoc = SrcMgr.getFileLoc(OpenParLoc); + if (SrcMgr.isInMainFile(OpenParLoc)) + SigHelp.argListStart = sourceLocToPosition(SrcMgr, OpenParLoc); + else + elog("Location oustide main file in signature help: {0}", + OpenParLoc.printToString(SrcMgr)); + std::vector<ScoredSignature> ScoredSignatures; SigHelp.signatures.reserve(NumCandidates); ScoredSignatures.reserve(NumCandidates); Modified: clang-tools-extra/trunk/clangd/Protocol.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=341065&r1=341064&r2=341065&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.h (original) +++ clang-tools-extra/trunk/clangd/Protocol.h Thu Aug 30 06:14:31 2018 @@ -828,6 +828,13 @@ struct SignatureHelp { /// The active parameter of the active signature. int activeParameter = 0; + + /// Position of the start of the argument list, including opening paren. e.g. + /// foo("first arg", "second arg", + /// ^-argListStart ^-cursor + /// This is a clangd-specific extension, it is only available via C++ API and + /// not currently serialized for the LSP. + Position argListStart; }; llvm::json::Value toJSON(const SignatureHelp &); Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=341065&r1=341064&r2=341065&view=diff ============================================================================== --- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original) +++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Thu Aug 30 06:14:31 2018 @@ -825,8 +825,7 @@ TEST(CompletionTest, IgnoreCompleteInExc EXPECT_TRUE(Results.Completions.empty()); } - -SignatureHelp signatures(StringRef Text, +SignatureHelp signatures(StringRef Text, Position Point, std::vector<Symbol> IndexSymbols = {}) { std::unique_ptr<SymbolIndex> Index; if (!IndexSymbols.empty()) @@ -840,9 +839,14 @@ SignatureHelp signatures(StringRef Text, ClangdServer Server(CDB, FS, DiagConsumer, Opts); auto File = testPath("foo.cpp"); + runAddDocument(Server, File, Text); + return cantFail(runSignatureHelp(Server, File, Point)); +} + +SignatureHelp signatures(StringRef Text, + std::vector<Symbol> IndexSymbols = {}) { Annotations Test(Text); - runAddDocument(Server, File, Test.code()); - return cantFail(runSignatureHelp(Server, File, Test.point())); + return signatures(Test.code(), Test.point(), std::move(IndexSymbols)); } MATCHER_P(ParamsAre, P, "") { @@ -907,6 +911,54 @@ TEST(SignatureHelpTest, ActiveArg) { EXPECT_EQ(1, Results.activeParameter); } +TEST(SignatureHelpTest, OpeningParen) { + llvm::StringLiteral Tests[] = {// Recursive function call. + R"cpp( + int foo(int a, int b, int c); + int main() { + foo(foo $p^( foo(10, 10, 10), ^ ))); + })cpp", + // Functional type cast. + R"cpp( + struct Foo { + Foo(int a, int b, int c); + }; + int main() { + Foo $p^( 10, ^ ); + })cpp", + // New expression. + R"cpp( + struct Foo { + Foo(int a, int b, int c); + }; + int main() { + new Foo $p^( 10, ^ ); + })cpp", + // Macro expansion. + R"cpp( + int foo(int a, int b, int c); + #define FOO foo( + + int main() { + // Macro expansions. + $p^FOO 10, ^ ); + })cpp", + // Macro arguments. + R"cpp( + int foo(int a, int b, int c); + int main() { + #define ID(X) X + ID(foo $p^( foo(10), ^ )) + })cpp"}; + + for (auto Test : Tests) { + Annotations Code(Test); + EXPECT_EQ(signatures(Code.code(), Code.point()).argListStart, + Code.point("p")) + << "Test source:" << Test; + } +} + class IndexRequestCollector : public SymbolIndex { public: bool _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits