[clang-tools-extra] r339224 - Added functionality to suggest FixIts for conversion of '->' to '.' and vice versa.

2018-08-09 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Aug  8 01:59:29 2018
New Revision: 339224

URL: http://llvm.org/viewvc/llvm-project?rev=339224&view=rev
Log:
Added functionality to suggest FixIts for conversion of '->' to '.' and vice 
versa.

Summary: Added functionality to suggest FixIts for conversion of '->' to '.' 
and vice versa.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: yvvan, ioeric, jkorous, arphaman, cfe-commits, kadircet

Differential Revision: https://reviews.llvm.org/D50193

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/Quality.h
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=339224&r1=339223&r2=339224&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Aug  8 01:59:29 2018
@@ -22,6 +22,7 @@
 #include "AST.h"
 #include "CodeCompletionStrings.h"
 #include "Compiler.h"
+#include "Diagnostics.h"
 #include "FileDistance.h"
 #include "FuzzyMatch.h"
 #include "Headers.h"
@@ -280,6 +281,10 @@ struct CodeCompletionBuilder {
   }
   Completion.Kind =
   toCompletionItemKind(C.SemaResult->Kind, C.SemaResult->Declaration);
+  for (const auto &FixIt : C.SemaResult->FixIts) {
+Completion.FixIts.push_back(
+toTextEdit(FixIt, ASTCtx.getSourceManager(), 
ASTCtx.getLangOpts()));
+  }
 }
 if (C.IndexResult) {
   Completion.Origin |= C.IndexResult->Origin;
@@ -906,6 +911,7 @@ clang::CodeCompleteOptions CodeCompleteO
   // the index can provide results from the preamble.
   // Tell Sema not to deserialize the preamble to look for results.
   Result.LoadExternal = !Index;
+  Result.IncludeFixIts = IncludeFixIts;
 
   return Result;
 }
@@ -1090,8 +1096,8 @@ private:
   // Groups overloads if desired, to form CompletionCandidate::Bundles.
   // The bundles are scored and top results are returned, best to worst.
   std::vector
-  mergeResults(const std::vector &SemaResults,
-   const SymbolSlab &IndexResults) {
+  mergeResults(const std::vector &SemaResults,
+   const SymbolSlab &IndexResults) {
 trace::Span Tracer("Merge and score results");
 std::vector Bundles;
 llvm::DenseMap BundleLookup;
@@ -1272,13 +1278,18 @@ CompletionItem CodeCompletion::render(co
   LSP.documentation = Documentation;
   LSP.sortText = sortText(Score.Total, Name);
   LSP.filterText = Name;
+  // FIXME(kadircet): Use LSP.textEdit instead of insertText, because it causes
+  // undesired behaviours. Like completing "this.^" into "this-push_back".
   LSP.insertText = RequiredQualifier + Name;
   if (Opts.EnableSnippets)
 LSP.insertText += SnippetSuffix;
   LSP.insertTextFormat = Opts.EnableSnippets ? InsertTextFormat::Snippet
  : InsertTextFormat::PlainText;
+  LSP.additionalTextEdits.reserve(FixIts.size() + (HeaderInsertion ? 1 : 0));
+  for (const auto &FixIt : FixIts)
+LSP.additionalTextEdits.push_back(FixIt);
   if (HeaderInsertion)
-LSP.additionalTextEdits = {*HeaderInsertion};
+LSP.additionalTextEdits.push_back(*HeaderInsertion);
   return LSP;
 }
 

Modified: clang-tools-extra/trunk/clangd/CodeComplete.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=339224&r1=339223&r2=339224&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.h (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.h Wed Aug  8 01:59:29 2018
@@ -77,6 +77,10 @@ struct CodeCompleteOptions {
   /// FIXME(ioeric): we might want a better way to pass the index around inside
   /// clangd.
   const SymbolIndex *Index = nullptr;
+
+  /// Include completions that require small corrections, e.g. change '.' to
+  /// '->' on member access etc.
+  bool IncludeFixIts = false;
 };
 
 // Semi-structured representation of a code-complete suggestion for our C++ 
API.
@@ -115,6 +119,10 @@ struct CodeCompletion {
   // Present if Header is set and should be inserted to use this item.
   llvm::Optional HeaderInsertion;
 
+  /// Holds information about small corrections that needs to be done. Like
+  /// converting '->' to '.' on member access.
+  std::vector FixIts;
+
   // Scores are used to rank completion items.
   struct Scores {
 // The score that items are ranked by.

r339540 - [clang] Store code completion token range in preprocessor.

2018-08-13 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Aug 13 01:13:35 2018
New Revision: 339540

URL: http://llvm.org/viewvc/llvm-project?rev=339540&view=rev
Log:
[clang] Store code completion token range in preprocessor.

Summary:
This change is to support a new fature in clangd, tests will be send 
toclang-tools-extra with that change.

Unittests are included in: https://reviews.llvm.org/D50449

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D50443

Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=339540&r1=339539&r2=339540&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Mon Aug 13 01:13:35 2018
@@ -310,6 +310,9 @@ class Preprocessor {
   /// on the stem that is to be code completed.
   IdentifierInfo *CodeCompletionII = nullptr;
 
+  /// Range for the code completion token.
+  SourceRange CodeCompletionTokenRange;
+
   /// The directory that the main file should be considered to occupy,
   /// if it does not correspond to a real file (as happens when building a
   /// module).
@@ -1131,6 +1134,16 @@ public:
 CodeCompletionII = Filter;
   }
 
+  /// Set the code completion token range for detecting replacement range later
+  /// on.
+  void setCodeCompletionTokenRange(const SourceLocation Start,
+   const SourceLocation End) {
+CodeCompletionTokenRange = {Start, End};
+  }
+  SourceRange getCodeCompletionTokenRange() const {
+return CodeCompletionTokenRange;
+  }
+
   /// Get the code completion token for filtering purposes.
   StringRef getCodeCompletionFilter() {
 if (CodeCompletionII)

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=339540&r1=339539&r2=339540&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Mon Aug 13 01:13:35 2018
@@ -868,6 +868,7 @@ void Preprocessor::Lex(Token &Result) {
   if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) {
 // Remember the identifier before code completion token.
 setCodeCompletionIdentifierInfo(Result.getIdentifierInfo());
+setCodeCompletionTokenRange(Result.getLocation(), Result.getEndLoc());
 // Set IdenfitierInfo to null to avoid confusing code that handles both
 // identifiers and completion tokens.
 Result.setIdentifierInfo(nullptr);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r339543 - [clangd] Support textEdit in addition to insertText.

2018-08-13 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Aug 13 01:23:01 2018
New Revision: 339543

URL: http://llvm.org/viewvc/llvm-project?rev=339543&view=rev
Log:
[clangd] Support textEdit in addition to insertText.

Summary:
Completion replies contains textEdits as well. Note that this change
relies on https://reviews.llvm.org/D50443.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: mgrang, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D50449

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=339543&r1=339542&r2=339543&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Aug 13 01:23:01 2018
@@ -34,6 +34,7 @@
 #include "index/Index.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -285,6 +286,11 @@ struct CodeCompletionBuilder {
 Completion.FixIts.push_back(
 toTextEdit(FixIt, ASTCtx.getSourceManager(), 
ASTCtx.getLangOpts()));
   }
+  std::sort(Completion.FixIts.begin(), Completion.FixIts.end(),
+[](const TextEdit &X, const TextEdit &Y) {
+  return std::tie(X.range.start.line, X.range.start.character) 
<
+ std::tie(Y.range.start.line, Y.range.start.character);
+});
 }
 if (C.IndexResult) {
   Completion.Origin |= C.IndexResult->Origin;
@@ -1044,6 +1050,23 @@ private:
   // This is called by run() once Sema code completion is done, but before the
   // Sema data structures are torn down. It does all the real work.
   CodeCompleteResult runWithSema() {
+const auto &CodeCompletionRange = CharSourceRange::getCharRange(
+Recorder->CCSema->getPreprocessor().getCodeCompletionTokenRange());
+Range TextEditRange;
+// When we are getting completions with an empty identifier, for example
+//std::vector asdf;
+//asdf.^;
+// Then the range will be invalid and we will be doing insertion, use
+// current cursor position in such cases as range.
+if (CodeCompletionRange.isValid()) {
+  TextEditRange = halfOpenToRange(Recorder->CCSema->getSourceManager(),
+  CodeCompletionRange);
+} else {
+  const auto &Pos = sourceLocToPosition(
+  Recorder->CCSema->getSourceManager(),
+  Recorder->CCSema->getPreprocessor().getCodeCompletionLoc());
+  TextEditRange.start = TextEditRange.end = Pos;
+}
 Filter = FuzzyMatcher(
 Recorder->CCSema->getPreprocessor().getCodeCompletionFilter());
 QueryScopes = getQueryScopes(Recorder->CCContext,
@@ -1063,6 +1086,7 @@ private:
 for (auto &C : Top) {
   Output.Completions.push_back(toCodeCompletion(C.first));
   Output.Completions.back().Score = C.second;
+  Output.Completions.back().CompletionTokenRange = TextEditRange;
 }
 Output.HasMore = Incomplete;
 Output.Context = Recorder->CCContext.getKind();
@@ -1278,16 +1302,29 @@ CompletionItem CodeCompletion::render(co
   LSP.documentation = Documentation;
   LSP.sortText = sortText(Score.Total, Name);
   LSP.filterText = Name;
-  // FIXME(kadircet): Use LSP.textEdit instead of insertText, because it causes
-  // undesired behaviours. Like completing "this.^" into "this-push_back".
-  LSP.insertText = RequiredQualifier + Name;
+  LSP.textEdit = {CompletionTokenRange, RequiredQualifier + Name};
+  // Merge continious additionalTextEdits into main edit. The main motivation
+  // behind this is to help LSP clients, it seems most of them are confused 
when
+  // they are provided with additionalTextEdits that are consecutive to main
+  // edit.
+  // Note that we store additional text edits from back to front in a line. 
That
+  // is mainly to help LSP clients again, so that changes do not effect each
+  // other.
+  for (const auto &FixIt : FixIts) {
+if (IsRangeConsecutive(FixIt.range, LSP.textEdit->range)) {
+  LSP.textEdit->newText = FixIt.newText + LSP.textEdit->newText;
+  LSP.textEdit->range.start = FixIt.range.start;
+} else {
+  LSP.additionalTextEdits.push_back(FixIt);
+}
+  }
   if (Opts.EnableSnippets)
-LSP.insertText += SnippetSuffix;
+LSP.textEdit->newText += SnippetSuffix;
+  // FIXME(kadircet): Do not 

[clang-tools-extra] r339547 - [clangd] Introduce scoring mechanism for SignatureInformations.

2018-08-13 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Aug 13 01:40:05 2018
New Revision: 339547

URL: http://llvm.org/viewvc/llvm-project?rev=339547&view=rev
Log:
[clangd] Introduce scoring mechanism for SignatureInformations.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: mgrang, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D50555

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/Quality.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=339547&r1=339546&r2=339547&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Aug 13 01:40:05 2018
@@ -129,16 +129,16 @@ toCompletionItemKind(CodeCompletionResul
 /// Get the optional chunk as a string. This function is possibly recursive.
 ///
 /// The parameter info for each parameter is appended to the Parameters.
-std::string
-getOptionalParameters(const CodeCompletionString &CCS,
-  std::vector &Parameters) {
+std::string getOptionalParameters(const CodeCompletionString &CCS,
+  std::vector 
&Parameters,
+  SignatureQualitySignals &Signal) {
   std::string Result;
   for (const auto &Chunk : CCS) {
 switch (Chunk.Kind) {
 case CodeCompletionString::CK_Optional:
   assert(Chunk.Optional &&
  "Expected the optional code completion string to be non-null.");
-  Result += getOptionalParameters(*Chunk.Optional, Parameters);
+  Result += getOptionalParameters(*Chunk.Optional, Parameters, Signal);
   break;
 case CodeCompletionString::CK_VerticalSpace:
   break;
@@ -154,6 +154,8 @@ getOptionalParameters(const CodeCompleti
   ParameterInformation Info;
   Info.label = Chunk.Text;
   Parameters.push_back(std::move(Info));
+  Signal.ContainsActiveParameter = true;
+  Signal.NumberOfOptionalParameters++;
   break;
 }
 default:
@@ -685,6 +687,9 @@ private:
   llvm::unique_function ResultsCallback;
 };
 
+using ScoredSignature =
+std::pair;
+
 class SignatureHelpCollector final : public CodeCompleteConsumer {
 
 public:
@@ -698,7 +703,9 @@ public:
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
  unsigned NumCandidates) override {
+std::vector ScoredSignatures;
 SigHelp.signatures.reserve(NumCandidates);
+ScoredSignatures.reserve(NumCandidates);
 // FIXME(rwols): How can we determine the "active overload candidate"?
 // Right now the overloaded candidates seem to be provided in a "best fit"
 // order, so I'm not too worried about this.
@@ -712,11 +719,45 @@ public:
   CurrentArg, S, *Allocator, CCTUInfo, true);
   assert(CCS && "Expected the CodeCompletionString to be non-null");
   // FIXME: for headers, we need to get a comment from the index.
-  SigHelp.signatures.push_back(processOverloadCandidate(
+  ScoredSignatures.push_back(processOverloadCandidate(
   Candidate, *CCS,
   getParameterDocComment(S.getASTContext(), Candidate, CurrentArg,
  /*CommentsFromHeaders=*/false)));
 }
+std::sort(ScoredSignatures.begin(), ScoredSignatures.end(),
+  [](const ScoredSignature &L, const ScoredSignature &R) {
+// Ordering follows:
+// - Less number of parameters is better.
+// - Function is better than FunctionType which is better than
+// Function Template.
+// - High score is better.
+// - Shorter signature is better.
+// - Alphebatically smaller is better.
+if (L.first.NumberOfParameters != R.first.NumberOfParameters)
+  return L.first.NumberOfParameters <
+ R.first.NumberOfParameters;
+if (L.first.NumberOfOptionalParameters !=
+R.first.NumberOfOptionalParameters)
+  return L.first.NumberOfOptionalParameters <
+ R.first.NumberOfOptionalParameters;
+if (L.first.Kind != R.first.Kind) {
+  using OC = CodeCompleteConsumer::OverloadCandidate;
+  switch (L.first.Kind) {
+  case OC::CK_Function:
+return true;
+  case OC::CK_FunctionType:
+return R.first.Kind != OC::CK_Function;
+  case OC::CK_FunctionTemplate:
+return false;
+  }
+ 

[clang-tools-extra] r339572 - Fix lint tests for D50449

2018-08-13 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Aug 13 07:32:19 2018
New Revision: 339572

URL: http://llvm.org/viewvc/llvm-project?rev=339572&view=rev
Log:
Fix lint tests for D50449

Reviewers: ilya-biryukov, hokein

Reviewed By: hokein

Subscribers: hokein, ioeric, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D50635

Modified:
clang-tools-extra/trunk/test/clangd/completion-snippets.test
clang-tools-extra/trunk/test/clangd/completion.test

Modified: clang-tools-extra/trunk/test/clangd/completion-snippets.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion-snippets.test?rev=339572&r1=339571&r2=339572&view=diff
==
--- clang-tools-extra/trunk/test/clangd/completion-snippets.test (original)
+++ clang-tools-extra/trunk/test/clangd/completion-snippets.test Mon Aug 13 
07:32:19 2018
@@ -34,6 +34,19 @@
 # CHECK-NEXT:  "kind": 3,
 # CHECK-NEXT:  "label": " func_with_args(int a, int b)",
 # CHECK-NEXT:  "sortText": "{{.*}}func_with_args"
+# CHECK-NEXT:  "textEdit": {
+# CHECK-NEXT:"newText": "func_with_args(${1:int a}, ${2:int b})",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 7,
+# CHECK-NEXT:"line": 2
+# CHECK-NEXT:  }
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 0,
+# CHECK-NEXT:"line": 2
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
 # CHECK-NEXT:}
 # CHECK-NEXT:]
 # CHECK-NEXT:  }

Modified: clang-tools-extra/trunk/test/clangd/completion.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/completion.test?rev=339572&r1=339571&r2=339572&view=diff
==
--- clang-tools-extra/trunk/test/clangd/completion.test (original)
+++ clang-tools-extra/trunk/test/clangd/completion.test Mon Aug 13 07:32:19 2018
@@ -18,6 +18,19 @@
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": " a",
 # CHECK-NEXT:  "sortText": "{{.*}}a"
+# CHECK-NEXT:  "textEdit": {
+# CHECK-NEXT:"newText": "a",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 4,
+# CHECK-NEXT:"line": 2
+# CHECK-NEXT:  }
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 4,
+# CHECK-NEXT:"line": 2
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 ---
@@ -38,6 +51,19 @@
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": " b",
 # CHECK-NEXT:  "sortText": "{{.*}}b"
+# CHECK-NEXT:  "textEdit": {
+# CHECK-NEXT:"newText": "b",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 4,
+# CHECK-NEXT:"line": 2
+# CHECK-NEXT:  }
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 4,
+# CHECK-NEXT:"line": 2
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
 # CHECK-NEXT:}
 # CHECK-NEXT:  ]
 ---


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r340040 - [clangd] Add parantheses while auto-completing functions.

2018-08-17 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Aug 17 08:42:54 2018
New Revision: 340040

URL: http://llvm.org/viewvc/llvm-project?rev=340040&view=rev
Log:
[clangd] Add parantheses while auto-completing functions.

Summary:
Currently we only add parantheses to the functions if snippets are
enabled, which also inserts snippets for parameters into parantheses. Adding a
new option to put only parantheses. Also it moves the cursor within parantheses
or at the end of them by looking at whether completion item has any parameters
or not. Still requires snippets support on the client side.

Reviewers: ioeric, ilya-biryukov, hokein

Reviewed By: ioeric

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D50835

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.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=340040&r1=340039&r2=340040&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Aug 17 08:42:54 2018
@@ -1413,8 +1413,17 @@ CompletionItem CodeCompletion::render(co
   LSP.additionalTextEdits.push_back(FixIt);
 }
   }
-  if (Opts.EnableSnippets)
-LSP.textEdit->newText += SnippetSuffix;
+  if (Opts.EnableSnippets && !SnippetSuffix.empty()) {
+if (!Opts.EnableFunctionArgSnippets &&
+((Kind == CompletionItemKind::Function) ||
+ (Kind == CompletionItemKind::Method)) &&
+(SnippetSuffix.front() == '(') && (SnippetSuffix.back() == ')'))
+  // Check whether function has any parameters or not.
+  LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
+else
+  LSP.textEdit->newText += SnippetSuffix;
+  }
+
   // FIXME(kadircet): Do not even fill insertText after making sure textEdit is
   // compatible with most of the editors.
   LSP.insertText = LSP.textEdit->newText;

Modified: clang-tools-extra/trunk/clangd/CodeComplete.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=340040&r1=340039&r2=340040&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.h (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.h Fri Aug 17 08:42:54 2018
@@ -82,6 +82,10 @@ struct CodeCompleteOptions {
   /// Include completions that require small corrections, e.g. change '.' to
   /// '->' on member access etc.
   bool IncludeFixIts = false;
+
+  /// Whether to generate snippets for function arguments on code-completion.
+  /// Needs snippets to be enabled as well.
+  bool EnableFunctionArgSnippets = true;
 };
 
 // Semi-structured representation of a code-complete suggestion for our C++ 
API.

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=340040&r1=340039&r2=340040&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Fri Aug 17 
08:42:54 2018
@@ -1648,6 +1648,58 @@ TEST(SignatureHelpTest, IndexDocumentati
 SigDoc("Doc from sema";
 }
 
+TEST(CompletionTest, RenderWithSnippetsForFunctionArgsDisabled) {
+  CodeCompleteOptions Opts;
+  Opts.EnableFunctionArgSnippets = true;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::PlainText);
+  }
+
+  Opts.EnableSnippets = true;
+  Opts.EnableFunctionArgSnippets = false;
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "";
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "()";
+C.Kind = CompletionItemKind::Method;
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x()");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+
+  {
+CodeCompletion C;
+C.RequiredQualifier = "Foo::";
+C.Name = "x";
+C.SnippetSuffix = "(${0:bool})";
+C.Kind = CompletionItemKind::Function;
+
+auto R = C.render(Opts);
+EXPECT_EQ(R.textEdit->newText, "Foo::x(${0})");
+EXPECT_EQ(R.insertTextFormat, InsertTextFormat::Snippet);
+  }
+}
+
 } // namespace
 } // n

[clang-tools-extra] r340527 - [clangd] Move function argument snippet disable mechanism from LSP rendering to internal clangd reprensentation.

2018-08-23 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Aug 23 05:19:39 2018
New Revision: 340527

URL: http://llvm.org/viewvc/llvm-project?rev=340527&view=rev
Log:
[clangd] Move function argument snippet disable mechanism from LSP rendering to 
internal clangd reprensentation.

Summary:
We were handling the EnableFunctionArgSnippets only when we are producing LSP
response. Move that code into CompletionItem generation so that internal clients
can benefit from that as well.

Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51102

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
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=340527&r1=340526&r2=340527&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Aug 23 05:19:39 2018
@@ -269,7 +269,8 @@ struct CodeCompletionBuilder {
 CodeCompletionString *SemaCCS,
 const IncludeInserter &Includes, StringRef FileName,
 const CodeCompleteOptions &Opts)
-  : ASTCtx(ASTCtx), ExtractDocumentation(Opts.IncludeComments) {
+  : ASTCtx(ASTCtx), ExtractDocumentation(Opts.IncludeComments),
+EnableFunctionArgSnippets(Opts.EnableFunctionArgSnippets) {
 add(C, SemaCCS);
 if (C.SemaResult) {
   Completion.Origin |= SymbolOrigin::AST;
@@ -385,10 +386,17 @@ private:
   }
 
   std::string summarizeSnippet() const {
-if (auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>())
-  return *Snippet;
-// All bundles are function calls.
-return "(${0})";
+auto *Snippet = onlyValue<&BundledEntry::SnippetSuffix>();
+if (!Snippet)
+  // All bundles are function calls.
+  return "($0)";
+if (!Snippet->empty() && !EnableFunctionArgSnippets &&
+((Completion.Kind == CompletionItemKind::Function) ||
+ (Completion.Kind == CompletionItemKind::Method)) &&
+(Snippet->front() == '(') && (Snippet->back() == ')'))
+  // Check whether function has any parameters or not.
+  return Snippet->size() > 2 ? "($0)" : "()";
+return *Snippet;
   }
 
   std::string summarizeSignature() const {
@@ -402,6 +410,7 @@ private:
   CodeCompletion Completion;
   SmallVector Bundled;
   bool ExtractDocumentation;
+  bool EnableFunctionArgSnippets;
 };
 
 // Determine the symbol ID for a Sema code completion result, if possible.
@@ -1413,16 +1422,8 @@ CompletionItem CodeCompletion::render(co
   LSP.additionalTextEdits.push_back(FixIt);
 }
   }
-  if (Opts.EnableSnippets && !SnippetSuffix.empty()) {
-if (!Opts.EnableFunctionArgSnippets &&
-((Kind == CompletionItemKind::Function) ||
- (Kind == CompletionItemKind::Method)) &&
-(SnippetSuffix.front() == '(') && (SnippetSuffix.back() == ')'))
-  // Check whether function has any parameters or not.
-  LSP.textEdit->newText += SnippetSuffix.size() > 2 ? "(${0})" : "()";
-else
-  LSP.textEdit->newText += SnippetSuffix;
-  }
+  if (Opts.EnableSnippets)
+LSP.textEdit->newText += SnippetSuffix;
 
   // FIXME(kadircet): Do not even fill insertText after making sure textEdit is
   // compatible with most of the editors.

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=340527&r1=340526&r2=340527&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Thu Aug 23 
05:19:39 2018
@@ -1140,7 +1140,7 @@ TEST(CompletionTest, OverloadBundling) {
   // For now we just return one of the doc strings arbitrarily.
   EXPECT_THAT(A.Documentation, AnyOf(HasSubstr("Overload with int"),
  HasSubstr("Overload with bool")));
-  EXPECT_EQ(A.SnippetSuffix, "(${0})");
+  EXPECT_EQ(A.SnippetSuffix, "($0)");
 }
 
 TEST(CompletionTest, DocumentationFromChangedFileCrash) {
@@ -1648,55 +1648,35 @@ TEST(SignatureHelpTest, IndexDocumentati
 SigDoc("Doc from sema";
 }
 
-TEST(CompletionTest, RenderWithSnippetsForFunctionArgsDisabled) {
+TEST(CompletionTest, CompletionFunctionArgsDisabled) {
   CodeCompleteOptions Opts;
-  Opts.EnableFunctionArgSnippets = true;
-  {
-CodeCompletion C;
-C.RequiredQualifier = "Foo::";
-C.Name = "x";
-C.SnippetSuffix = "()";
-
-auto R = C.render(Opts);
-EXPECT_EQ(R.textEdit->newText, "Foo::x");
-EXPECT_EQ(R.insertTextFormat, InsertTextForm

[clang-tools-extra] r340530 - [clangd] Suggest code-completions for overriding base class virtual methods.

2018-08-23 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Aug 23 06:14:50 2018
New Revision: 340530

URL: http://llvm.org/viewvc/llvm-project?rev=340530&view=rev
Log:
[clangd] Suggest code-completions for overriding base class virtual methods.

Summary:
Whenever a code-completion is triggered within a class/struct/union looks at
base classes and figures out non-overriden virtual functions. Than suggests
completions for those.

Reviewers: ilya-biryukov, hokein, ioeric

Reviewed By: hokein

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D50898

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
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=340530&r1=340529&r2=340530&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Aug 23 06:14:50 2018
@@ -188,6 +188,55 @@ static llvm::Expected toHead
   return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
 }
 
+// First traverses all method definitions inside current class/struct/union
+// definition. Than traverses base classes to find virtual methods that haven't
+// been overriden within current context.
+// FIXME(kadircet): Currently we cannot see declarations below completion 
point.
+// It is because Sema gets run only upto completion point. Need to find a
+// solution to run it for the whole class/struct/union definition.
+static std::vector
+getNonOverridenMethodCompletionResults(const DeclContext *DC, Sema *S) {
+  const auto *CR = llvm::dyn_cast(DC);
+  // If not inside a class/struct/union return empty.
+  if (!CR)
+return {};
+  // First store overrides within current class.
+  // These are stored by name to make querying fast in the later step.
+  llvm::StringMap> Overrides;
+  for (auto *Method : CR->methods()) {
+if (!Method->isVirtual())
+  continue;
+Overrides[Method->getName()].push_back(Method);
+  }
+
+  std::vector Results;
+  for (const auto &Base : CR->bases()) {
+const auto *BR = Base.getType().getTypePtr()->getAsCXXRecordDecl();
+if (!BR)
+  continue;
+for (auto *Method : BR->methods()) {
+  if (!Method->isVirtual())
+continue;
+  const auto it = Overrides.find(Method->getName());
+  bool IsOverriden = false;
+  if (it != Overrides.end()) {
+for (auto *MD : it->second) {
+  // If the method in current body is not an overload of this virtual
+  // function, that it overrides this one.
+  if (!S->IsOverload(MD, Method, false)) {
+IsOverriden = true;
+break;
+  }
+}
+  }
+  if (!IsOverriden)
+Results.emplace_back(Method, 0);
+}
+  }
+
+  return Results;
+}
+
 /// A code completion result, in clang-native form.
 /// It may be promoted to a CompletionItem if it's among the top-ranked 
results.
 struct CompletionCandidate {
@@ -196,6 +245,9 @@ struct CompletionCandidate {
   const CodeCompletionResult *SemaResult = nullptr;
   const Symbol *IndexResult = nullptr;
 
+  // States whether this item is an override suggestion.
+  bool IsOverride = false;
+
   // Returns a token identifying the overload set this is part of.
   // 0 indicates it's not part of any overload set.
   size_t overloadSet() const {
@@ -352,6 +404,8 @@ struct CodeCompletionBuilder {
 Completion.Documentation = getDocComment(ASTCtx, *C.SemaResult,
  /*CommentsFromHeader=*/false);
 }
+if (C.IsOverride)
+  S.OverrideSuffix = true;
   }
 
   CodeCompletion build() {
@@ -359,6 +413,12 @@ struct CodeCompletionBuilder {
 Completion.Signature = summarizeSignature();
 Completion.SnippetSuffix = summarizeSnippet();
 Completion.BundleSize = Bundled.size();
+if (summarizeOverride()) {
+  Completion.Name = Completion.ReturnType + ' ' +
+std::move(Completion.Name) +
+std::move(Completion.Signature) + " override";
+  Completion.Signature.clear();
+}
 return std::move(Completion);
   }
 
@@ -367,6 +427,7 @@ private:
 std::string SnippetSuffix;
 std::string Signature;
 std::string ReturnType;
+bool OverrideSuffix;
   };
 
   // If all BundledEntrys have the same value for a property, return it.
@@ -379,6 +440,14 @@ private:
 return &(B->*Member);
   }
 
+  template  const bool *onlyValue() const {
+auto B = Bundled.begin(), E = Bundled.end();
+for (auto I = B + 1; I != E; ++I)
+  if (I->*Member != B->*Member)
+return nullptr;
+return &(B->*Member);
+  }
+
   std::string summarizeReturnType() const {
 if (auto *RT = onlyValue<&BundledEntry::ReturnType>())
   return *RT;
@@ -406,6 +475,12 @@ priv

[clang-tools-extra] r340539 - [clangd] Check for include overlapping looks for only the line now.

2018-08-23 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Aug 23 08:55:27 2018
New Revision: 340539

URL: http://llvm.org/viewvc/llvm-project?rev=340539&view=rev
Log:
[clangd] Check for include overlapping looks for only the line now.

Summary:
Currently we match an include only if we are inside filename, with this patch we
will match whenever we are on the starting line of the include.

Reviewers: ilya-biryukov, hokein, ioeric

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51163

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=340539&r1=340538&r2=340539&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Aug 23 08:55:27 2018
@@ -211,7 +211,7 @@ std::vector findDefinitions(Pa
   std::vector Result;
   // Handle goto definition for #include.
   for (auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
-if (!Inc.Resolved.empty() && Inc.R.contains(Pos))
+if (!Inc.Resolved.empty() && Inc.R.start.line == Pos.line)
   Result.push_back(Location{URIForFile{Inc.Resolved}, {}});
   }
   if (!Result.empty())

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=340539&r1=340538&r2=340539&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Thu Aug 23 08:55:27 
2018
@@ -1014,11 +1014,13 @@ TEST(GoToInclude, All) {
 
   Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("5"));
   ASSERT_TRUE(bool(Locations)) << "findDefinitions returned an error";
-  EXPECT_THAT(*Locations, IsEmpty());
+  EXPECT_THAT(*Locations,
+  ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
 
   Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("7"));
   ASSERT_TRUE(bool(Locations)) << "findDefinitions returned an error";
-  EXPECT_THAT(*Locations, IsEmpty());
+  EXPECT_THAT(*Locations,
+  ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
 }
 
 TEST(GoToDefinition, WithPreamble) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r340607 - [clangd] Initial cancellation mechanism for LSP requests.

2018-08-24 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Aug 24 06:09:41 2018
New Revision: 340607

URL: http://llvm.org/viewvc/llvm-project?rev=340607&view=rev
Log:
[clangd] Initial cancellation mechanism for LSP requests.

Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: mgorny, ioeric, MaskRay, jkorous, arphaman, jfb, cfe-commits

Differential Revision: https://reviews.llvm.org/D50502

Added:
clang-tools-extra/trunk/clangd/Cancellation.cpp
clang-tools-extra/trunk/clangd/Cancellation.h
clang-tools-extra/trunk/unittests/clangd/CancellationTests.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=340607&r1=340606&r2=340607&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Aug 24 06:09:41 2018
@@ -9,6 +9,7 @@ endif()
 
 add_clang_library(clangDaemon
   AST.cpp
+  Cancellation.cpp
   ClangdLSPServer.cpp
   ClangdServer.cpp
   ClangdUnit.cpp

Added: clang-tools-extra/trunk/clangd/Cancellation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Cancellation.cpp?rev=340607&view=auto
==
--- clang-tools-extra/trunk/clangd/Cancellation.cpp (added)
+++ clang-tools-extra/trunk/clangd/Cancellation.cpp Fri Aug 24 06:09:41 2018
@@ -0,0 +1,34 @@
+//===--- Cancellation.cpp 
-*-C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Cancellation.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+namespace {
+static Key TaskKey;
+} // namespace
+
+char CancelledError::ID = 0;
+
+const Task &getCurrentTask() {
+  const auto TH = Context::current().getExisting(TaskKey);
+  assert(TH && "Fetched a nullptr for TaskHandle from context.");
+  return *TH;
+}
+
+Context setCurrentTask(ConstTaskHandle TH) {
+  assert(TH && "Trying to stash a nullptr as TaskHandle into context.");
+  return Context::current().derive(TaskKey, std::move(TH));
+}
+
+} // namespace clangd
+} // namespace clang

Added: clang-tools-extra/trunk/clangd/Cancellation.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Cancellation.h?rev=340607&view=auto
==
--- clang-tools-extra/trunk/clangd/Cancellation.h (added)
+++ clang-tools-extra/trunk/clangd/Cancellation.h Fri Aug 24 06:09:41 2018
@@ -0,0 +1,142 @@
+//===--- Cancellation.h 
---*-C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+// Cancellation mechanism for async tasks. Roughly all the clients of this code
+// can be classified into three categories:
+// 1. The code that creates and schedules async tasks, e.g. TUScheduler.
+// 2. The callers of the async method that can cancel some of the running 
tasks,
+// e.g. `ClangdLSPServer`
+// 3. The code running inside the async task itself, i.e. code completion or
+// find definition implementation that run clang, etc.
+//
+// For (1), the guideline is to accept a callback for the result of async
+// operation and return a `TaskHandle` to allow cancelling the request.
+//
+//  TaskHandle someAsyncMethod(Runnable T,
+//  function)> Callback) {
+//   auto TH = Task::createHandle();
+//   WithContext ContextWithCancellationToken(TH);
+//   auto run = [](){
+// Callback(T());
+//   }
+//   // Start run() in a new async thread, and make sure to propagate Context.
+//   return TH;
+// }
+//
+// The callers of async methods (2) can issue cancellations and should be
+// prepared to handle `TaskCancelledError` result:
+//
+// void Caller() {
+//   // You should store this handle if you wanna cancel the task later on.
+//   Task

r341824 - [clang] Make sure codecompletion is called for calls even when inside a token.

2018-09-10 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Sep 10 06:46:28 2018
New Revision: 341824

URL: http://llvm.org/viewvc/llvm-project?rev=341824&view=rev
Log:
[clang] Make sure codecompletion is called for calls even when inside a token.

Summary:
Currently CodeCompleteCall only gets called after a comma or parantheses. This
patch makes sure it is called even at the cases like:
```foo(1^);```

Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51038

Added:
cfe/trunk/test/CodeCompletion/function-overloads.cpp
Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/test/Index/complete-block-property-assignment.m

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=341824&r1=341823&r2=341824&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Sep 10 06:46:28 2018
@@ -214,6 +214,11 @@ class Parser : public CodeCompletionHand
   /// should not be set directly.
   bool InMessageExpression;
 
+  /// Gets set to true after calling ProduceSignatureHelp, it is for a
+  /// workaround to make sure ProduceSignatureHelp is only called at the 
deepest
+  /// function call.
+  bool CalledSignatureHelp = false;
+
   /// The "depth" of the template parameters currently being parsed.
   unsigned TemplateParameterDepth;
 

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=341824&r1=341823&r2=341824&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Mon Sep 10 06:46:28 2018
@@ -2305,6 +2305,7 @@ Decl *Parser::ParseDeclarationAfterDecla
   QualType PreferredType = Actions.ProduceConstructorSignatureHelp(
   getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
   ThisDecl->getLocation(), Exprs, T.getOpenLocation());
+  CalledSignatureHelp = true;
   Actions.CodeCompleteExpression(getCurScope(), PreferredType);
 };
 if (ThisVarDecl) {
@@ -2317,6 +2318,12 @@ Decl *Parser::ParseDeclarationAfterDecla
 }
 
 if (ParseExpressionList(Exprs, CommaLocs, ExprListCompleter)) {
+  if (ThisVarDecl && PP.isCodeCompletionReached() && !CalledSignatureHelp) 
{
+Actions.ProduceConstructorSignatureHelp(
+getCurScope(), ThisVarDecl->getType()->getCanonicalTypeInternal(),
+ThisDecl->getLocation(), Exprs, T.getOpenLocation());
+CalledSignatureHelp = true;
+  }
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 } else {

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=341824&r1=341823&r2=341824&view=diff
==
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Mon Sep 10 06:46:28 2018
@@ -1652,6 +1652,7 @@ Parser::ParsePostfixExpressionSuffix(Exp
   if (Tok.is(tok::code_completion)) {
 QualType PreferredType = Actions.ProduceCallSignatureHelp(
 getCurScope(), LHS.get(), None, PT.getOpenLocation());
+CalledSignatureHelp = true;
 Actions.CodeCompleteExpression(getCurScope(), PreferredType);
 cutOffParsing();
 return ExprError();
@@ -1662,9 +1663,19 @@ Parser::ParsePostfixExpressionSuffix(Exp
   if (ParseExpressionList(ArgExprs, CommaLocs, [&] {
 QualType PreferredType = Actions.ProduceCallSignatureHelp(
 getCurScope(), LHS.get(), ArgExprs, PT.getOpenLocation());
+CalledSignatureHelp = true;
 Actions.CodeCompleteExpression(getCurScope(), PreferredType);
   })) {
 (void)Actions.CorrectDelayedTyposInExpr(LHS);
+// If we got an error when parsing expression list, we don't call
+// the CodeCompleteCall handler inside the parser. So call it here
+// to make sure we get overload suggestions even when we are in the
+// middle of a parameter.
+if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
+  Actions.ProduceCallSignatureHelp(getCurScope(), LHS.get(),
+   ArgExprs, PT.getOpenLocation());
+  CalledSignatureHelp = true;
+}
 LHS = ExprError();
   } else if (LHS.isInvalid()) {

[clang-tools-extra] r341830 - [clangd] Add unittests for D51038

2018-09-10 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Sep 10 07:22:42 2018
New Revision: 341830

URL: http://llvm.org/viewvc/llvm-project?rev=341830&view=rev
Log:
[clangd] Add unittests for D51038

Reviewers: ilya-biryukov, ioeric, hokein

Reviewed By: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51039

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

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=341830&r1=341829&r2=341830&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon Sep 10 
07:22:42 2018
@@ -1917,6 +1917,56 @@ TEST(CompletionTest, DeprecatedResults)
AllOf(Named("TestClangc"), Deprecated(;
 }
 
+TEST(SignatureHelpTest, InsideArgument) {
+  {
+const auto Results = signatures(R"cpp(
+  void foo(int x);
+  void foo(int x, int y);
+  int main() { foo(1+^); }
+)cpp");
+EXPECT_THAT(
+Results.signatures,
+ElementsAre(Sig("foo(int x) -> void", {"int x"}),
+Sig("foo(int x, int y) -> void", {"int x", "int y"})));
+EXPECT_EQ(0, Results.activeParameter);
+  }
+  {
+const auto Results = signatures(R"cpp(
+  void foo(int x);
+  void foo(int x, int y);
+  int main() { foo(1^); }
+)cpp");
+EXPECT_THAT(
+Results.signatures,
+ElementsAre(Sig("foo(int x) -> void", {"int x"}),
+Sig("foo(int x, int y) -> void", {"int x", "int y"})));
+EXPECT_EQ(0, Results.activeParameter);
+  }
+  {
+const auto Results = signatures(R"cpp(
+  void foo(int x);
+  void foo(int x, int y);
+  int main() { foo(1^0); }
+)cpp");
+EXPECT_THAT(
+Results.signatures,
+ElementsAre(Sig("foo(int x) -> void", {"int x"}),
+Sig("foo(int x, int y) -> void", {"int x", "int y"})));
+EXPECT_EQ(0, Results.activeParameter);
+  }
+  {
+const auto Results = signatures(R"cpp(
+  void foo(int x);
+  void foo(int x, int y);
+  int bar(int x, int y);
+  int main() { bar(foo(2, 3^)); }
+)cpp");
+EXPECT_THAT(Results.signatures, ElementsAre(Sig("foo(int x, int y) -> 
void",
+{"int x", "int y"})));
+EXPECT_EQ(1, Results.activeParameter);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341949 - [CodeCompletion] Enable signature help when initializing class/struct/union members.

2018-09-11 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Sep 11 08:02:18 2018
New Revision: 341949

URL: http://llvm.org/viewvc/llvm-project?rev=341949&view=rev
Log:
[CodeCompletion] Enable signature help when initializing class/struct/union 
members.

Summary:
Factors out member decleration gathering and uses it in parsing to call 
signature
help. Doesn't support signature help for base class constructors, the code was 
too
coupled with diagnostic handling, but still can be factored out but just needs
more afford.

Reviewers: sammccall, ilya-biryukov, ioeric

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D51917

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeCompletion/ctor-initializer.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=341949&r1=341948&r2=341949&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Sep 11 08:02:18 2018
@@ -4568,6 +4568,11 @@ private:
   // of a ComparisonCategoryType enumerator.
   llvm::SmallBitVector FullyCheckedComparisonCategories;
 
+  ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl,
+ CXXScopeSpec &SS,
+ ParsedType TemplateTypeTy,
+ IdentifierInfo *MemberOrBase);
+
 public:
   /// Lookup the specified comparison category types in the standard
   ///   library, an check the VarDecls possibly returned by the operator<=>
@@ -10254,6 +10259,12 @@ public:
SourceLocation Loc,
ArrayRef Args,
SourceLocation OpenParLoc);
+  QualType ProduceCtorInitMemberSignatureHelp(Scope *S, Decl *ConstructorDecl,
+  CXXScopeSpec SS,
+  ParsedType TemplateTypeTy,
+  ArrayRef ArgExprs,
+  IdentifierInfo *II,
+  SourceLocation OpenParLoc);
   void CodeCompleteInitializer(Scope *S, Decl *D);
   void CodeCompleteReturn(Scope *S);
   void CodeCompleteAfterIf(Scope *S);
@@ -10794,7 +10805,6 @@ struct LateParsedTemplate {
   /// The template function declaration to be late parsed.
   Decl *D;
 };
-
 } // end namespace clang
 
 namespace llvm {

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=341949&r1=341948&r2=341949&view=diff
==
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Tue Sep 11 08:02:18 2018
@@ -3449,6 +3449,7 @@ MemInitResult Parser::ParseMemInitialize
   if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
 Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists);
 
+// FIXME: Add support for signature help inside initializer lists.
 ExprResult InitList = ParseBraceInitializer();
 if (InitList.isInvalid())
   return true;
@@ -3466,7 +3467,20 @@ MemInitResult Parser::ParseMemInitialize
 // Parse the optional expression-list.
 ExprVector ArgExprs;
 CommaLocsTy CommaLocs;
-if (Tok.isNot(tok::r_paren) && ParseExpressionList(ArgExprs, CommaLocs)) {
+if (Tok.isNot(tok::r_paren) &&
+ParseExpressionList(ArgExprs, CommaLocs, [&] {
+  QualType PreferredType = Actions.ProduceCtorInitMemberSignatureHelp(
+  getCurScope(), ConstructorDecl, SS, TemplateTypeTy, ArgExprs, II,
+  T.getOpenLocation());
+  CalledSignatureHelp = true;
+  Actions.CodeCompleteExpression(getCurScope(), PreferredType);
+})) {
+  if (PP.isCodeCompletionReached() && !CalledSignatureHelp) {
+Actions.ProduceCtorInitMemberSignatureHelp(
+getCurScope(), ConstructorDecl, SS, TemplateTypeTy, ArgExprs, II,
+T.getOpenLocation());
+CalledSignatureHelp = true;
+  }
   SkipUntil(tok::r_paren, StopAtSemi);
   return true;
 }

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=341949&r1=341948&r2=341949&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Sep 11 08:02:18 2018
@@ -4586,6 +4586,25 @@ QualType Sema::ProduceConstructorSignatu
   return ProduceSignatureHelp(*this, S, Results, 

[clang-tools-extra] r341950 - [clangd] Add unittests for D51917

2018-09-11 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Sep 11 08:12:10 2018
New Revision: 341950

URL: http://llvm.org/viewvc/llvm-project?rev=341950&view=rev
Log:
[clangd] Add unittests for D51917

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51924

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp

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=341950&r1=341949&r2=341950&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Tue Sep 11 
08:12:10 2018
@@ -1967,6 +1967,45 @@ TEST(SignatureHelpTest, InsideArgument)
   }
 }
 
+TEST(SignatureHelpTest, ConstructorInitializeFields) {
+  {
+const auto Results = signatures(R"cpp(
+  struct A {
+A(int);
+  };
+  struct B {
+B() : a_elem(^) {}
+A a_elem;
+  };
+)cpp");
+EXPECT_THAT(Results.signatures, UnorderedElementsAre(
+Sig("A(int)", {"int"}),
+Sig("A(A &&)", {"A &&"}),
+Sig("A(const A &)", {"const A &"})
+));
+  }
+  {
+const auto Results = signatures(R"cpp(
+  struct A {
+A(int);
+  };
+  struct C {
+C(int);
+C(A);
+  };
+  struct B {
+B() : c_elem(A(1^)) {}
+C c_elem;
+  };
+)cpp");
+EXPECT_THAT(Results.signatures, UnorderedElementsAre(
+Sig("A(int)", {"int"}),
+Sig("A(A &&)", {"A &&"}),
+Sig("A(const A &)", {"const A &"})
+));
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r344033 - [clangd] Mark colon as a safe character when percent-encoding.

2018-10-09 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Oct  9 03:29:54 2018
New Revision: 344033

URL: http://llvm.org/viewvc/llvm-project?rev=344033&view=rev
Log:
[clangd] Mark colon as a safe character when percent-encoding.

Summary: Also change output of percent-encoding to use upper-case letters.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D53016

Modified:
clang-tools-extra/trunk/clangd/URI.cpp
clang-tools-extra/trunk/unittests/clangd/URITests.cpp

Modified: clang-tools-extra/trunk/clangd/URI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/URI.cpp?rev=344033&r1=344032&r2=344033&view=diff
==
--- clang-tools-extra/trunk/clangd/URI.cpp (original)
+++ clang-tools-extra/trunk/clangd/URI.cpp Tue Oct  9 03:29:54 2018
@@ -91,6 +91,8 @@ bool shouldEscape(unsigned char C) {
   case '.':
   case '~':
   case '/': // '/' is only reserved when parsing.
+  // ':' is only reserved for relative URI paths, which clangd doesn't produce.
+  case ':':
 return false;
   }
   return true;
@@ -105,7 +107,7 @@ std::string percentEncode(llvm::StringRe
   llvm::raw_string_ostream OS(Result);
   for (unsigned char C : Content)
 if (shouldEscape(C))
-  OS << '%' << llvm::format_hex_no_prefix(C, 2);
+  OS << '%' << llvm::format_hex_no_prefix(C, 2, /*Upper = */true);
 else
   OS << C;
 

Modified: clang-tools-extra/trunk/unittests/clangd/URITests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/URITests.cpp?rev=344033&r1=344032&r2=344033&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/URITests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/URITests.cpp Tue Oct  9 03:29:54 
2018
@@ -44,8 +44,9 @@ URI parseOrDie(llvm::StringRef Uri) {
 
 TEST(PercentEncodingTest, Encode) {
   EXPECT_EQ(URI("x", /*Authority=*/"", "a/b/c").toString(), "x:a/b/c");
-  EXPECT_EQ(URI("x", /*Authority=*/"", "a!b;c~").toString(), "x:a%21b%3bc~");
+  EXPECT_EQ(URI("x", /*Authority=*/"", "a!b;c~").toString(), "x:a%21b%3Bc~");
   EXPECT_EQ(URI("x", /*Authority=*/"", "a123b").toString(), "x:a123b");
+  EXPECT_EQ(URI("x", /*Authority=*/"", "a:b;c").toString(), "x:a:b%3Bc");
 }
 
 TEST(PercentEncodingTest, Decode) {
@@ -56,6 +57,7 @@ TEST(PercentEncodingTest, Decode) {
   EXPECT_EQ(parseOrDie("s%2b://%3a/%3").body(), "/%3");
 
   EXPECT_EQ(parseOrDie("x:a%21b%3ac~").body(), "a!b:c~");
+  EXPECT_EQ(parseOrDie("x:a:b%3bc").body(), "a:b;c");
 }
 
 std::string resolveOrDie(const URI &U, llvm::StringRef HintPath = "") {
@@ -67,10 +69,10 @@ std::string resolveOrDie(const URI &U, l
 
 TEST(URITest, Create) {
 #ifdef _WIN32
-  EXPECT_THAT(createOrDie("c:\\x\\y\\z"), "file:///c%3a/x/y/z");
+  EXPECT_THAT(createOrDie("c:\\x\\y\\z"), "file:///c:/x/y/z");
 #else
   EXPECT_THAT(createOrDie("/x/y/z"), "file:///x/y/z");
-  EXPECT_THAT(createOrDie("/(x)/y/\\ z"), "file:///%28x%29/y/%5c%20z");
+  EXPECT_THAT(createOrDie("/(x)/y/\\ z"), "file:///%28x%29/y/%5C%20z");
 #endif
 }
 
@@ -138,6 +140,7 @@ TEST(URITest, ParseFailed) {
 TEST(URITest, Resolve) {
 #ifdef _WIN32
   EXPECT_THAT(resolveOrDie(parseOrDie("file:///c%3a/x/y/z")), "c:\\x\\y\\z");
+  EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:\\x\\y\\z");
 #else
   EXPECT_EQ(resolveOrDie(parseOrDie("file:/a/b/c")), "/a/b/c");
   EXPECT_EQ(resolveOrDie(parseOrDie("file://auth/a/b/c")), "/a/b/c");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r345029 - [clang] Fix a null pointer dereference.

2018-10-23 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Oct 23 06:49:37 2018
New Revision: 345029

URL: http://llvm.org/viewvc/llvm-project?rev=345029&view=rev
Log:
[clang] Fix a null pointer dereference.

Summary:
Sometimes expression inside switch statement can be invalid, for
example type might be incomplete. In those cases code were causing a null
pointer dereference. This patch fixes that.

Reviewers: sammccall, ioeric, hokein

Reviewed By: sammccall

Subscribers: arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D53561

Added:
cfe/trunk/test/Index/complete-switch.c
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=345029&r1=345028&r2=345029&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Oct 23 06:49:37 2018
@@ -4419,6 +4419,9 @@ void Sema::CodeCompleteCase(Scope *S) {
 return;
 
   SwitchStmt *Switch = getCurFunction()->SwitchStack.back().getPointer();
+  // Condition expression might be invalid, do not continue in this case.
+  if (!Switch->getCond())
+return;
   QualType type = Switch->getCond()->IgnoreImplicit()->getType();
   if (!type->isEnumeralType()) {
 CodeCompleteExpressionData Data(type);

Added: cfe/trunk/test/Index/complete-switch.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-switch.c?rev=345029&view=auto
==
--- cfe/trunk/test/Index/complete-switch.c (added)
+++ cfe/trunk/test/Index/complete-switch.c Tue Oct 23 06:49:37 2018
@@ -0,0 +1,10 @@
+void f() {
+  auto foo = bar;
+  switch(foo) {
+case x:
+  break;
+  }
+}
+
+// RUN: not %clang_cc1 -fsyntax-only -code-completion-at=%s:4:10 %s | 
FileCheck %s -allow-empty
+// CHECK-NOT: COMPLETION: foo


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r345152 - [clang] Introduce new completion context types

2018-10-24 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Oct 24 08:23:49 2018
New Revision: 345152

URL: http://llvm.org/viewvc/llvm-project?rev=345152&view=rev
Log:
[clang] Introduce new completion context types

Summary: New name suggestions were being used in places where existing names 
should have been used, this patch tries to fix some of those situations.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D53191

Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/tools/libclang/CIndexCodeCompletion.cpp

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=345152&r1=345151&r2=345152&view=diff
==
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Wed Oct 24 08:23:49 2018
@@ -272,11 +272,15 @@ public:
 CCC_Type,
 
 /// Code completion occurred where a new name is expected.
-CCC_Name,
+CCC_NewName,
 
-/// Code completion occurred where a new name is expected and a
-/// qualified name is permissible.
-CCC_PotentiallyQualifiedName,
+/// Code completion occurred where both a new name and an existing symbol 
is
+/// permissible.
+CCC_SymbolOrNewName,
+
+/// Code completion occurred where an existing name(such as type, function
+/// or variable) is expected.
+CCC_Symbol,
 
 /// Code completion occurred where an macro is being defined.
 CCC_MacroName,

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=345152&r1=345151&r2=345152&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Oct 24 08:23:49 2018
@@ -282,7 +282,7 @@ void ASTUnit::enableSourceFileDiagnostic
 
 /// Determine the set of code-completion contexts in which this
 /// declaration should be shown.
-static unsigned getDeclShowContexts(const NamedDecl *ND,
+static uint64_t getDeclShowContexts(const NamedDecl *ND,
 const LangOptions &LangOpts,
 bool &IsNestedNameSpecifier) {
   IsNestedNameSpecifier = false;
@@ -436,14 +436,15 @@ void ASTUnit::CacheCodeCompletionResults
   | (1LL << CodeCompletionContext::CCC_UnionTag)
   | (1LL << CodeCompletionContext::CCC_ClassOrStructTag)
   | (1LL << CodeCompletionContext::CCC_Type)
-  | (1LL << CodeCompletionContext::CCC_PotentiallyQualifiedName)
+  | (1LL << CodeCompletionContext::CCC_Symbol)
+  | (1LL << CodeCompletionContext::CCC_SymbolOrNewName)
   | (1LL << CodeCompletionContext::CCC_ParenthesizedExpression);
 
 if (isa(R.Declaration) ||
 isa(R.Declaration))
   NNSContexts |= (1LL << CodeCompletionContext::CCC_Namespace);
 
-if (unsigned RemainingContexts
+if (uint64_t RemainingContexts
 = NNSContexts & ~CachedResult.ShowInContexts) {
   // If there any contexts where this completion can be a
   // nested-name-specifier but isn't already an option, create a
@@ -1951,8 +1952,8 @@ static void CalculateHiddenNames(const C
   case CodeCompletionContext::CCC_ObjCPropertyAccess:
   case CodeCompletionContext::CCC_Namespace:
   case CodeCompletionContext::CCC_Type:
-  case CodeCompletionContext::CCC_Name:
-  case CodeCompletionContext::CCC_PotentiallyQualifiedName:
+  case CodeCompletionContext::CCC_Symbol:
+  case CodeCompletionContext::CCC_SymbolOrNewName:
   case CodeCompletionContext::CCC_ParenthesizedExpression:
   case CodeCompletionContext::CCC_ObjCInterfaceName:
 break;
@@ -1977,6 +1978,7 @@ static void CalculateHiddenNames(const C
   case CodeCompletionContext::CCC_ObjCClassMessage:
   case CodeCompletionContext::CCC_ObjCCategoryName:
   case CodeCompletionContext::CCC_IncludedFile:
+  case CodeCompletionContext::CCC_NewName:
 // We're looking for nothing, or we're looking for names that cannot
 // be hidden.
 return;

Modified: cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp?rev=345152&r1=345151&r2=345152&view=diff
==
--- cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp (original)
+++ cfe/trunk/lib/Sema/CodeCompleteConsumer.cpp Wed Oct 24 08:23:49 2018
@@ -49,6 +49,8 @@ bool CodeCompletionContext::wantConstruc
   case CCC_Expression:
   case CCC_ObjCMessageReceiver:
   case CCC_ParenthesizedExpression:
+  

[clang-tools-extra] r345153 - [clangd] Do not query index for new name completions.

2018-10-24 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Oct 24 08:24:29 2018
New Revision: 345153

URL: http://llvm.org/viewvc/llvm-project?rev=345153&view=rev
Log:
[clangd] Do not query index for new name completions.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D53192

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
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=345153&r1=345152&r2=345153&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Oct 24 08:24:29 2018
@@ -625,13 +625,12 @@ bool contextAllowsIndex(enum CodeComplet
   case CodeCompletionContext::CCC_ObjCProtocolName:
   case CodeCompletionContext::CCC_Namespace:
   case CodeCompletionContext::CCC_Type:
-  case CodeCompletionContext::CCC_Name: // FIXME: why does ns::^ give this?
-  case CodeCompletionContext::CCC_PotentiallyQualifiedName:
   case CodeCompletionContext::CCC_ParenthesizedExpression:
   case CodeCompletionContext::CCC_ObjCInterfaceName:
   case CodeCompletionContext::CCC_ObjCCategoryName:
+  case CodeCompletionContext::CCC_Symbol:
+  case CodeCompletionContext::CCC_SymbolOrNewName:
 return true;
-  case CodeCompletionContext::CCC_Other: // Be conservative.
   case CodeCompletionContext::CCC_OtherWithMacros:
   case CodeCompletionContext::CCC_DotMemberAccess:
   case CodeCompletionContext::CCC_ArrowMemberAccess:
@@ -640,13 +639,16 @@ bool contextAllowsIndex(enum CodeComplet
   case CodeCompletionContext::CCC_MacroNameUse:
   case CodeCompletionContext::CCC_PreprocessorExpression:
   case CodeCompletionContext::CCC_PreprocessorDirective:
-  case CodeCompletionContext::CCC_NaturalLanguage:
   case CodeCompletionContext::CCC_SelectorName:
   case CodeCompletionContext::CCC_TypeQualifiers:
   case CodeCompletionContext::CCC_ObjCInstanceMessage:
   case CodeCompletionContext::CCC_ObjCClassMessage:
   case CodeCompletionContext::CCC_IncludedFile:
+  // FIXME: Provide identifier based completions for the following contexts:
+  case CodeCompletionContext::CCC_Other: // Be conservative.
+  case CodeCompletionContext::CCC_NaturalLanguage:
   case CodeCompletionContext::CCC_Recovery:
+  case CodeCompletionContext::CCC_NewName:
 return false;
   }
   llvm_unreachable("unknown code completion context");

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=345153&r1=345152&r2=345153&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Wed Oct 24 
08:24:29 2018
@@ -551,7 +551,7 @@ const Symbol *SymbolCollector::addDeclar
   // We use the primary template, as clang does during code completion.
   CodeCompletionResult SymbolCompletion(&getTemplateOrThis(ND), 0);
   const auto *CCS = SymbolCompletion.CreateCodeCompletionString(
-  *ASTCtx, *PP, CodeCompletionContext::CCC_Name, *CompletionAllocator,
+  *ASTCtx, *PP, CodeCompletionContext::CCC_Symbol, *CompletionAllocator,
   *CompletionTUInfo,
   /*IncludeBriefComments*/ false);
   std::string Signature;

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=345153&r1=345152&r2=345153&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Oct 24 
08:24:29 2018
@@ -2178,6 +2178,15 @@ TEST(CompletionTest, NoQualifierIfShadow
AllOf(Qualifier("nx::"), 
Named("Clangd2";
 }
 
+TEST(CompletionTest, NoCompletionsForNewNames) {
+  clangd::CodeCompleteOptions Opts;
+  Opts.AllScopes = true;
+  auto Results = completions(R"cpp(
+  void f() { int n^ }
+)cpp",
+ {cls("naber"), cls("nx::naber")}, Opts);
+  EXPECT_THAT(Results.Completions, UnorderedElementsAre());
+}
 } // namespace
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r345590 - [clangd] Use thread pool for background indexing.

2018-10-30 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Oct 30 05:13:27 2018
New Revision: 345590

URL: http://llvm.org/viewvc/llvm-project?rev=345590&view=rev
Log:
[clangd] Use thread pool for background indexing.

Reviewers: sammccall, ioeric

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, jfb, cfe-commits

Differential Revision: https://reviews.llvm.org/D53651

Modified:
clang-tools-extra/trunk/clangd/Threading.cpp
clang-tools-extra/trunk/clangd/Threading.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h

Modified: clang-tools-extra/trunk/clangd/Threading.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.cpp?rev=345590&r1=345589&r2=345590&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.cpp (original)
+++ clang-tools-extra/trunk/clangd/Threading.cpp Tue Oct 30 05:13:27 2018
@@ -1,9 +1,13 @@
 #include "Threading.h"
 #include "Trace.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/Config/config.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Threading.h"
 #include 
+#ifdef HAVE_PTHREAD_H
+#include 
+#endif
 
 using namespace llvm;
 namespace clang {
@@ -97,5 +101,15 @@ void wait(std::unique_lock &
   CV.wait_until(Lock, D.time());
 }
 
+void setThreadPriority(std::thread &T, ThreadPriority Priority) {
+#ifdef HAVE_PTHREAD_H
+  sched_param priority;
+  priority.sched_priority = 0;
+  pthread_setschedparam(
+  T.native_handle(),
+  Priority == ThreadPriority::Low ? SCHED_IDLE : SCHED_OTHER, &priority);
+#endif
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/Threading.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.h?rev=345590&r1=345589&r2=345590&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.h (original)
+++ clang-tools-extra/trunk/clangd/Threading.h Tue Oct 30 05:13:27 2018
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 namespace clang {
@@ -115,6 +116,13 @@ private:
   mutable std::condition_variable TasksReachedZero;
   std::size_t InFlightTasks = 0;
 };
+
+enum class ThreadPriority {
+  Low = 0,
+  Normal = 1,
+};
+void setThreadPriority(std::thread &T, ThreadPriority Priority);
+
 } // namespace clangd
 } // namespace clang
 #endif

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=345590&r1=345589&r2=345590&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Tue Oct 30 05:13:27 2018
@@ -11,6 +11,7 @@
 #include "ClangdUnit.h"
 #include "Compiler.h"
 #include "Logger.h"
+#include "Threading.h"
 #include "Trace.h"
 #include "index/IndexAction.h"
 #include "index/MemIndex.h"
@@ -25,14 +26,26 @@ namespace clangd {
 BackgroundIndex::BackgroundIndex(Context BackgroundContext,
  StringRef ResourceDir,
  const FileSystemProvider &FSProvider,
- ArrayRef URISchemes)
+ ArrayRef URISchemes,
+ size_t ThreadPoolSize)
 : SwapIndex(make_unique()), ResourceDir(ResourceDir),
   FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)),
-  URISchemes(URISchemes), Thread([this] { run(); }) {}
+  URISchemes(URISchemes) {
+  assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
+  while (ThreadPoolSize--) {
+ThreadPool.emplace_back([this] { run(); });
+// Set priority to low, since background indexing is a long running task we
+// do not want to eat up cpu when there are any other high priority 
threads.
+// FIXME: In the future we might want a more general way of handling this 
to
+// support a tasks with various priorities.
+setThreadPriority(ThreadPool.back(), ThreadPriority::Low);
+  }
+}
 
 BackgroundIndex::~BackgroundIndex() {
   stop();
-  Thread.join();
+  for (auto &Thread : ThreadPool)
+Thread.join();
 }
 
 void BackgroundIndex::stop() {
@@ -44,7 +57,7 @@ void BackgroundIndex::stop() {
 }
 
 void BackgroundIndex::run() {
-  WithContext Background(std::move(BackgroundContext));
+  WithContext Background(BackgroundContext.clone());
   while (true) {
 Optional Task;
 {

Modified: clang-tools-extra/trunk/clangd/index/Background.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.h?rev=345590&r1=345589&r2=345590&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.h (original)
+

[clang-tools-extra] r351052 - [clangd] Fix a reference invalidation

2019-01-14 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Jan 14 03:24:07 2019
New Revision: 351052

URL: http://llvm.org/viewvc/llvm-project?rev=351052&view=rev
Log:
[clangd] Fix a reference invalidation

Summary: Fix for the breakage in 
http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/52811/consoleFull#-42777206a1ca8a51-895e-46c6-af87-ce24fa4cd561

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D56656

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=351052&r1=351051&r2=351052&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Mon Jan 14 03:24:07 2019
@@ -476,29 +476,33 @@ BackgroundIndex::loadShard(const tooling
   // Dependencies of this TU, paired with the information about whether they
   // need to be re-indexed or not.
   std::vector Dependencies;
+  std::queue ToVisit;
   std::string AbsolutePath = getAbsolutePath(Cmd).str();
   // Up until we load the shard related to a dependency it needs to be
   // re-indexed.
-  Dependencies.emplace_back(AbsolutePath, true);
+  ToVisit.emplace(AbsolutePath, true);
   InQueue.insert(AbsolutePath);
   // Goes over each dependency.
-  for (size_t CurrentDependency = 0; CurrentDependency < Dependencies.size();
-   CurrentDependency++) {
-llvm::StringRef CurDependencyPath = Dependencies[CurrentDependency].Path;
+  while (!ToVisit.empty()) {
+Dependencies.push_back(std::move(ToVisit.front()));
+// Dependencies is not modified during the rest of the loop, so it is safe
+// to keep the reference.
+auto &CurDependency = Dependencies.back();
+ToVisit.pop();
 // If we have already seen this shard before(either loaded or failed) don't
 // re-try again. Since the information in the shard won't change from one 
TU
 // to another.
-if (!LoadedShards.try_emplace(CurDependencyPath).second) {
+if (!LoadedShards.try_emplace(CurDependency.Path).second) {
   // If the dependency needs to be re-indexed, first occurence would 
already
   // have detected that, so we don't need to issue it again.
-  Dependencies[CurrentDependency].NeedsReIndexing = false;
+  CurDependency.NeedsReIndexing = false;
   continue;
 }
 
-auto Shard = IndexStorage->loadShard(CurDependencyPath);
+auto Shard = IndexStorage->loadShard(CurDependency.Path);
 if (!Shard || !Shard->Sources) {
   // File will be returned as requiring re-indexing to caller.
-  vlog("Failed to load shard: {0}", CurDependencyPath);
+  vlog("Failed to load shard: {0}", CurDependency.Path);
   continue;
 }
 // These are the edges in the include graph for current dependency.
@@ -506,34 +510,34 @@ BackgroundIndex::loadShard(const tooling
   auto U = URI::parse(I.getKey());
   if (!U)
 continue;
-  auto AbsolutePath = URI::resolve(*U, CurDependencyPath);
+  auto AbsolutePath = URI::resolve(*U, CurDependency.Path);
   if (!AbsolutePath)
 continue;
   // Add file as dependency if haven't seen before.
   if (InQueue.try_emplace(*AbsolutePath).second)
-Dependencies.emplace_back(*AbsolutePath, true);
+ToVisit.emplace(*AbsolutePath, true);
   // The node contains symbol information only for current file, the rest 
is
   // just edges.
-  if (*AbsolutePath != CurDependencyPath)
+  if (*AbsolutePath != CurDependency.Path)
 continue;
 
   // We found source file info for current dependency.
   assert(I.getValue().Digest != FileDigest{{0}} && "Digest is empty?");
   ShardInfo SI;
-  SI.AbsolutePath = CurDependencyPath;
+  SI.AbsolutePath = CurDependency.Path;
   SI.Shard = std::move(Shard);
   SI.Digest = I.getValue().Digest;
   IntermediateSymbols.push_back(std::move(SI));
   // Check if the source needs re-indexing.
   // Get the digest, skip it if file doesn't exist.
-  auto Buf = FS->getBufferForFile(CurDependencyPath);
+  auto Buf = FS->getBufferForFile(CurDependency.Path);
   if (!Buf) {
-elog("Couldn't get buffer for file: {0}: {1}", CurDependencyPath,
+elog("Couldn't get buffer for file: {0}: {1}", CurDependency.Path,
  Buf.getError().message());
 continue;
   }
   // If digests match then dependency doesn't need re-indexing.
-  Dependencies[CurrentDependency].NeedsReIndexing =
+  CurDependency.NeedsReIndexing =
   digest(Buf->get()->getBuffer()) != I.getValue().Digest;
 }
   }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r351170 - [clangd] Fix updated file detection logic in indexing

2019-01-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Jan 15 01:03:33 2019
New Revision: 351170

URL: http://llvm.org/viewvc/llvm-project?rev=351170&view=rev
Log:
[clangd] Fix updated file detection logic in indexing

Summary:
Files without any symbols were never marked as updated during indexing, which 
resulted in failure while writing shards for these files.

This patch fixes the logic to mark files that are seen for the first time but 
don't contain any symbols as updated.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D56592

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=351170&r1=351169&r2=351170&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Tue Jan 15 01:03:33 2019
@@ -91,12 +91,10 @@ IncludeGraph getSubGraph(const URI &U, c
 
 // Creates a filter to not collect index results from files with unchanged
 // digests.
-// \p FileDigests contains file digests for the current indexed files, and all
-// changed files will be added to \p FilesToUpdate.
+// \p FileDigests contains file digests for the current indexed files.
 decltype(SymbolCollector::Options::FileFilter)
-createFileFilter(const llvm::StringMap &FileDigests,
- llvm::StringMap &FilesToUpdate) {
-  return [&FileDigests, &FilesToUpdate](const SourceManager &SM, FileID FID) {
+createFileFilter(const llvm::StringMap &FileDigests) {
+  return [&FileDigests](const SourceManager &SM, FileID FID) {
 const auto *F = SM.getFileEntryForID(FID);
 if (!F)
   return false; // Skip invalid files.
@@ -109,8 +107,6 @@ createFileFilter(const llvm::StringMapsecond == Digest)
   return false; // Skip files that haven't changed.
-
-FilesToUpdate[*AbsPath] = *Digest;
 return true;
   };
 }
@@ -264,22 +260,34 @@ void BackgroundIndex::enqueueTask(Task T
   QueueCV.notify_all();
 }
 
-/// Given index results from a TU, only update files in \p FilesToUpdate.
+/// Given index results from a TU, only update symbols coming from files that
+/// are different or missing from than \p DigestsSnapshot. Also stores new 
index
+/// information on IndexStorage.
 void BackgroundIndex::update(llvm::StringRef MainFile, IndexFileIn Index,
- const llvm::StringMap &FilesToUpdate,
+ const llvm::StringMap 
&DigestsSnapshot,
  BackgroundIndexStorage *IndexStorage) {
   // Partition symbols/references into files.
   struct File {
 llvm::DenseSet Symbols;
 llvm::DenseSet Refs;
+FileDigest Digest;
   };
   llvm::StringMap Files;
   URIToFileCache URICache(MainFile);
+  for (const auto &IndexIt : *Index.Sources) {
+const auto &IGN = IndexIt.getValue();
+const auto AbsPath = URICache.resolve(IGN.URI);
+const auto DigestIt = DigestsSnapshot.find(AbsPath);
+// File has different contents.
+if (DigestIt == DigestsSnapshot.end() || DigestIt->getValue() != 
IGN.Digest)
+  Files.try_emplace(AbsPath).first->getValue().Digest = IGN.Digest;
+  }
   for (const auto &Sym : *Index.Symbols) {
 if (Sym.CanonicalDeclaration) {
   auto DeclPath = URICache.resolve(Sym.CanonicalDeclaration.FileURI);
-  if (FilesToUpdate.count(DeclPath) != 0)
-Files[DeclPath].Symbols.insert(&Sym);
+  const auto FileIt = Files.find(DeclPath);
+  if (FileIt != Files.end())
+FileIt->second.Symbols.insert(&Sym);
 }
 // For symbols with different declaration and definition locations, we 
store
 // the full symbol in both the header file and the implementation file, so
@@ -288,16 +296,18 @@ void BackgroundIndex::update(llvm::Strin
 if (Sym.Definition &&
 Sym.Definition.FileURI != Sym.CanonicalDeclaration.FileURI) {
   auto DefPath = URICache.resolve(Sym.Definition.FileURI);
-  if (FilesToUpdate.count(DefPath) != 0)
-Files[DefPath].Symbols.insert(&Sym);
+  const auto FileIt = Files.find(DefPath);
+  if (FileIt != Files.end())
+FileIt->second.Symbols.insert(&Sym);
 }
   }
   llvm::DenseMap RefToIDs;
   for (const auto &SymRefs : *Index.Refs) {
 for (const auto &R : SymRefs.second) {
   auto Path = URICache.resolve(R.Location.FileURI);
-  if (FilesToUpdate.count(Path) != 0) {
-auto &F = Files[Path];
+  const auto FileIt = Files.find(Path);
+  if (FileIt != Files.end()) {
+auto &F = FileIt->getValue();
 RefToIDs[&R] = SymRefs.first;
 F.Refs.insert(&R);
   }
@@ -305,18 +315,14 @@ vo

r351531 - [tooling] Add a new argument adjuster for deleting plugin related command line args

2019-01-18 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Jan 18 01:00:31 2019
New Revision: 351531

URL: http://llvm.org/viewvc/llvm-project?rev=351531&view=rev
Log:
[tooling] Add a new argument adjuster for deleting plugin related command line 
args

Summary:
Currently both clangd and clang-tidy makes use of this mechanism so
putting it into tooling so that all tools can make use of it.

Reviewers: ilya-biryukov, sammccall

Subscribers: ioeric, cfe-commits

Differential Revision: https://reviews.llvm.org/D56856

Modified:
cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
cfe/trunk/unittests/Tooling/ToolingTest.cpp

Modified: cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h?rev=351531&r1=351530&r2=351531&view=diff
==
--- cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h (original)
+++ cfe/trunk/include/clang/Tooling/ArgumentsAdjusters.h Fri Jan 18 01:00:31 
2019
@@ -61,6 +61,10 @@ ArgumentsAdjuster getInsertArgumentAdjus
 const char *Extra,
 ArgumentInsertPosition Pos = ArgumentInsertPosition::END);
 
+/// Gets an argument adjuster which strips plugin related command line
+/// arguments.
+ArgumentsAdjuster getStripPluginsAdjuster();
+
 /// Gets an argument adjuster which adjusts the arguments in sequence
 /// with the \p First adjuster and then with the \p Second one.
 ArgumentsAdjuster combineAdjusters(ArgumentsAdjuster First,

Modified: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp?rev=351531&r1=351530&r2=351531&view=diff
==
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp (original)
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp Fri Jan 18 01:00:31 2019
@@ -108,5 +108,27 @@ ArgumentsAdjuster combineAdjusters(Argum
   };
 }
 
+ArgumentsAdjuster getStripPluginsAdjuster() {
+  return [](const CommandLineArguments &Args, StringRef /*unused*/) {
+CommandLineArguments AdjustedArgs;
+for (size_t I = 0, E = Args.size(); I != E; I++) {
+  // According to https://clang.llvm.org/docs/ClangPlugins.html
+  // plugin arguments are in the form:
+  // -Xclang {-load, -plugin, -plugin-arg-, -add-plugin}
+  // -Xclang 
+  if (I + 4 < E && Args[I] == "-Xclang" &&
+  (Args[I + 1] == "-load" || Args[I + 1] == "-plugin" ||
+   llvm::StringRef(Args[I + 1]).startswith("-plugin-arg-") ||
+   Args[I + 1] == "-add-plugin") &&
+  Args[I + 2] == "-Xclang") {
+I += 3;
+continue;
+  }
+  AdjustedArgs.push_back(Args[I]);
+}
+return AdjustedArgs;
+  };
+}
+
 } // end namespace tooling
 } // end namespace clang

Modified: cfe/trunk/unittests/Tooling/ToolingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ToolingTest.cpp?rev=351531&r1=351530&r2=351531&view=diff
==
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp Fri Jan 18 01:00:31 2019
@@ -450,6 +450,37 @@ TEST(ClangToolTest, StripDependencyFileA
   EXPECT_TRUE(HasFlag("-w"));
 }
 
+// Check getClangStripPluginsAdjuster strips plugin related args.
+TEST(ClangToolTest, StripPluginsAdjuster) {
+  FixedCompilationDatabase Compilations(
+  "/", {"-Xclang", "-add-plugin", "-Xclang", "random-plugin"});
+
+  ClangTool Tool(Compilations, std::vector(1, "/a.cc"));
+  Tool.mapVirtualFile("/a.cc", "void a() {}");
+
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+
+  CommandLineArguments FinalArgs;
+  ArgumentsAdjuster CheckFlagsAdjuster =
+  [&FinalArgs](const CommandLineArguments &Args, StringRef /*unused*/) {
+FinalArgs = Args;
+return Args;
+  };
+  Tool.clearArgumentsAdjusters();
+  Tool.appendArgumentsAdjuster(getStripPluginsAdjuster());
+  Tool.appendArgumentsAdjuster(CheckFlagsAdjuster);
+  Tool.run(Action.get());
+
+  auto HasFlag = [&FinalArgs](const std::string &Flag) {
+return std::find(FinalArgs.begin(), FinalArgs.end(), Flag) !=
+   FinalArgs.end();
+  };
+  EXPECT_FALSE(HasFlag("-Xclang"));
+  EXPECT_FALSE(HasFlag("-add-plugin"));
+  EXPECT_FALSE(HasFlag("-random-plugin"));
+}
+
 namespace {
 /// Find a target name such that looking for it in TargetRegistry by that name
 /// returns the same target. We expect that there is at least one target


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r351738 - [clang-tidy] Use getStripPluginsAdjuster

2019-01-21 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Jan 21 02:10:18 2019
New Revision: 351738

URL: http://llvm.org/viewvc/llvm-project?rev=351738&view=rev
Log:
[clang-tidy] Use getStripPluginsAdjuster

Summary: See rC351531 for the introduction of getStripPluginsAdjuster.

Reviewers: alexfh

Subscribers: xazax.hun, cfe-commits

Differential Revision: https://reviews.llvm.org/D56902

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=351738&r1=351737&r2=351738&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Mon Jan 21 02:10:18 2019
@@ -528,24 +528,8 @@ runClangTidy(clang::tidy::ClangTidyConte
 return AdjustedArgs;
   };
 
-  // Remove plugins arguments.
-  ArgumentsAdjuster PluginArgumentsRemover =
-  [](const CommandLineArguments &Args, StringRef Filename) {
-CommandLineArguments AdjustedArgs;
-for (size_t I = 0, E = Args.size(); I < E; ++I) {
-  if (I + 4 < Args.size() && Args[I] == "-Xclang" &&
-  (Args[I + 1] == "-load" || Args[I + 1] == "-add-plugin" ||
-   StringRef(Args[I + 1]).startswith("-plugin-arg-")) &&
-  Args[I + 2] == "-Xclang") {
-I += 3;
-  } else
-AdjustedArgs.push_back(Args[I]);
-}
-return AdjustedArgs;
-  };
-
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
-  Tool.appendArgumentsAdjuster(PluginArgumentsRemover);
+  Tool.appendArgumentsAdjuster(getStripPluginsAdjuster());
   Context.setEnableProfiling(EnableCheckProfile);
   Context.setProfileStoragePrefix(StoreCheckProfile);
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r351788 - [clangd] Filter out plugin related flags and move all commandline manipulations into OverlayCDB.

2019-01-22 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Jan 22 01:10:20 2019
New Revision: 351788

URL: http://llvm.org/viewvc/llvm-project?rev=351788&view=rev
Log:
[clangd] Filter out plugin related flags and move all commandline manipulations 
into OverlayCDB.

Summary:
Some projects make use of clang plugins when building, but clangd is
not aware of those plugins therefore can't work with the same compile command
arguments.

There were multiple places clangd performed commandline manipulations,
 this one also moves them all into OverlayCDB.

Reviewers: ilya-biryukov

Subscribers: klimek, sammccall, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D56841

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=351788&r1=351787&r2=351788&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Jan 22 01:10:20 2019
@@ -289,7 +289,8 @@ void ClangdLSPServer::onInitialize(const
   if (UseDirBasedCDB)
 BaseCDB = llvm::make_unique(
 CompileCommandsDir);
-  CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags);
+  CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
+  ClangdServerOpts.ResourceDir);
   Server.emplace(*CDB, FSProvider, static_cast(*this),
  ClangdServerOpts);
   applyConfiguration(Params.initializationOptions.ConfigSettings);

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=351788&r1=351787&r2=351788&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Jan 22 01:10:20 2019
@@ -37,11 +37,6 @@ namespace clang {
 namespace clangd {
 namespace {
 
-std::string getStandardResourceDir() {
-  static int Dummy; // Just an address in this process.
-  return CompilerInvocation::GetResourcesPath("clangd", (void *)&Dummy);
-}
-
 class RefactoringResultCollector final
 : public tooling::RefactoringResultConsumer {
 public:
@@ -107,8 +102,6 @@ ClangdServer::ClangdServer(const GlobalC
DiagnosticsConsumer &DiagConsumer,
const Options &Opts)
 : CDB(CDB), FSProvider(FSProvider),
-  ResourceDir(Opts.ResourceDir ? *Opts.ResourceDir
-   : getStandardResourceDir()),
   DynamicIdx(Opts.BuildDynamicSymbolIndex
  ? new FileIndex(Opts.HeavyweightDynamicSymbolIndex)
  : nullptr),
@@ -136,7 +129,7 @@ ClangdServer::ClangdServer(const GlobalC
 AddIndex(Opts.StaticIndex);
   if (Opts.BackgroundIndex) {
 BackgroundIdx = llvm::make_unique(
-Context::current().clone(), ResourceDir, FSProvider, CDB,
+Context::current().clone(), FSProvider, CDB,
 BackgroundIndexStorage::createDiskBackedStorageFactory(),
 Opts.BackgroundIndexRebuildPeriodMs);
 AddIndex(BackgroundIdx.get());
@@ -461,10 +454,6 @@ tooling::CompileCommand ClangdServer::ge
   llvm::Optional C = CDB.getCompileCommand(File);
   if (!C) // FIXME: Suppress diagnostics? Let the user know?
 C = CDB.getFallbackCommand(File);
-
-  // Inject the resource dir.
-  // FIXME: Don't overwrite it if it's already there.
-  C->CommandLine.push_back("-resource-dir=" + ResourceDir);
   return std::move(*C);
 }
 

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=351788&r1=351787&r2=351788&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Tue Jan 22 
01:10:20 2019
@@ -8,12 +8,36 @@
 
 #include "GlobalCompilationDatabase.h"
 #include "Logger.h"
+#include "clang/Frontend/CompilerInvocation.h"
+#include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/FileS

[clang-tools-extra] r351793 - [clangd] NFC: Use buildCompilerInvocation in CodeComplete

2019-01-22 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Jan 22 01:58:53 2019
New Revision: 351793

URL: http://llvm.org/viewvc/llvm-project?rev=351793&view=rev
Log:
[clangd] NFC: Use buildCompilerInvocation in CodeComplete

Reviewers: ilya-biryukov, sammccall

Reviewed By: sammccall

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D56860

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/Compiler.cpp
clang-tools-extra/trunk/clangd/Compiler.h

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=351793&r1=351792&r2=351793&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Jan 22 01:58:53 2019
@@ -418,34 +418,6 @@ ParsedAST::ParsedAST(std::shared_ptrAction);
 }
 
-std::unique_ptr
-buildCompilerInvocation(const ParseInputs &Inputs) {
-  std::vector ArgStrs;
-  for (const auto &S : Inputs.CompileCommand.CommandLine)
-ArgStrs.push_back(S.c_str());
-
-  if (Inputs.FS->setCurrentWorkingDirectory(Inputs.CompileCommand.Directory)) {
-log("Couldn't set working directory when creating compiler invocation.");
-// We proceed anyway, our lit-tests rely on results for non-existing 
working
-// dirs.
-  }
-
-  // FIXME(ibiryukov): store diagnostics from CommandLine when we start
-  // reporting them.
-  IgnoreDiagnostics IgnoreDiagnostics;
-  llvm::IntrusiveRefCntPtr CommandLineDiagsEngine =
-  CompilerInstance::createDiagnostics(new DiagnosticOptions,
-  &IgnoreDiagnostics, false);
-  std::unique_ptr CI = createInvocationFromCommandLine(
-  ArgStrs, CommandLineDiagsEngine, Inputs.FS);
-  if (!CI)
-return nullptr;
-  // createInvocationFromCommandLine sets DisableFree.
-  CI->getFrontendOpts().DisableFree = false;
-  CI->getLangOpts()->CommentOpts.ParseAllComments = true;
-  return CI;
-}
-
 std::shared_ptr
 buildPreamble(PathRef FileName, CompilerInvocation &CI,
   std::shared_ptr OldPreamble,

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=351793&r1=351792&r2=351793&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.h Tue Jan 22 01:58:53 2019
@@ -9,7 +9,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H
 
-#include "../clang-tidy/ClangTidyOptions.h"
+#include "Compiler.h"
 #include "Diagnostics.h"
 #include "FS.h"
 #include "Function.h"
@@ -60,14 +60,6 @@ struct PreambleData {
   std::unique_ptr StatCache;
 };
 
-/// Information required to run clang, e.g. to parse AST or do code completion.
-struct ParseInputs {
-  tooling::CompileCommand CompileCommand;
-  IntrusiveRefCntPtr FS;
-  std::string Contents;
-  tidy::ClangTidyOptions ClangTidyOpts;
-};
-
 /// Stores and provides access to parsed AST.
 class ParsedAST {
 public:
@@ -137,10 +129,6 @@ private:
 using PreambleParsedCallback =
 std::function)>;
 
-/// Builds compiler invocation that could be used to build AST or preamble.
-std::unique_ptr
-buildCompilerInvocation(const ParseInputs &Inputs);
-
 /// Rebuild the preamble for the new inputs unless the old one can be reused.
 /// If \p OldPreamble can be reused, it is returned unchanged.
 /// If \p OldPreamble is null, always builds the preamble.

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=351793&r1=351792&r2=351793&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Jan 22 01:58:53 2019
@@ -1016,33 +1016,17 @@ bool semaCodeComplete(std::unique_ptr ArgStrs;
-  for (const auto &S : Input.Command.CommandLine)
-ArgStrs.push_back(S.c_str());
-
-  if (Input.VFS->setCurrentWorkingDirectory(Input.Command.Directory)) {
-log("Couldn't set working directory");
-// We run parsing anyway, our lit-tests rely on results for non-existing
-// working dirs.
-  }
-
   llvm::IntrusiveRefCntPtr VFS = Input.VFS;
   if (Input.Preamble && Input.Preamble->StatCache)
 VFS = Input.Preamble->StatCache->getConsumingFS(std::move(VFS));
-  IgnoreDiagnostics DummyDiagsConsumer;
-  auto CI = createInvocationFromCommandLine(
-  ArgStrs,
-  CompilerInstance::createDiagnostics(new DiagnosticOptions,
-  &DummyDiagsConsumer, fals

[clang-tools-extra] r352481 - [clangd] Make USRs for macros to be position independent

2019-01-29 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Jan 29 03:19:15 2019
New Revision: 352481

URL: http://llvm.org/viewvc/llvm-project?rev=352481&view=rev
Log:
[clangd] Make USRs for macros to be position independent

Summary:
USRs for macros were not cannonical due to usage of cursor location
instead of definition location.

Reviewers: jkorous

Subscribers: ilya-biryukov, ioeric, MaskRay, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D57228

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=352481&r1=352480&r2=352481&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Jan 29 03:19:15 2019
@@ -794,7 +794,8 @@ std::vector getSymbolInfo
 SymbolDetails NewMacro;
 NewMacro.name = Macro.Name;
 llvm::SmallString<32> USR;
-if (!index::generateUSRForMacro(NewMacro.name, Loc, SM, USR)) {
+if (!index::generateUSRForMacro(NewMacro.name,
+Macro.Info->getDefinitionLoc(), SM, USR)) {
   NewMacro.USR = USR.str();
   NewMacro.ID = SymbolID(NewMacro.USR);
 }

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp?rev=352481&r1=352480&r2=352481&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp Tue Jan 29 
03:19:15 2019
@@ -149,7 +149,13 @@ TEST(SymbolInfoTests, All) {
   #define MACRO 5\nint i = MAC^RO;
 )cpp",
   {CreateExpectedSymbolDetails("MACRO", "",
-   "c:TestTU.cpp@55@macro@MACRO")}},
+   "c:TestTU.cpp@38@macro@MACRO")}},
+  {
+  R"cpp( // Macro reference
+  #define MACRO 5\nint i = MACRO^;
+)cpp",
+  {CreateExpectedSymbolDetails("MACRO", "",
+   "c:TestTU.cpp@38@macro@MACRO")}},
   {
   R"cpp( // Multiple symbols returned - using overloaded function 
name
   void foo() {}


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r345729 - Delete dependency on config.h

2018-10-31 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Oct 31 08:37:09 2018
New Revision: 345729

URL: http://llvm.org/viewvc/llvm-project?rev=345729&view=rev
Log:
Delete dependency on config.h

Summary:
Since llvm/Config/config.h is not available on standalone builds,
use __USE_POSIX instead of HAVE_PTHREAD_H and get rid of the include.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: lebedev.ri, krytarowski, ilya-biryukov, ioeric, jkorous, arphaman, 
jfb, cfe-commits

Differential Revision: https://reviews.llvm.org/D53935

Modified:
clang-tools-extra/trunk/clangd/Threading.cpp

Modified: clang-tools-extra/trunk/clangd/Threading.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.cpp?rev=345729&r1=345728&r2=345729&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.cpp (original)
+++ clang-tools-extra/trunk/clangd/Threading.cpp Wed Oct 31 08:37:09 2018
@@ -1,11 +1,10 @@
 #include "Threading.h"
 #include "Trace.h"
 #include "llvm/ADT/ScopeExit.h"
-#include "llvm/Config/config.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Threading.h"
 #include 
-#ifdef HAVE_PTHREAD_H
+#ifdef __USE_POSIX
 #include 
 #endif
 
@@ -102,7 +101,7 @@ void wait(std::unique_lock &
 }
 
 void setThreadPriority(std::thread &T, ThreadPriority Priority) {
-#if defined(HAVE_PTHREAD_H) && defined(__linux__)
+#ifdef __linux__
   sched_param priority;
   priority.sched_priority = 0;
   pthread_setschedparam(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r345844 - [clang] Improve ctor initializer completions.

2018-11-01 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov  1 08:54:18 2018
New Revision: 345844

URL: http://llvm.org/viewvc/llvm-project?rev=345844&view=rev
Log:
[clang] Improve ctor initializer completions.

Summary:
Instead of providing generic "args" for member and base class
initializers, tries to fetch relevant constructors and show their signatures.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ZaMaZaN4iK, eraman, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D53654

Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/CodeCompletion/ctor-initializer.cpp
cfe/trunk/test/Index/complete-ctor-inits.cpp
cfe/trunk/test/Index/complete-cxx-inline-methods.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=345844&r1=345843&r2=345844&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Thu Nov  1 08:54:18 2018
@@ -808,12 +808,20 @@ void ResultBuilder::AdjustResultPriority
   }
 }
 
+DeclContext::lookup_result getConstructors(ASTContext &Context,
+   const CXXRecordDecl *Record) {
+  QualType RecordTy = Context.getTypeDeclType(Record);
+  DeclarationName ConstructorName =
+  Context.DeclarationNames.getCXXConstructorName(
+  Context.getCanonicalType(RecordTy));
+  return Record->lookup(ConstructorName);
+}
+
 void ResultBuilder::MaybeAddConstructorResults(Result R) {
   if (!SemaRef.getLangOpts().CPlusPlus || !R.Declaration ||
   !CompletionContext.wantConstructorResults())
 return;
 
-  ASTContext &Context = SemaRef.Context;
   const NamedDecl *D = R.Declaration;
   const CXXRecordDecl *Record = nullptr;
   if (const ClassTemplateDecl *ClassTemplate = dyn_cast(D))
@@ -831,16 +839,8 @@ void ResultBuilder::MaybeAddConstructorR
   if (!Record)
 return;
 
-
-  QualType RecordTy = Context.getTypeDeclType(Record);
-  DeclarationName ConstructorName
-= Context.DeclarationNames.getCXXConstructorName(
-   Context.getCanonicalType(RecordTy));
-  DeclContext::lookup_result Ctors = Record->lookup(ConstructorName);
-  for (DeclContext::lookup_iterator I = Ctors.begin(),
-  E = Ctors.end();
-   I != E; ++I) {
-R.Declaration = *I;
+  for(auto Ctor : getConstructors(SemaRef.Context, Record)) {
+R.Declaration = Ctor;
 R.CursorKind = getCursorKindForDecl(R.Declaration);
 Results.push_back(R);
   }
@@ -5073,11 +5073,77 @@ void Sema::CodeCompleteConstructorInitia
   }
 
   // Add completions for base classes.
-  CodeCompletionBuilder Builder(Results.getAllocator(),
-Results.getCodeCompletionTUInfo());
   PrintingPolicy Policy = getCompletionPrintingPolicy(*this);
   bool SawLastInitializer = Initializers.empty();
   CXXRecordDecl *ClassDecl = Constructor->getParent();
+
+  auto GenerateCCS = [&](const NamedDecl *ND, const char *Name) {
+CodeCompletionBuilder Builder(Results.getAllocator(),
+  Results.getCodeCompletionTUInfo());
+Builder.AddTypedTextChunk(Name);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+if (auto Function = dyn_cast(ND))
+  AddFunctionParameterChunks(PP, Policy, Function, Builder);
+else if (auto FunTemplDecl = dyn_cast(ND))
+  AddFunctionParameterChunks(PP, Policy, FunTemplDecl->getTemplatedDecl(),
+ Builder);
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+return Builder.TakeString();
+  };
+  auto AddDefaultCtorInit = [&](const char *Name, const char *Type,
+const NamedDecl *ND) {
+CodeCompletionBuilder Builder(Results.getAllocator(),
+  Results.getCodeCompletionTUInfo());
+Builder.AddTypedTextChunk(Name);
+Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+Builder.AddPlaceholderChunk(Type);
+Builder.AddChunk(CodeCompletionString::CK_RightParen);
+if (ND) {
+  auto CCR = CodeCompletionResult(
+  Builder.TakeString(), ND,
+  SawLastInitializer ? CCP_NextInitializer : CCP_MemberDeclaration);
+  if (isa(ND))
+CCR.CursorKind = CXCursor_MemberRef;
+  return Results.AddResult(CCR);
+}
+return Results.AddResult(CodeCompletionResult(
+Builder.TakeString(),
+SawLastInitializer ? CCP_NextInitializer : CCP_MemberDeclaration));
+  };
+  auto AddCtorsWithName = [&](const CXXRecordDecl *RD, unsigned int Priority,
+  const char *Name, const FieldDecl *FD) {
+if (!RD)
+  return AddDefaultCtorInit(Name,
+FD ? Results.getAllocator().CopyString(
+ FD->getType().getAsString(Policy))
+

r346123 - Fix breakage on FrontendTest by initializing new field on constructor

2018-11-05 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Nov  5 02:01:34 2018
New Revision: 346123

URL: http://llvm.org/viewvc/llvm-project?rev=346123&view=rev
Log:
Fix breakage on FrontendTest by initializing new field on constructor

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=346123&r1=346122&r2=346123&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Mon Nov  5 
02:01:34 2018
@@ -249,12 +249,11 @@ private:
 public:
   AnalyzerOptions()
   : DisableAllChecks(false), ShowCheckerHelp(false),
-ShowEnabledCheckerList(false), AnalyzeAll(false),
-AnalyzerDisplayProgress(false), AnalyzeNestedBlocks(false),
-eagerlyAssumeBinOpBifurcation(false), TrimGraph(false),
-visualizeExplodedGraphWithGraphViz(false),
-UnoptimizedCFG(false),
-PrintStats(false), NoRetryExhausted(false) {}
+ShowEnabledCheckerList(false), ShowConfigOptionsList(false),
+AnalyzeAll(false), AnalyzerDisplayProgress(false),
+AnalyzeNestedBlocks(false), eagerlyAssumeBinOpBifurcation(false),
+TrimGraph(false), visualizeExplodedGraphWithGraphViz(false),
+UnoptimizedCFG(false), PrintStats(false), NoRetryExhausted(false) {}
 
   /// Interprets an option's string value as a boolean. The "true" string is
   /// interpreted as true and the "false" string is interpreted as false.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r346216 - T was unused on assertion disabled builds.

2018-11-06 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Nov  6 00:59:25 2018
New Revision: 346216

URL: http://llvm.org/viewvc/llvm-project?rev=346216&view=rev
Log:
T was unused on assertion disabled builds.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=346216&r1=346215&r2=346216&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Nov  6 00:59:25 2018
@@ -249,12 +249,13 @@ static Value *MakeAtomicCmpXchgValue(Cod
 static
 Value *EmitAtomicCmpXchgForMSIntrin(CodeGenFunction &CGF, const CallExpr *E,
 AtomicOrdering SuccessOrdering = AtomicOrdering::SequentiallyConsistent) {
-  auto T = E->getType();
   assert(E->getArg(0)->getType()->isPointerType());
-  assert(CGF.getContext().hasSameUnqualifiedType(T,
-  E->getArg(0)->getType()->getPointeeType()));
-  assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(1)->getType()));
-  assert(CGF.getContext().hasSameUnqualifiedType(T, E->getArg(2)->getType()));
+  assert(CGF.getContext().hasSameUnqualifiedType(
+  E->getType(), E->getArg(0)->getType()->getPointeeType()));
+  assert(CGF.getContext().hasSameUnqualifiedType(E->getType(),
+ E->getArg(1)->getType()));
+  assert(CGF.getContext().hasSameUnqualifiedType(E->getType(),
+ E->getArg(2)->getType()));
 
   auto *Destination = CGF.EmitScalarExpr(E->getArg(0));
   auto *Comparand = CGF.EmitScalarExpr(E->getArg(2));


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r346308 - [clangd] [NFC] Fix clang-tidy warnings.

2018-11-07 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Nov  7 04:25:27 2018
New Revision: 346308

URL: http://llvm.org/viewvc/llvm-project?rev=346308&view=rev
Log:
[clangd] [NFC] Fix clang-tidy warnings.

Reviewers: ioeric, sammccall, ilya-biryukov, hokein

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D54157

Modified:
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=346308&r1=346307&r2=346308&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Wed Nov  7 04:25:27 2018
@@ -126,7 +126,7 @@ FileSymbols::buildIndex(IndexType Type,
   for (const auto &Sym : *Slab) {
 auto I = Merged.try_emplace(Sym.ID, Sym);
 if (!I.second)
-  I.first->second = mergeSymbol(std::move(I.first->second), Sym);
+  I.first->second = mergeSymbol(I.first->second, Sym);
   }
 }
 SymsStorage.reserve(Merged.size());

Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp?rev=346308&r1=346307&r2=346308&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Wed Nov  
7 04:25:27 2018
@@ -43,7 +43,7 @@ TEST(BackgroundIndexTest, IndexTwoFiles)
   void f_b() {
 (void)common;
   })cpp";
-  BackgroundIndex Idx(Context::empty(), "", FS, /*URISchmes=*/{"unittest"});
+  BackgroundIndex Idx(Context::empty(), "", FS, /*URISchemes=*/{"unittest"});
 
   tooling::CompileCommand Cmd;
   Cmd.Filename = testPath("root/A.cc");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r346524 - [clangd] Fix clang-tidy warnings.

2018-11-09 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Nov  9 09:33:48 2018
New Revision: 346524

URL: http://llvm.org/viewvc/llvm-project?rev=346524&view=rev
Log:
[clangd] Fix clang-tidy warnings.

Modified:
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TestTU.cpp?rev=346524&r1=346523&r2=346524&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/TestTU.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TestTU.cpp Fri Nov  9 09:33:48 2018
@@ -41,7 +41,7 @@ ParsedAST TestTU::build() const {
   auto Preamble =
   buildPreamble(FullFilename, *createInvocationFromCommandLine(Cmd),
 /*OldPreamble=*/nullptr,
-/*OldCommand=*/Inputs.CompileCommand, Inputs, PCHs,
+/*OldCompileCommand=*/Inputs.CompileCommand, Inputs, PCHs,
 /*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
   auto AST = buildAST(FullFilename, createInvocationFromCommandLine(Cmd),
   Inputs, Preamble, PCHs);
@@ -109,17 +109,17 @@ const NamedDecl &findDecl(ParsedAST &AST
 }
 
 const NamedDecl &findDecl(ParsedAST &AST,
-  std::function Callback) {
+  std::function Filter) {
   struct Visitor : RecursiveASTVisitor {
-decltype(Callback) CB;
+decltype(Filter) F;
 SmallVector Decls;
 bool VisitNamedDecl(const NamedDecl *ND) {
-  if (CB(*ND))
+  if (F(*ND))
 Decls.push_back(ND);
   return true;
 }
   } Visitor;
-  Visitor.CB = Callback;
+  Visitor.F = Filter;
   Visitor.TraverseDecl(AST.getASTContext().getTranslationUnitDecl());
   if (Visitor.Decls.size() != 1) {
 ADD_FAILURE() << Visitor.Decls.size() << " symbols matched.";


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r346872 - [clangd] Delete unused includes.

2018-11-14 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Nov 14 09:07:39 2018
New Revision: 346872

URL: http://llvm.org/viewvc/llvm-project?rev=346872&view=rev
Log:
[clangd] Delete unused includes.

Modified:
clang-tools-extra/trunk/unittests/clangd/TestFS.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/TestFS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TestFS.cpp?rev=346872&r1=346871&r2=346872&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/TestFS.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TestFS.cpp Wed Nov 14 09:07:39 2018
@@ -8,11 +8,9 @@
 
//===--===//
 #include "TestFS.h"
 #include "URI.h"
-#include "clang/AST/DeclCXX.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Path.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace clangd {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r346938 - Introduce shard storage to auto-index.

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:31:10 2018
New Revision: 346938

URL: http://llvm.org/viewvc/llvm-project?rev=346938&view=rev
Log:
Introduce shard storage to auto-index.

Reviewers: sammccall, ioeric

Subscribers: ilya-biryukov, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D54269

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346938&r1=346937&r2=346938&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:31:10 2018
@@ -26,26 +26,52 @@
 #include "llvm/Support/SHA1.h"
 #include 
 #include 
+#include 
+#include 
 
 using namespace llvm;
 namespace clang {
 namespace clangd {
 
-BackgroundIndex::BackgroundIndex(Context BackgroundContext,
- StringRef ResourceDir,
- const FileSystemProvider &FSProvider,
- ArrayRef URISchemes,
- size_t ThreadPoolSize)
+namespace {
+
+static BackgroundIndex::FileDigest digest(StringRef Content) {
+  return SHA1::hash({(const uint8_t *)Content.data(), Content.size()});
+}
+
+static Optional digestFile(const SourceManager 
&SM,
+FileID FID) {
+  bool Invalid = false;
+  StringRef Content = SM.getBufferData(FID, &Invalid);
+  if (Invalid)
+return None;
+  return digest(Content);
+}
+
+llvm::SmallString<128>
+getShardPathFromFilePath(llvm::SmallString<128> ShardRoot,
+ llvm::StringRef FilePath) {
+  sys::path::append(ShardRoot, sys::path::filename(FilePath) +
+   toHex(digest(FilePath)) + ".idx");
+  return ShardRoot;
+}
+
+} // namespace
+
+BackgroundIndex::BackgroundIndex(
+Context BackgroundContext, StringRef ResourceDir,
+const FileSystemProvider &FSProvider, ArrayRef URISchemes,
+std::unique_ptr IndexShardStorage, size_t ThreadPoolSize)
 : SwapIndex(make_unique()), ResourceDir(ResourceDir),
   FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)),
-  URISchemes(URISchemes) {
+  URISchemes(URISchemes), IndexShardStorage(std::move(IndexShardStorage)) {
   assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
   while (ThreadPoolSize--) {
 ThreadPool.emplace_back([this] { run(); });
 // Set priority to low, since background indexing is a long running task we
 // do not want to eat up cpu when there are any other high priority 
threads.
 // FIXME: In the future we might want a more general way of handling this 
to
-// support a tasks with various priorities.
+// support tasks with various priorities.
 setThreadPriority(ThreadPool.back(), ThreadPriority::Low);
   }
 }
@@ -123,6 +149,12 @@ void BackgroundIndex::enqueueAll(StringR
 }
 
 void BackgroundIndex::enqueueLocked(tooling::CompileCommand Cmd) {
+  // Initialize storage to project root. Since Initialize is no-op for multiple
+  // calls we can simply call it for each file.
+  if (IndexShardStorage && !IndexShardStorage->initialize(Cmd.Directory)) {
+elog("Failed to initialize shard storage");
+IndexShardStorage.reset();
+  }
   Queue.push_back(Bind(
   [this](tooling::CompileCommand Cmd) {
 std::string Filename = Cmd.Filename;
@@ -133,19 +165,6 @@ void BackgroundIndex::enqueueLocked(tool
   std::move(Cmd)));
 }
 
-static BackgroundIndex::FileDigest digest(StringRef Content) {
-  return SHA1::hash({(const uint8_t *)Content.data(), Content.size()});
-}
-
-static Optional digestFile(const SourceManager 
&SM,
-FileID FID) {
-  bool Invalid = false;
-  StringRef Content = SM.getBufferData(FID, &Invalid);
-  if (Invalid)
-return None;
-  return digest(Content);
-}
-
 // Resolves URI to file paths with cache.
 class URIToFileCache {
 public:
@@ -227,14 +246,25 @@ void BackgroundIndex::update(StringRef M
 for (const auto *R : F.second.Refs)
   Refs.insert(RefToIDs[R], *R);
 
+auto SS = llvm::make_unique(std::move(Syms).build());
+auto RS = llvm::make_unique(std::move(Refs).build());
+
+auto Hash = FilesToUpdate.lookup(Path);
+// Put shards into storage for subsequent use.
+// FIXME: Store Hash in the Shard.
+if (IndexShardStorage) {
+  IndexFileOut Shard;
+  Shard.Symbols = SS.get();
+  Shard.Refs = RS.get();
+  IndexShardStorage->storeShard(Path, Shard);
+}
+
 std::lock_guard Lock(DigestsMu);
 // This can override a newer version that is added in another thread,
  

[clang-tools-extra] r346940 - Address comments

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:31:19 2018
New Revision: 346940

URL: http://llvm.org/viewvc/llvm-project?rev=346940&view=rev
Log:
Address comments

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346940&r1=346939&r2=346940&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:31:19 2018
@@ -56,15 +56,77 @@ getShardPathFromFilePath(llvm::SmallStri
   return ShardRoot;
 }
 
+// Uses disk as a storage for index shards. Creates a directory called
+// ".clangd-index/" under the path provided during initialize.
+// Note: Requires initialize to be called before storing or retrieval.
+// This class is thread-safe.
+class DiskBackedIndexStorage : public BackgroundIndexStorage {
+  llvm::SmallString<128> DiskShardRoot;
+
+public:
+  llvm::Expected
+  retrieveShard(llvm::StringRef ShardIdentifier) const override {
+auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
+auto Buffer = MemoryBuffer::getFile(ShardPath);
+if (!Buffer) {
+  elog("Couldn't retrieve {0}: {1}", ShardPath,
+   Buffer.getError().message());
+  return llvm::make_error(Buffer.getError());
+}
+// FIXME: Change readIndexFile to also look at Hash of the source that
+// generated index and skip if there is a mismatch.
+return readIndexFile(Buffer->get()->getBuffer());
+  }
+
+  bool storeShard(llvm::StringRef ShardIdentifier,
+  IndexFileOut Shard) const override {
+auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
+std::error_code EC;
+llvm::raw_fd_ostream OS(ShardPath, EC);
+if (EC) {
+  elog("Failed to open {0} for writing: {1}", ShardPath, EC.message());
+  return false;
+}
+OS << Shard;
+return true;
+  }
+
+  // Initializes DiskShardRoot to (Directory + ".clangd-index/") which is the
+  // base directory for all shard files. After the initialization succeeds all
+  // subsequent calls are no-op.
+  DiskBackedIndexStorage(llvm::StringRef Directory) : DiskShardRoot(Directory) 
{
+sys::path::append(DiskShardRoot, ".clangd-index/");
+if (!llvm::sys::fs::exists(DiskShardRoot)) {
+  std::error_code OK;
+  std::error_code EC = llvm::sys::fs::create_directory(DiskShardRoot);
+  if (EC != OK) {
+elog("Failed to create {0}: {1}", DiskShardRoot, EC.message());
+  }
+}
+  }
+};
+
+SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) {
+  SmallString<128> AbsolutePath;
+  if (sys::path::is_absolute(Cmd.Filename)) {
+AbsolutePath = Cmd.Filename;
+  } else {
+AbsolutePath = Cmd.Directory;
+sys::path::append(AbsolutePath, Cmd.Filename);
+  }
+  return AbsolutePath;
+}
+
 } // namespace
 
-BackgroundIndex::BackgroundIndex(
-Context BackgroundContext, StringRef ResourceDir,
-const FileSystemProvider &FSProvider, ArrayRef URISchemes,
-std::unique_ptr IndexShardStorage, size_t ThreadPoolSize)
+BackgroundIndex::BackgroundIndex(Context BackgroundContext,
+ StringRef ResourceDir,
+ const FileSystemProvider &FSProvider,
+ ArrayRef URISchemes,
+ size_t ThreadPoolSize)
 : SwapIndex(make_unique()), ResourceDir(ResourceDir),
   FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)),
-  URISchemes(URISchemes), IndexShardStorage(std::move(IndexShardStorage)) {
+  URISchemes(URISchemes) {
   assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
   while (ThreadPoolSize--) {
 ThreadPool.emplace_back([this] { run(); });
@@ -123,19 +185,58 @@ void BackgroundIndex::blockUntilIdleForT
 
 void BackgroundIndex::enqueue(StringRef Directory,
   tooling::CompileCommand Cmd) {
+  auto IndexStorage = BackgroundIndexStorage::getForDirectory(Directory);
+  if (IndexStorage)
+loadShard(IndexStorage.get(), Cmd);
+  else
+elog("No index storage for: {0}", Directory);
   {
 std::lock_guard Lock(QueueMu);
-enqueueLocked(std::move(Cmd));
+enqueueLocked(std::move(Cmd), std::move(IndexStorage));
   }
   QueueCV.notify_all();
 }
 
+void BackgroundIndex::loadShard(BackgroundIndexStorage *IndexStorage,
+const tooling::CompileCommand &Cmd) {
+  assert(IndexStorage && "No index storage to load from?");
+  auto AbsolutePath = getAbsolutePath(Cmd);
+  auto Shard = IndexStorage->retrieveShard(AbsolutePath);
+  if (Shard) {
+// FIXME: Updated hashes once we have th

[clang-tools-extra] r346939 - clang-format

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:31:15 2018
New Revision: 346939

URL: http://llvm.org/viewvc/llvm-project?rev=346939&view=rev
Log:
clang-format

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346939&r1=346938&r2=346939&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:31:15 2018
@@ -24,10 +24,10 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/SHA1.h"
+#include 
+#include 
 #include 
 #include 
-#include 
-#include 
 
 using namespace llvm;
 namespace clang {

Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp?rev=346939&r1=346938&r2=346939&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Thu Nov 
15 02:31:15 2018
@@ -82,7 +82,7 @@ TEST(BackgroundIndexTest, ShardStorageTe
   class MemoryShardStorage : public ShardStorage {
 mutable std::mutex StorageMu;
 llvm::StringMap &Storage;
-size_t& CacheHits;
+size_t &CacheHits;
 
   public:
 MemoryShardStorage(llvm::StringMap &Storage, size_t 
&CacheHits)
@@ -103,7 +103,7 @@ TEST(BackgroundIndexTest, ShardStorageTe
 return llvm::make_error(
 "Shard not found.", llvm::inconvertibleErrorCode());
   auto IndexFile = readIndexFile(Storage[ShardIdentifier]);
-  if(!IndexFile)
+  if (!IndexFile)
 return IndexFile;
   CacheHits++;
   return IndexFile;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r346941 - Address comments.

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:31:23 2018
New Revision: 346941

URL: http://llvm.org/viewvc/llvm-project?rev=346941&view=rev
Log:
Address comments.

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346941&r1=346940&r2=346941&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:31:23 2018
@@ -48,54 +48,49 @@ static Optional
-getShardPathFromFilePath(llvm::SmallString<128> ShardRoot,
- llvm::StringRef FilePath) {
-  sys::path::append(ShardRoot, sys::path::filename(FilePath) +
-   toHex(digest(FilePath)) + ".idx");
-  return ShardRoot;
+std::string getShardPathFromFilePath(llvm::StringRef ShardRoot,
+ llvm::StringRef FilePath) {
+  llvm::SmallString<128> ShardRootSS(ShardRoot);
+  sys::path::append(ShardRootSS, sys::path::filename(FilePath) +
+ toHex(digest(FilePath)) + ".idx");
+  return ShardRoot.str();
 }
 
 // Uses disk as a storage for index shards. Creates a directory called
-// ".clangd-index/" under the path provided during initialize.
-// Note: Requires initialize to be called before storing or retrieval.
+// ".clangd-index/" under the path provided during construction.
 // This class is thread-safe.
 class DiskBackedIndexStorage : public BackgroundIndexStorage {
-  llvm::SmallString<128> DiskShardRoot;
+  std::string DiskShardRoot;
 
 public:
-  llvm::Expected
-  retrieveShard(llvm::StringRef ShardIdentifier) const override {
-auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
+  llvm::Expected loadShard(llvm::StringRef ShardIdentifier) const 
{
+const std::string ShardPath =
+getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
 auto Buffer = MemoryBuffer::getFile(ShardPath);
 if (!Buffer) {
-  elog("Couldn't retrieve {0}: {1}", ShardPath,
-   Buffer.getError().message());
+  elog("Couldn't load {0}: {1}", ShardPath, Buffer.getError().message());
   return llvm::make_error(Buffer.getError());
 }
-// FIXME: Change readIndexFile to also look at Hash of the source that
-// generated index and skip if there is a mismatch.
 return readIndexFile(Buffer->get()->getBuffer());
   }
 
-  bool storeShard(llvm::StringRef ShardIdentifier,
-  IndexFileOut Shard) const override {
+  llvm::Error storeShard(llvm::StringRef ShardIdentifier,
+ IndexFileOut Shard) const override {
 auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
 std::error_code EC;
 llvm::raw_fd_ostream OS(ShardPath, EC);
-if (EC) {
-  elog("Failed to open {0} for writing: {1}", ShardPath, EC.message());
-  return false;
-}
+if (EC)
+  return errorCodeToError(EC);
 OS << Shard;
-return true;
+return llvm::Error::success();
   }
 
-  // Initializes DiskShardRoot to (Directory + ".clangd-index/") which is the
-  // base directory for all shard files. After the initialization succeeds all
-  // subsequent calls are no-op.
-  DiskBackedIndexStorage(llvm::StringRef Directory) : DiskShardRoot(Directory) 
{
-sys::path::append(DiskShardRoot, ".clangd-index/");
+  // Sets DiskShardRoot to (Directory + ".clangd-index/") which is the base
+  // directory for all shard files.
+  DiskBackedIndexStorage(llvm::StringRef Directory) {
+llvm::SmallString<128> CDBDirectory(Directory);
+sys::path::append(CDBDirectory, ".clangd-index/");
+DiskShardRoot = CDBDirectory.str();
 if (!llvm::sys::fs::exists(DiskShardRoot)) {
   std::error_code OK;
   std::error_code EC = llvm::sys::fs::create_directory(DiskShardRoot);
@@ -106,7 +101,7 @@ public:
   }
 };
 
-SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) {
+std::string getAbsoluteFilePath(const tooling::CompileCommand &Cmd) {
   SmallString<128> AbsolutePath;
   if (sys::path::is_absolute(Cmd.Filename)) {
 AbsolutePath = Cmd.Filename;
@@ -114,7 +109,7 @@ SmallString<128> getAbsolutePath(const t
 AbsolutePath = Cmd.Directory;
 sys::path::append(AbsolutePath, Cmd.Filename);
   }
-  return AbsolutePath;
+  return AbsolutePath.str();
 }
 
 } // namespace
@@ -123,10 +118,12 @@ BackgroundIndex::BackgroundIndex(Context
  StringRef ResourceDir,
  const FileSystemProvider &FSProvider,
  ArrayRef URISchemes,
+ IndexStorageFactory IndexStorageCreator,
   

[clang-tools-extra] r346945 - Revert "Introduce shard storage to auto-index."

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:34:47 2018
New Revision: 346945

URL: http://llvm.org/viewvc/llvm-project?rev=346945&view=rev
Log:
Revert "Introduce shard storage to auto-index."

This reverts commit 6dd1f24aead10a8d375d0311001987198d26e900.

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346945&r1=346944&r2=346945&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:34:47 2018
@@ -26,52 +26,26 @@
 #include "llvm/Support/SHA1.h"
 #include 
 #include 
-#include 
-#include 
 
 using namespace llvm;
 namespace clang {
 namespace clangd {
 
-namespace {
-
-static BackgroundIndex::FileDigest digest(StringRef Content) {
-  return SHA1::hash({(const uint8_t *)Content.data(), Content.size()});
-}
-
-static Optional digestFile(const SourceManager 
&SM,
-FileID FID) {
-  bool Invalid = false;
-  StringRef Content = SM.getBufferData(FID, &Invalid);
-  if (Invalid)
-return None;
-  return digest(Content);
-}
-
-llvm::SmallString<128>
-getShardPathFromFilePath(llvm::SmallString<128> ShardRoot,
- llvm::StringRef FilePath) {
-  sys::path::append(ShardRoot, sys::path::filename(FilePath) +
-   toHex(digest(FilePath)) + ".idx");
-  return ShardRoot;
-}
-
-} // namespace
-
-BackgroundIndex::BackgroundIndex(
-Context BackgroundContext, StringRef ResourceDir,
-const FileSystemProvider &FSProvider, ArrayRef URISchemes,
-std::unique_ptr IndexShardStorage, size_t ThreadPoolSize)
+BackgroundIndex::BackgroundIndex(Context BackgroundContext,
+ StringRef ResourceDir,
+ const FileSystemProvider &FSProvider,
+ ArrayRef URISchemes,
+ size_t ThreadPoolSize)
 : SwapIndex(make_unique()), ResourceDir(ResourceDir),
   FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)),
-  URISchemes(URISchemes), IndexShardStorage(std::move(IndexShardStorage)) {
+  URISchemes(URISchemes) {
   assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
   while (ThreadPoolSize--) {
 ThreadPool.emplace_back([this] { run(); });
 // Set priority to low, since background indexing is a long running task we
 // do not want to eat up cpu when there are any other high priority 
threads.
 // FIXME: In the future we might want a more general way of handling this 
to
-// support tasks with various priorities.
+// support a tasks with various priorities.
 setThreadPriority(ThreadPool.back(), ThreadPriority::Low);
   }
 }
@@ -149,12 +123,6 @@ void BackgroundIndex::enqueueAll(StringR
 }
 
 void BackgroundIndex::enqueueLocked(tooling::CompileCommand Cmd) {
-  // Initialize storage to project root. Since Initialize is no-op for multiple
-  // calls we can simply call it for each file.
-  if (IndexShardStorage && !IndexShardStorage->initialize(Cmd.Directory)) {
-elog("Failed to initialize shard storage");
-IndexShardStorage.reset();
-  }
   Queue.push_back(Bind(
   [this](tooling::CompileCommand Cmd) {
 std::string Filename = Cmd.Filename;
@@ -165,6 +133,19 @@ void BackgroundIndex::enqueueLocked(tool
   std::move(Cmd)));
 }
 
+static BackgroundIndex::FileDigest digest(StringRef Content) {
+  return SHA1::hash({(const uint8_t *)Content.data(), Content.size()});
+}
+
+static Optional digestFile(const SourceManager 
&SM,
+FileID FID) {
+  bool Invalid = false;
+  StringRef Content = SM.getBufferData(FID, &Invalid);
+  if (Invalid)
+return None;
+  return digest(Content);
+}
+
 // Resolves URI to file paths with cache.
 class URIToFileCache {
 public:
@@ -246,25 +227,14 @@ void BackgroundIndex::update(StringRef M
 for (const auto *R : F.second.Refs)
   Refs.insert(RefToIDs[R], *R);
 
-auto SS = llvm::make_unique(std::move(Syms).build());
-auto RS = llvm::make_unique(std::move(Refs).build());
-
-auto Hash = FilesToUpdate.lookup(Path);
-// Put shards into storage for subsequent use.
-// FIXME: Store Hash in the Shard.
-if (IndexShardStorage) {
-  IndexFileOut Shard;
-  Shard.Symbols = SS.get();
-  Shard.Refs = RS.get();
-  IndexShardStorage->storeShard(Path, Shard);
-}
-
 std::lock_guard Lock(DigestsMu);
 // This can override a newer version that is added in another thread,
 // if this thread sees the older version but finishes later. This shoul

[clang-tools-extra] r346944 - Revert "clang-format"

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:34:43 2018
New Revision: 346944

URL: http://llvm.org/viewvc/llvm-project?rev=346944&view=rev
Log:
Revert "clang-format"

This reverts commit 0a37e9c3d88a2e21863657df2f7735fb7e5f746e.

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346944&r1=346943&r2=346944&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:34:43 2018
@@ -24,10 +24,10 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/SHA1.h"
-#include 
-#include 
 #include 
 #include 
+#include 
+#include 
 
 using namespace llvm;
 namespace clang {

Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp?rev=346944&r1=346943&r2=346944&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Thu Nov 
15 02:34:43 2018
@@ -82,7 +82,7 @@ TEST(BackgroundIndexTest, ShardStorageTe
   class MemoryShardStorage : public ShardStorage {
 mutable std::mutex StorageMu;
 llvm::StringMap &Storage;
-size_t &CacheHits;
+size_t& CacheHits;
 
   public:
 MemoryShardStorage(llvm::StringMap &Storage, size_t 
&CacheHits)
@@ -103,7 +103,7 @@ TEST(BackgroundIndexTest, ShardStorageTe
 return llvm::make_error(
 "Shard not found.", llvm::inconvertibleErrorCode());
   auto IndexFile = readIndexFile(Storage[ShardIdentifier]);
-  if (!IndexFile)
+  if(!IndexFile)
 return IndexFile;
   CacheHits++;
   return IndexFile;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r346942 - Revert "Address comments."

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:34:35 2018
New Revision: 346942

URL: http://llvm.org/viewvc/llvm-project?rev=346942&view=rev
Log:
Revert "Address comments."

This reverts commit b43c4d1c731e07172a382567f3146b3c461c5b69.

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346942&r1=346941&r2=346942&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:34:35 2018
@@ -48,49 +48,54 @@ static Optional ShardRootSS(ShardRoot);
-  sys::path::append(ShardRootSS, sys::path::filename(FilePath) +
- toHex(digest(FilePath)) + ".idx");
-  return ShardRoot.str();
+llvm::SmallString<128>
+getShardPathFromFilePath(llvm::SmallString<128> ShardRoot,
+ llvm::StringRef FilePath) {
+  sys::path::append(ShardRoot, sys::path::filename(FilePath) +
+   toHex(digest(FilePath)) + ".idx");
+  return ShardRoot;
 }
 
 // Uses disk as a storage for index shards. Creates a directory called
-// ".clangd-index/" under the path provided during construction.
+// ".clangd-index/" under the path provided during initialize.
+// Note: Requires initialize to be called before storing or retrieval.
 // This class is thread-safe.
 class DiskBackedIndexStorage : public BackgroundIndexStorage {
-  std::string DiskShardRoot;
+  llvm::SmallString<128> DiskShardRoot;
 
 public:
-  llvm::Expected loadShard(llvm::StringRef ShardIdentifier) const 
{
-const std::string ShardPath =
-getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
+  llvm::Expected
+  retrieveShard(llvm::StringRef ShardIdentifier) const override {
+auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
 auto Buffer = MemoryBuffer::getFile(ShardPath);
 if (!Buffer) {
-  elog("Couldn't load {0}: {1}", ShardPath, Buffer.getError().message());
+  elog("Couldn't retrieve {0}: {1}", ShardPath,
+   Buffer.getError().message());
   return llvm::make_error(Buffer.getError());
 }
+// FIXME: Change readIndexFile to also look at Hash of the source that
+// generated index and skip if there is a mismatch.
 return readIndexFile(Buffer->get()->getBuffer());
   }
 
-  llvm::Error storeShard(llvm::StringRef ShardIdentifier,
- IndexFileOut Shard) const override {
+  bool storeShard(llvm::StringRef ShardIdentifier,
+  IndexFileOut Shard) const override {
 auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
 std::error_code EC;
 llvm::raw_fd_ostream OS(ShardPath, EC);
-if (EC)
-  return errorCodeToError(EC);
+if (EC) {
+  elog("Failed to open {0} for writing: {1}", ShardPath, EC.message());
+  return false;
+}
 OS << Shard;
-return llvm::Error::success();
+return true;
   }
 
-  // Sets DiskShardRoot to (Directory + ".clangd-index/") which is the base
-  // directory for all shard files.
-  DiskBackedIndexStorage(llvm::StringRef Directory) {
-llvm::SmallString<128> CDBDirectory(Directory);
-sys::path::append(CDBDirectory, ".clangd-index/");
-DiskShardRoot = CDBDirectory.str();
+  // Initializes DiskShardRoot to (Directory + ".clangd-index/") which is the
+  // base directory for all shard files. After the initialization succeeds all
+  // subsequent calls are no-op.
+  DiskBackedIndexStorage(llvm::StringRef Directory) : DiskShardRoot(Directory) 
{
+sys::path::append(DiskShardRoot, ".clangd-index/");
 if (!llvm::sys::fs::exists(DiskShardRoot)) {
   std::error_code OK;
   std::error_code EC = llvm::sys::fs::create_directory(DiskShardRoot);
@@ -101,7 +106,7 @@ public:
   }
 };
 
-std::string getAbsoluteFilePath(const tooling::CompileCommand &Cmd) {
+SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) {
   SmallString<128> AbsolutePath;
   if (sys::path::is_absolute(Cmd.Filename)) {
 AbsolutePath = Cmd.Filename;
@@ -109,7 +114,7 @@ std::string getAbsoluteFilePath(const to
 AbsolutePath = Cmd.Directory;
 sys::path::append(AbsolutePath, Cmd.Filename);
   }
-  return AbsolutePath.str();
+  return AbsolutePath;
 }
 
 } // namespace
@@ -118,12 +123,10 @@ BackgroundIndex::BackgroundIndex(Context
  StringRef ResourceDir,
  const FileSystemProvider &FSProvider,
  ArrayRef URISchemes,
- IndexStorageFactory IndexStorageCreator,
  size_t ThreadPoolSize)
 : 

[clang-tools-extra] r346943 - Revert "Address comments"

2018-11-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Nov 15 02:34:39 2018
New Revision: 346943

URL: http://llvm.org/viewvc/llvm-project?rev=346943&view=rev
Log:
Revert "Address comments"

This reverts commit 19a39b14eab2b5339325e276262b177357d6b412.

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=346943&r1=346942&r2=346943&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Nov 15 02:34:39 2018
@@ -56,77 +56,15 @@ getShardPathFromFilePath(llvm::SmallStri
   return ShardRoot;
 }
 
-// Uses disk as a storage for index shards. Creates a directory called
-// ".clangd-index/" under the path provided during initialize.
-// Note: Requires initialize to be called before storing or retrieval.
-// This class is thread-safe.
-class DiskBackedIndexStorage : public BackgroundIndexStorage {
-  llvm::SmallString<128> DiskShardRoot;
-
-public:
-  llvm::Expected
-  retrieveShard(llvm::StringRef ShardIdentifier) const override {
-auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
-auto Buffer = MemoryBuffer::getFile(ShardPath);
-if (!Buffer) {
-  elog("Couldn't retrieve {0}: {1}", ShardPath,
-   Buffer.getError().message());
-  return llvm::make_error(Buffer.getError());
-}
-// FIXME: Change readIndexFile to also look at Hash of the source that
-// generated index and skip if there is a mismatch.
-return readIndexFile(Buffer->get()->getBuffer());
-  }
-
-  bool storeShard(llvm::StringRef ShardIdentifier,
-  IndexFileOut Shard) const override {
-auto ShardPath = getShardPathFromFilePath(DiskShardRoot, ShardIdentifier);
-std::error_code EC;
-llvm::raw_fd_ostream OS(ShardPath, EC);
-if (EC) {
-  elog("Failed to open {0} for writing: {1}", ShardPath, EC.message());
-  return false;
-}
-OS << Shard;
-return true;
-  }
-
-  // Initializes DiskShardRoot to (Directory + ".clangd-index/") which is the
-  // base directory for all shard files. After the initialization succeeds all
-  // subsequent calls are no-op.
-  DiskBackedIndexStorage(llvm::StringRef Directory) : DiskShardRoot(Directory) 
{
-sys::path::append(DiskShardRoot, ".clangd-index/");
-if (!llvm::sys::fs::exists(DiskShardRoot)) {
-  std::error_code OK;
-  std::error_code EC = llvm::sys::fs::create_directory(DiskShardRoot);
-  if (EC != OK) {
-elog("Failed to create {0}: {1}", DiskShardRoot, EC.message());
-  }
-}
-  }
-};
-
-SmallString<128> getAbsolutePath(const tooling::CompileCommand &Cmd) {
-  SmallString<128> AbsolutePath;
-  if (sys::path::is_absolute(Cmd.Filename)) {
-AbsolutePath = Cmd.Filename;
-  } else {
-AbsolutePath = Cmd.Directory;
-sys::path::append(AbsolutePath, Cmd.Filename);
-  }
-  return AbsolutePath;
-}
-
 } // namespace
 
-BackgroundIndex::BackgroundIndex(Context BackgroundContext,
- StringRef ResourceDir,
- const FileSystemProvider &FSProvider,
- ArrayRef URISchemes,
- size_t ThreadPoolSize)
+BackgroundIndex::BackgroundIndex(
+Context BackgroundContext, StringRef ResourceDir,
+const FileSystemProvider &FSProvider, ArrayRef URISchemes,
+std::unique_ptr IndexShardStorage, size_t ThreadPoolSize)
 : SwapIndex(make_unique()), ResourceDir(ResourceDir),
   FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)),
-  URISchemes(URISchemes) {
+  URISchemes(URISchemes), IndexShardStorage(std::move(IndexShardStorage)) {
   assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
   while (ThreadPoolSize--) {
 ThreadPool.emplace_back([this] { run(); });
@@ -185,58 +123,19 @@ void BackgroundIndex::blockUntilIdleForT
 
 void BackgroundIndex::enqueue(StringRef Directory,
   tooling::CompileCommand Cmd) {
-  auto IndexStorage = BackgroundIndexStorage::getForDirectory(Directory);
-  if (IndexStorage)
-loadShard(IndexStorage.get(), Cmd);
-  else
-elog("No index storage for: {0}", Directory);
   {
 std::lock_guard Lock(QueueMu);
-enqueueLocked(std::move(Cmd), std::move(IndexStorage));
+enqueueLocked(std::move(Cmd));
   }
   QueueCV.notify_all();
 }
 
-void BackgroundIndex::loadShard(BackgroundIndexStorage *IndexStorage,
-const tooling::CompileCommand &Cmd) {
-  assert(IndexStorage && "No index storage to load from?");
-  auto AbsolutePath = getAbsolutePath(Cmd);
-  auto Shard = IndexStorage->retrieveShard(Abso

[clang-tools-extra] r347038 - Introduce shard storage to auto-index.

2018-11-16 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Nov 16 01:03:56 2018
New Revision: 347038

URL: http://llvm.org/viewvc/llvm-project?rev=347038&view=rev
Log:
Introduce shard storage to auto-index.

Reviewers: sammccall, ioeric

Reviewed By: sammccall

Subscribers: llvm-commits, mgorny, Eugene.Zelenko, ilya-biryukov, jkorous, 
arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D54269

Added:
clang-tools-extra/trunk/clangd/index/BackgroundIndexStorage.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=347038&r1=347037&r2=347038&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Nov 16 01:03:56 2018
@@ -38,6 +38,7 @@ add_clang_library(clangDaemon
   XRefs.cpp
 
   index/Background.cpp
+  index/BackgroundIndexStorage.cpp
   index/CanonicalIncludes.cpp
   index/FileIndex.cpp
   index/Index.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=347038&r1=347037&r2=347038&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Fri Nov 16 01:03:56 2018
@@ -24,6 +24,9 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/SHA1.h"
+
+#include 
+#include 
 #include 
 #include 
 
@@ -31,21 +34,22 @@ using namespace llvm;
 namespace clang {
 namespace clangd {
 
-BackgroundIndex::BackgroundIndex(Context BackgroundContext,
- StringRef ResourceDir,
- const FileSystemProvider &FSProvider,
- ArrayRef URISchemes,
- size_t ThreadPoolSize)
+BackgroundIndex::BackgroundIndex(
+Context BackgroundContext, StringRef ResourceDir,
+const FileSystemProvider &FSProvider, ArrayRef URISchemes,
+BackgroundIndexStorage::Factory IndexStorageFactory, size_t ThreadPoolSize)
 : SwapIndex(make_unique()), ResourceDir(ResourceDir),
   FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)),
-  URISchemes(URISchemes) {
+  URISchemes(URISchemes),
+  IndexStorageFactory(std::move(IndexStorageFactory)) {
   assert(ThreadPoolSize > 0 && "Thread pool size can't be zero.");
+  assert(IndexStorageFactory && "Storage factory can not be null!");
   while (ThreadPoolSize--) {
 ThreadPool.emplace_back([this] { run(); });
 // Set priority to low, since background indexing is a long running task we
 // do not want to eat up cpu when there are any other high priority 
threads.
 // FIXME: In the future we might want a more general way of handling this 
to
-// support a tasks with various priorities.
+// support tasks with various priorities.
 setThreadPriority(ThreadPool.back(), ThreadPriority::Low);
   }
 }
@@ -97,9 +101,10 @@ void BackgroundIndex::blockUntilIdleForT
 
 void BackgroundIndex::enqueue(StringRef Directory,
   tooling::CompileCommand Cmd) {
+  BackgroundIndexStorage *IndexStorage = IndexStorageFactory(Directory);
   {
 std::lock_guard Lock(QueueMu);
-enqueueLocked(std::move(Cmd));
+enqueueLocked(std::move(Cmd), IndexStorage);
   }
   QueueCV.notify_all();
 }
@@ -110,6 +115,7 @@ void BackgroundIndex::enqueueAll(StringR
   // FIXME: this function may be slow. Perhaps enqueue a task to re-read the 
CDB
   // from disk and enqueue the commands asynchronously?
   auto Cmds = CDB.getAllCompileCommands();
+  BackgroundIndexStorage *IndexStorage = IndexStorageFactory(Directory);
   SPAN_ATTACH(Tracer, "commands", int64_t(Cmds.size()));
   std::mt19937 Generator(std::random_device{}());
   std::shuffle(Cmds.begin(), Cmds.end(), Generator);
@@ -117,17 +123,18 @@ void BackgroundIndex::enqueueAll(StringR
   {
 std::lock_guard Lock(QueueMu);
 for (auto &Cmd : Cmds)
-  enqueueLocked(std::move(Cmd));
+  enqueueLocked(std::move(Cmd), IndexStorage);
   }
   QueueCV.notify_all();
 }
 
-void BackgroundIndex::enqueueLocked(tooling::CompileCommand Cmd) {
+void BackgroundIndex::enqueueLocked(tooling::CompileCommand Cmd,
+BackgroundIndexStorage *IndexStorage) {
   Queue.push_back(Bind(
-  [this](tooling::CompileCommand Cmd) {
+  [this, IndexStorage](tooling::CompileCommand Cmd) {
 std::string Filename = Cmd.Filename;
 Cmd.CommandLine.push_back("-resource-dir=" + Resource

[clang-tools-extra] r347235 - [clangd] Store source file hash in IndexFile{In, Out}

2018-11-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Nov 19 10:06:29 2018
New Revision: 347235

URL: http://llvm.org/viewvc/llvm-project?rev=347235&view=rev
Log:
[clangd] Store source file hash in IndexFile{In,Out}

Summary:
Puts the digest of the source file that generated the index into
serialized index and stores them back on load, if exists.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D54693

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/Serialization.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=347235&r1=347234&r2=347235&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Mon Nov 19 10:06:29 2018
@@ -246,6 +246,7 @@ void BackgroundIndex::update(StringRef M
   IndexFileOut Shard;
   Shard.Symbols = SS.get();
   Shard.Refs = RS.get();
+  Shard.Digest = &Hash;
   if (auto Error = IndexStorage->storeShard(Path, Shard))
 elog("Failed to write background-index shard for file {0}: {1}", Path,
  std::move(Error));

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=347235&r1=347234&r2=347235&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Mon Nov 19 10:06:29 
2018
@@ -363,6 +363,13 @@ Expected readRIFF(StringRef
 return Strings.takeError();
 
   IndexFileIn Result;
+  if (Chunks.count("hash")) {
+Reader Hash(Chunks.lookup("hash"));
+llvm::StringRef Digest = Hash.consume(20);
+Result.Digest.emplace();
+std::copy(Digest.bytes_begin(), Digest.bytes_end(), 
Result.Digest->begin());
+  }
+
   if (Chunks.count("symb")) {
 Reader SymbolReader(Chunks.lookup("symb"));
 SymbolSlab::Builder Symbols;
@@ -399,6 +406,12 @@ void writeRIFF(const IndexFileOut &Data,
   }
   RIFF.Chunks.push_back({riff::fourCC("meta"), Meta});
 
+  if (Data.Digest) {
+llvm::StringRef Hash(reinterpret_cast(Data.Digest->data()),
+ Data.Digest->size());
+RIFF.Chunks.push_back({riff::fourCC("hash"), Hash});
+  }
+
   StringTableOut Strings;
   std::vector Symbols;
   for (const auto &Sym : *Data.Symbols) {

Modified: clang-tools-extra/trunk/clangd/index/Serialization.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.h?rev=347235&r1=347234&r2=347235&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.h (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.h Mon Nov 19 10:06:29 
2018
@@ -39,6 +39,8 @@ enum class IndexFileFormat {
 struct IndexFileIn {
   llvm::Optional Symbols;
   llvm::Optional Refs;
+  // Digest of the source file that generated the contents.
+  llvm::Optional> Digest;
 };
 // Parse an index file. The input must be a RIFF or YAML file.
 llvm::Expected readIndexFile(llvm::StringRef);
@@ -47,6 +49,8 @@ llvm::Expected readIndexFil
 struct IndexFileOut {
   const SymbolSlab *Symbols = nullptr;
   const RefSlab *Refs = nullptr;
+  // Digest of the source file that generated the contents.
+  const std::array *Digest = nullptr;
   // TODO: Support serializing Dex posting lists.
   IndexFileFormat Format = IndexFileFormat::RIFF;
 

Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp?rev=347235&r1=347234&r2=347235&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Mon Nov 
19 10:06:29 2018
@@ -121,8 +121,10 @@ TEST(BackgroundIndexTest, ShardStorageWr
   void f_b();
   class A_CC {};
   )cpp";
-  FS.Files[testPath("root/A.cc")] =
-  "#include \"A.h\"\nvoid g() { (void)common; }";
+  std::string A_CC = "#include \"A.h\"\nvoid g() { (void)common; }";
+  FS.Files[testPath("root/A.cc")] = A_CC;
+  auto Digest = llvm::SHA1::hash(
+  {reinterpret_cast(A_CC.data()), A_CC.size()});
 
   llvm::StringMap Storage;
   size_t CacheHits = 0;
@@ -156,6 +158,7 @@ TEST(BackgroundIndexTest, ShardSt

[clang-tools-extra] r347237 - Address comments.

2018-11-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Nov 19 10:06:36 2018
New Revision: 347237

URL: http://llvm.org/viewvc/llvm-project?rev=347237&view=rev
Log:
Address comments.

Modified:
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/Serialization.h

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=347237&r1=347236&r2=347237&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Mon Nov 19 10:06:36 
2018
@@ -331,6 +331,7 @@ std::pair> re
 // A file is a RIFF chunk with type 'CdIx'.
 // It contains the sections:
 //   - meta: version number
+//   - srcs: checksum of the source file
 //   - stri: string table
 //   - symb: symbols
 //   - refs: references to symbols
@@ -363,8 +364,8 @@ Expected readRIFF(StringRef
 return Strings.takeError();
 
   IndexFileIn Result;
-  if (Chunks.count("hash")) {
-Reader Hash(Chunks.lookup("hash"));
+  if (Chunks.count("srcs")) {
+Reader Hash(Chunks.lookup("srcs"));
 Result.Digest.emplace();
 llvm::StringRef Digest = Hash.consume(Result.Digest->size());
 std::copy(Digest.bytes_begin(), Digest.bytes_end(), 
Result.Digest->begin());
@@ -409,7 +410,7 @@ void writeRIFF(const IndexFileOut &Data,
   if (Data.Digest) {
 llvm::StringRef Hash(reinterpret_cast(Data.Digest->data()),
  Data.Digest->size());
-RIFF.Chunks.push_back({riff::fourCC("hash"), Hash});
+RIFF.Chunks.push_back({riff::fourCC("srcs"), Hash});
   }
 
   StringTableOut Strings;

Modified: clang-tools-extra/trunk/clangd/index/Serialization.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.h?rev=347237&r1=347236&r2=347237&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.h (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.h Mon Nov 19 10:06:36 
2018
@@ -37,10 +37,11 @@ enum class IndexFileFormat {
 
 // Holds the contents of an index file that was read.
 struct IndexFileIn {
+  using FileDigest = std::array;
   llvm::Optional Symbols;
   llvm::Optional Refs;
   // Digest of the source file that generated the contents.
-  llvm::Optional> Digest;
+  llvm::Optional Digest;
 };
 // Parse an index file. The input must be a RIFF or YAML file.
 llvm::Expected readIndexFile(llvm::StringRef);
@@ -50,7 +51,7 @@ struct IndexFileOut {
   const SymbolSlab *Symbols = nullptr;
   const RefSlab *Refs = nullptr;
   // Digest of the source file that generated the contents.
-  const std::array *Digest = nullptr;
+  const IndexFileIn::FileDigest *Digest = nullptr;
   // TODO: Support serializing Dex posting lists.
   IndexFileFormat Format = IndexFileFormat::RIFF;
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r347236 - Use digest size instead of hardcoding it.

2018-11-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Nov 19 10:06:33 2018
New Revision: 347236

URL: http://llvm.org/viewvc/llvm-project?rev=347236&view=rev
Log:
Use digest size instead of hardcoding it.

Modified:
clang-tools-extra/trunk/clangd/index/Serialization.cpp

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=347236&r1=347235&r2=347236&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Mon Nov 19 10:06:33 
2018
@@ -365,8 +365,8 @@ Expected readRIFF(StringRef
   IndexFileIn Result;
   if (Chunks.count("hash")) {
 Reader Hash(Chunks.lookup("hash"));
-llvm::StringRef Digest = Hash.consume(20);
 Result.Digest.emplace();
+llvm::StringRef Digest = Hash.consume(Result.Digest->size());
 std::copy(Digest.bytes_begin(), Digest.bytes_end(), 
Result.Digest->begin());
   }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r347669 - [clangd] Put direct headers into srcs section.

2018-11-27 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Nov 27 08:08:53 2018
New Revision: 347669

URL: http://llvm.org/viewvc/llvm-project?rev=347669&view=rev
Log:
[clangd] Put direct headers into srcs section.

Summary:
Currently, there's no way of knowing about header files
using compilation database, since it doesn't contain header files as entries.

Using this information, restoring from cache using compile commands becomes
possible instead of doing directory traversal. Also, we can issue indexing
actions for out-of-date headers even if source files depending on them haven't
changed.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D54817

Modified:
clang-tools-extra/trunk/clangd/Headers.h
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/Serialization.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp

Modified: clang-tools-extra/trunk/clangd/Headers.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=347669&r1=347668&r2=347669&view=diff
==
--- clang-tools-extra/trunk/clangd/Headers.h (original)
+++ clang-tools-extra/trunk/clangd/Headers.h Tue Nov 27 08:08:53 2018
@@ -48,6 +48,20 @@ struct Inclusion {
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion&);
 
+// Contains information about one file in the build grpah and its direct
+// dependencies. Doesn't own the strings it references (IncludeGraph is
+// self-contained).
+struct IncludeGraphNode {
+  // True if current file is a main file rather than a header.
+  bool IsTU;
+  llvm::StringRef URI;
+  FileDigest Digest;
+  std::vector DirectIncludes;
+};
+// FileURI and FileInclusions are references to keys of the map containing
+// them.
+using IncludeGraph = llvm::StringMap;
+
 // Information captured about the inclusion graph in a translation unit.
 // This includes detailed information about the direct #includes, and summary
 // information about all transitive includes.

Modified: clang-tools-extra/trunk/clangd/SourceCode.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.cpp?rev=347669&r1=347668&r2=347669&view=diff
==
--- clang-tools-extra/trunk/clangd/SourceCode.cpp (original)
+++ clang-tools-extra/trunk/clangd/SourceCode.cpp Tue Nov 27 08:08:53 2018
@@ -227,5 +227,17 @@ bool IsRangeConsecutive(const Range &Lef
  Left.end.character == Right.start.character;
 }
 
+FileDigest digest(StringRef Content) {
+  return llvm::SHA1::hash({(const uint8_t *)Content.data(), Content.size()});
+}
+
+Optional digestFile(const SourceManager &SM, FileID FID) {
+  bool Invalid = false;
+  StringRef Content = SM.getBufferData(FID, &Invalid);
+  if (Invalid)
+return None;
+  return digest(Content);
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/SourceCode.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.h?rev=347669&r1=347668&r2=347669&view=diff
==
--- clang-tools-extra/trunk/clangd/SourceCode.h (original)
+++ clang-tools-extra/trunk/clangd/SourceCode.h Tue Nov 27 08:08:53 2018
@@ -16,13 +16,22 @@
 #include "Protocol.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Tooling/Core/Replacement.h"
+#include "llvm/Support/SHA1.h"
 
 namespace clang {
 class SourceManager;
 
 namespace clangd {
 
+// We tend to generate digests for source codes in a lot of different places.
+// This represents the type for those digests to prevent us hard coding details
+// of hashing function at every place that needs to store this information.
+using FileDigest = decltype(llvm::SHA1::hash({}));
+FileDigest digest(StringRef Content);
+Optional digestFile(const SourceManager &SM, FileID FID);
+
 // Counts the number of UTF-16 code units needed to represent a string (LSP
 // specifies string lengths in UTF-16 code units).
 size_t lspLength(StringRef Code);

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=347669&r1=347668&r2=347669&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Tue Nov 27 08:08:53 2018
@@ -11,

[clang-tools-extra] r348005 - [clangd] Populate include graph during static indexing action.

2018-11-30 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Nov 30 08:59:00 2018
New Revision: 348005

URL: http://llvm.org/viewvc/llvm-project?rev=348005&view=rev
Log:
[clangd] Populate include graph during static indexing action.

Summary:
This is the second part for introducing include hierarchy into index
files produced by clangd. You can see the base patch that introduces structures
and discusses the future of the patches in D54817

Reviewers: ilya-biryukov

Subscribers: mgorny, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D54999

Added:
clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp
Modified:
clang-tools-extra/trunk/clangd/Headers.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/index/IndexAction.h
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/Headers.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=348005&r1=348004&r2=348005&view=diff
==
--- clang-tools-extra/trunk/clangd/Headers.h (original)
+++ clang-tools-extra/trunk/clangd/Headers.h Fri Nov 30 08:59:00 2018
@@ -46,7 +46,7 @@ struct Inclusion {
   unsigned HashOffset = 0; // Byte offset from start of file to #.
   SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
 };
-llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion&);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion &);
 
 // Contains information about one file in the build grpah and its direct
 // dependencies. Doesn't own the strings it references (IncludeGraph is
@@ -60,6 +60,8 @@ struct IncludeGraphNode {
 };
 // FileURI and FileInclusions are references to keys of the map containing
 // them.
+// Important: The graph generated by those callbacks might contain cycles, self
+// edges and multi edges.
 using IncludeGraph = llvm::StringMap;
 
 // Information captured about the inclusion graph in a translation unit.

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=348005&r1=348004&r2=348005&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Fri Nov 30 08:59:00 2018
@@ -342,7 +342,8 @@ Error BackgroundIndex::index(tooling::Co
   RefSlab Refs;
   auto Action = createStaticIndexingAction(
   IndexOpts, [&](SymbolSlab S) { Symbols = std::move(S); },
-  [&](RefSlab R) { Refs = std::move(R); });
+  [&](RefSlab R) { Refs = std::move(R); },
+  /*IncludeGraphCallback=*/nullptr);
 
   // We're going to run clang here, and it could potentially crash.
   // We could use CrashRecoveryContext to try to make indexing crashes 
nonfatal,

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=348005&r1=348004&r2=348005&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Fri Nov 30 08:59:00 
2018
@@ -9,6 +9,98 @@ namespace clang {
 namespace clangd {
 namespace {
 
+llvm::Optional toURI(const FileEntry *File) {
+  if (!File)
+return llvm::None;
+  auto AbsolutePath = File->tryGetRealPathName();
+  if (AbsolutePath.empty())
+return llvm::None;
+  return URI::create(AbsolutePath).toString();
+}
+
+// Collects the nodes and edges of include graph during indexing action.
+// Important: The graph generated by those callbacks might contain cycles and
+// self edges.
+struct IncludeGraphCollector : public PPCallbacks {
+public:
+  IncludeGraphCollector(const SourceManager &SM, IncludeGraph &IG)
+  : SM(SM), IG(IG) {}
+
+  // Populates everything except direct includes for a node, which represents
+  // edges in the include graph and populated in inclusion directive.
+  // We cannot populate the fields in InclusionDirective because it does not
+  // have access to the contents of the included file.
+  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+   SrcMgr::CharacteristicKind FileType,
+   FileID PrevFID) override {
+// We only need to process each file once. So we don't care about anything
+// but entries.
+if (Reason != FileChangeReason::EnterFile)
+  return;
+
+const auto FileID = SM.getFileID(Loc);
+const auto File = SM.getFileEntryForID(FileID);
+auto URI = toURI(File);
+if (!URI)
+  return;
+auto I = IG.try_emplace(*URI).first;
+
+auto &Node = I->getValue();

r348006 - [clang] Fill RealPathName for virtual files.

2018-11-30 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Nov 30 09:10:11 2018
New Revision: 348006

URL: http://llvm.org/viewvc/llvm-project?rev=348006&view=rev
Log:
[clang] Fill RealPathName for virtual files.

Summary:
Absolute path information for virtual files were missing even if we
have already stat'd the files. This patch puts that information for virtual
files that can succesffully be stat'd.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D55054

Modified:
cfe/trunk/include/clang/Basic/FileManager.h
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/unittests/Basic/FileManagerTest.cpp

Modified: cfe/trunk/include/clang/Basic/FileManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileManager.h?rev=348006&r1=348005&r2=348006&view=diff
==
--- cfe/trunk/include/clang/Basic/FileManager.h (original)
+++ cfe/trunk/include/clang/Basic/FileManager.h Fri Nov 30 09:10:11 2018
@@ -104,6 +104,10 @@ public:
   void closeFile() const {
 File.reset(); // rely on destructor to close File
   }
+
+  // Only for use in tests to see if deferred opens are happening, rather than
+  // relying on RealPathName being empty.
+  bool isOpenForTests() const { return File != nullptr; }
 };
 
 struct FileData;
@@ -173,6 +177,9 @@ class FileManager : public RefCountedBas
   /// or a directory) as virtual directories.
   void addAncestorsAsVirtualDirs(StringRef Path);
 
+  /// Fills the RealPathName in file entry.
+  void fillRealPathName(FileEntry *UFE, llvm::StringRef FileName);
+
 public:
   FileManager(const FileSystemOptions &FileSystemOpts,
   IntrusiveRefCntPtr FS = nullptr);

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=348006&r1=348005&r2=348006&view=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Fri Nov 30 09:10:11 2018
@@ -293,16 +293,8 @@ const FileEntry *FileManager::getFile(St
   // If we opened the file for the first time, record the resulting info.
   // Do this even if the cache entry was valid, maybe we didn't previously 
open.
   if (F && !UFE.File) {
-if (auto PathName = F->getName()) {
-  llvm::SmallString<128> AbsPath(*PathName);
-  // This is not the same as `VFS::getRealPath()`, which resolves symlinks
-  // but can be very expensive on real file systems.
-  // FIXME: the semantic of RealPathName is unclear, and the name might be
-  // misleading. We need to clean up the interface here.
-  makeAbsolutePath(AbsPath);
-  llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true);
-  UFE.RealPathName = AbsPath.str();
-}
+if (auto PathName = F->getName())
+  fillRealPathName(&UFE, *PathName);
 UFE.File = std::move(F);
 assert(!UFE.DeferredOpen && "we just opened it!");
   }
@@ -395,6 +387,7 @@ FileManager::getVirtualFile(StringRef Fi
 UFE->UniqueID = Data.UniqueID;
 UFE->IsNamedPipe = Data.IsNamedPipe;
 UFE->InPCH = Data.InPCH;
+fillRealPathName(UFE, Data.Name);
   }
 
   if (!UFE) {
@@ -438,6 +431,17 @@ bool FileManager::makeAbsolutePath(Small
   return Changed;
 }
 
+void FileManager::fillRealPathName(FileEntry *UFE, llvm::StringRef FileName) {
+  llvm::SmallString<128> AbsPath(FileName);
+  // This is not the same as `VFS::getRealPath()`, which resolves symlinks
+  // but can be very expensive on real file systems.
+  // FIXME: the semantic of RealPathName is unclear, and the name might be
+  // misleading. We need to clean up the interface here.
+  makeAbsolutePath(AbsPath);
+  llvm::sys::path::remove_dots(AbsPath, /*remove_dot_dot=*/true);
+  UFE->RealPathName = AbsPath.str();
+}
+
 llvm::ErrorOr>
 FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile,
   bool ShouldCloseOpenFile) {

Modified: cfe/trunk/unittests/Basic/FileManagerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=348006&r1=348005&r2=348006&view=diff
==
--- cfe/trunk/unittests/Basic/FileManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/FileManagerTest.cpp Fri Nov 30 09:10:11 2018
@@ -235,22 +235,18 @@ TEST_F(FileManagerTest, getFileDefersOpe
   ASSERT_TRUE(file != nullptr);
   ASSERT_TRUE(file->isValid());
   // "real path name" reveals whether the file was actually opened.
-  EXPECT_EQ("", file->tryGetRealPathName());
+  EXPECT_FALSE(file->isOpenForTests());
 
   file = manager.getFile("/tmp/test", /*OpenFile=*/true);
   ASSERT_TRUE(file != nullptr);
   ASSERT_TRUE(file->isValid());
-#ifdef _WIN32
-  EXPECT_EQ("/tmp\\test", file->tryGetRealPathName());
-#else
-  EXPECT_EQ("/tmp/test", file->tryGetRealPathName());
-#endif
+  EXPECT_TR

r348015 - [clang] Fix rL348006 for windows

2018-11-30 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Nov 30 10:36:31 2018
New Revision: 348015

URL: http://llvm.org/viewvc/llvm-project?rev=348015&view=rev
Log:
[clang] Fix rL348006 for windows

Modified:
cfe/trunk/unittests/Basic/FileManagerTest.cpp

Modified: cfe/trunk/unittests/Basic/FileManagerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/FileManagerTest.cpp?rev=348015&r1=348014&r2=348015&view=diff
==
--- cfe/trunk/unittests/Basic/FileManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/FileManagerTest.cpp Fri Nov 30 10:36:31 2018
@@ -361,7 +361,14 @@ TEST_F(FileManagerTest, getVirtualFileFi
   const FileEntry *file = manager.getVirtualFile("/tmp/test", 123, 1);
   ASSERT_TRUE(file != nullptr);
   ASSERT_TRUE(file->isValid());
-  EXPECT_EQ(file->tryGetRealPathName(), "/tmp/test");
+  SmallString<64> ExpectedResult;
+#ifdef _WIN32
+  ExpectedResult = "C:";
+#else
+  ExpectedResult = "/";
+#endif
+  llvm::sys::path::append(ExpectedResult, "tmp", "test");
+  EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
 }
 
 } // anonymous namespace


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r348252 - [clangd] Partition include graph on auto-index.

2018-12-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Dec  4 03:31:57 2018
New Revision: 348252

URL: http://llvm.org/viewvc/llvm-project?rev=348252&view=rev
Log:
[clangd] Partition include graph on auto-index.

Summary:
Partitions include graphs in auto-index so that each shards contains
only part of the include graph related to itself.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D55062

Modified:
clang-tools-extra/trunk/clangd/Headers.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/Headers.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Headers.h?rev=348252&r1=348251&r2=348252&view=diff
==
--- clang-tools-extra/trunk/clangd/Headers.h (original)
+++ clang-tools-extra/trunk/clangd/Headers.h Tue Dec  4 03:31:57 2018
@@ -53,9 +53,9 @@ llvm::raw_ostream &operator<<(llvm::raw_
 // self-contained).
 struct IncludeGraphNode {
   // True if current file is a main file rather than a header.
-  bool IsTU;
+  bool IsTU = false;
   llvm::StringRef URI;
-  FileDigest Digest;
+  FileDigest Digest{0};
   std::vector DirectIncludes;
 };
 // FileURI and FileInclusions are references to keys of the map containing

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=348252&r1=348251&r2=348252&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Tue Dec  4 03:31:57 2018
@@ -35,6 +35,58 @@
 using namespace llvm;
 namespace clang {
 namespace clangd {
+namespace {
+// Resolves URI to file paths with cache.
+class URIToFileCache {
+public:
+  URIToFileCache(llvm::StringRef HintPath) : HintPath(HintPath) {}
+
+  llvm::StringRef resolve(llvm::StringRef FileURI) {
+auto I = URIToPathCache.try_emplace(FileURI);
+if (I.second) {
+  auto U = URI::parse(FileURI);
+  if (!U) {
+elog("Failed to parse URI {0}: {1}", FileURI, U.takeError());
+assert(false && "Failed to parse URI");
+return "";
+  }
+  auto Path = URI::resolve(*U, HintPath);
+  if (!Path) {
+elog("Failed to resolve URI {0}: {1}", FileURI, Path.takeError());
+assert(false && "Failed to resolve URI");
+return "";
+  }
+  I.first->second = *Path;
+}
+return I.first->second;
+  }
+
+private:
+  std::string HintPath;
+  llvm::StringMap URIToPathCache;
+};
+
+// We keep only the node "U" and its edges. Any node other than "U" will be
+// empty in the resultant graph.
+IncludeGraph getSubGraph(const URI &U, const IncludeGraph &FullGraph) {
+  IncludeGraph IG;
+
+  std::string FileURI = U.toString();
+  auto Entry = IG.try_emplace(FileURI).first;
+  auto &Node = Entry->getValue();
+  Node = FullGraph.lookup(Entry->getKey());
+  Node.URI = Entry->getKey();
+
+  // URIs inside nodes must point into the keys of the same IncludeGraph.
+  for (auto &Include : Node.DirectIncludes) {
+auto I = IG.try_emplace(Include).first;
+I->getValue().URI = I->getKey();
+Include = I->getKey();
+  }
+
+  return IG;
+}
+} // namespace
 
 BackgroundIndex::BackgroundIndex(
 Context BackgroundContext, StringRef ResourceDir,
@@ -150,36 +202,6 @@ void BackgroundIndex::enqueueTask(Task T
   QueueCV.notify_all();
 }
 
-// Resolves URI to file paths with cache.
-class URIToFileCache {
-public:
-  URIToFileCache(llvm::StringRef HintPath) : HintPath(HintPath) {}
-
-  llvm::StringRef resolve(llvm::StringRef FileURI) {
-auto I = URIToPathCache.try_emplace(FileURI);
-if (I.second) {
-  auto U = URI::parse(FileURI);
-  if (!U) {
-elog("Failed to parse URI {0}: {1}", FileURI, U.takeError());
-assert(false && "Failed to parse URI");
-return "";
-  }
-  auto Path = URI::resolve(*U, HintPath);
-  if (!Path) {
-elog("Failed to resolve URI {0}: {1}", FileURI, Path.takeError());
-assert(false && "Failed to resolve URI");
-return "";
-  }
-  I.first->second = *Path;
-}
-return I.first->second;
-  }
-
-private:
-  std::string HintPath;
-  llvm::StringMap URIToPathCache;
-};
-
 /// Given index results from a TU, only update files in \p FilesToUpdate.
 void BackgroundIndex::update(StringRef MainFile, IndexFileIn Index,
  const StringMap &FilesToUpdate,
@@ -233,6 +255,8 @@ void BackgroundIndex::update(StringRef M
 
 auto SS = llvm::make_unique(std::move(Syms).build());
 auto RS = llvm::make_unique(std::move(Refs).build());
+auto IG = llvm::make_unique(
+getSubGraph(URI::create(Path), Index.Sources.getValue()));
 
 auto Hash = Fil

[clang-tools-extra] r348359 - [clangd] Dont provide locations for non-existent files.

2018-12-05 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Dec  5 03:57:15 2018
New Revision: 348359

URL: http://llvm.org/viewvc/llvm-project?rev=348359&view=rev
Log:
[clangd] Dont provide locations for non-existent files.

Summary:
We were getting assertion errors when we had bad file names, instead we
should skip those.

Reviewers: hokein

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D55275

Modified:
clang-tools-extra/trunk/clangd/AST.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/AST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=348359&r1=348358&r2=348359&view=diff
==
--- clang-tools-extra/trunk/clangd/AST.cpp (original)
+++ clang-tools-extra/trunk/clangd/AST.cpp Wed Dec  5 03:57:15 2018
@@ -23,9 +23,11 @@ namespace clang {
 namespace clangd {
 
 // Returns true if the complete name of decl \p D is spelled in the source 
code.
-// This is not the case for symbols formed via macro concatenation.
-// (We used to attempt to treat names spelled on the command-line this way too,
-// but the preamble doesn't preserve the required information).
+// This is not the case for:
+//   * symbols formed via macro concatenation, the spelling location will
+// be ""
+//   * symbols controlled and defined by a compile command-line option
+// `-DName=foo`, the spelling location will be "".
 bool isSpelledInSourceCode(const Decl *D) {
   const auto &SM = D->getASTContext().getSourceManager();
   auto Loc = D->getLocation();
@@ -33,7 +35,8 @@ bool isSpelledInSourceCode(const Decl *D
   // macros, we should use the location where the whole definition occurs.
   if (Loc.isMacroID()) {
 std::string PrintLoc = SM.getSpellingLoc(Loc).printToString(SM);
-if (StringRef(PrintLoc).startswith(""))
   return false;
   }
   return true;

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=348359&r1=348358&r2=348359&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Wed Dec  
5 03:57:15 2018
@@ -614,6 +614,18 @@ TEST_F(SymbolCollectorTest, SymbolFormed
 DeclURI(TestHeaderURI;
 }
 
+TEST_F(SymbolCollectorTest, SymbolFormedByCLI) {
+  Annotations Header(R"(
+#ifdef NAME
+class $expansion[[NAME]] {};
+#endif
+  )");
+  runSymbolCollector(Header.code(), /*Main=*/"", 
/*ExtraArgs=*/{"-DNAME=name"});
+  EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(
+   QName("name"), DeclRange(Header.range("expansion")),
+   DeclURI(TestHeaderURI;
+}
+
 TEST_F(SymbolCollectorTest, IgnoreSymbolsInMainFile) {
   const std::string Header = R"(
 class Foo {};


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r354865 - [clangd] Update docs to mention YCM integration and new LSP features

2019-02-26 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Feb 26 03:08:04 2019
New Revision: 354865

URL: http://llvm.org/viewvc/llvm-project?rev=354865&view=rev
Log:
[clangd] Update docs to mention YCM integration and new LSP features

Reviewers: gribozavr

Reviewed By: gribozavr

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D56718

Modified:
clang-tools-extra/trunk/docs/clangd/index.rst

Modified: clang-tools-extra/trunk/docs/clangd/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd/index.rst?rev=354865&r1=354864&r2=354865&view=diff
==
--- clang-tools-extra/trunk/docs/clangd/index.rst (original)
+++ clang-tools-extra/trunk/docs/clangd/index.rst Tue Feb 26 03:08:04 2019
@@ -77,35 +77,35 @@ extension to the protocol.
 +-++--+
 | Source hover| Yes|   Yes|
 +-++--+
-| Find References | Yes|   No |
-+-++--+
-| Code Lens   | Yes|   No |
+| Find References | Yes|   Yes|
 +-++--+
 | Document Symbols| Yes|   Yes|
 +-++--+
 | Workspace Symbols   | Yes|   Yes|
 +-++--+
-| Syntax and Semantic Coloring| No |   No |
+| Code Lens   | Yes|   No |
 +-++--+
-| Code folding| No |   No |
+| Code folding| Yes|   No |
 +-++--+
-| Call hierarchy  | No |   No |
+| Extract Local Variable  | Yes|   No |
 +-++--+
-| Type hierarchy  | No |   No |
+| Extract Function/Method | Yes|   No |
 +-++--+
-| Organize Includes   | No |   No |
+| Quick Assist| Yes|   No |
++-++--+
+| Hide Method | Yes|   No |
 +-++--+
-| Quick Assist| No |   No |
+| Implement Method| Yes|   No |
 +-++--+
-| Extract Local Variable  | No |   No |
+| Gen. Getters/Setters| Yes|   No |
 +-++--+
-| Extract Function/Method | No |   No |
+| Syntax and Semantic Coloring| No |   No |
 +-++--+
-| Hide Method | No |   No |
+| Call hierarchy  | No |   No |
 +-++--+
-| Implement Method| No |   No |
+| Type hierarchy  | No |   No |
 +-++--+
-| Gen. Getters/Setters| No |   No |
+| Organize Includes   | No |   No |
 +-++--+
 
 Editor Integration


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r354878 - [clang][Index] Visit UsingDecls and generate USRs for them

2019-02-26 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Feb 26 06:23:12 2019
New Revision: 354878

URL: http://llvm.org/viewvc/llvm-project?rev=354878&view=rev
Log:
[clang][Index] Visit UsingDecls and generate USRs for them

Summary:
Add indexing of UsingDecl itself.
Also enable generation of USRs for UsingDecls, using the qualified name of the
decl.

Reviewers: ilya-biryukov, akyrtzi

Subscribers: arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58340

Modified:
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/lib/Index/IndexSymbol.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/usrs.cpp
cfe/trunk/unittests/Index/IndexTests.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=354878&r1=354877&r2=354878&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Tue Feb 26 06:23:12 2019
@@ -580,9 +580,10 @@ public:
   }
 
   bool VisitUsingDecl(const UsingDecl *D) {
+IndexCtx.handleDecl(D);
+
 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
 const NamedDecl *Parent = dyn_cast(DC);
-
 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
  D->getLexicalDeclContext());
 for (const auto *I : D->shadows())

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=354878&r1=354877&r2=354878&view=diff
==
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Tue Feb 26 06:23:12 2019
@@ -316,6 +316,10 @@ SymbolInfo index::getSymbolInfo(const De
   Info.Lang = SymbolLanguage::CXX;
   Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
   break;
+case Decl::Using:
+  Info.Kind = SymbolKind::Using;
+  Info.Lang = SymbolLanguage::CXX;
+  break;
 case Decl::Binding:
   Info.Kind = SymbolKind::Variable;
   Info.Lang = SymbolLanguage::CXX;

Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=354878&r1=354877&r2=354878&view=diff
==
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Tue Feb 26 06:23:12 2019
@@ -111,7 +111,12 @@ public:
   }
 
   void VisitUsingDecl(const UsingDecl *D) {
-IgnoreResults = true;
+VisitDeclContext(D->getDeclContext());
+Out << "@UD@";
+
+bool EmittedDeclName = !EmitDeclName(D);
+assert(EmittedDeclName && "EmitDeclName can not fail for UsingDecls");
+(void)EmittedDeclName;
   }
 
   bool ShouldGenerateLocation(const NamedDecl *D);

Modified: cfe/trunk/test/Index/usrs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.cpp?rev=354878&r1=354877&r2=354878&view=diff
==
--- cfe/trunk/test/Index/usrs.cpp (original)
+++ cfe/trunk/test/Index/usrs.cpp Tue Feb 26 06:23:12 2019
@@ -158,7 +158,7 @@ __m128 vectorOverload(__m128 f);
 // CHECK: usrs.cpp c:@NA@foo_alias
 // CHECK-NOT: foo
 // CHECK: usrs.cpp c:@NA@foo_alias2
-// CHECK-NOT: ClsB
+// CHECK: usrs.cpp c:@UD@ClsB Extent=[64:1 - 64:16]
 // CHECK: usrs.cpp c:@NA@foo_alias3
 // CHECK: usrs.cpp c:@aN Extent=[68:1 - 73:2]
 // CHECK: usrs.cpp c:usrs.cpp@aN@S@RDar9371763_Foo Extent=[69:1 - 72:2]

Modified: cfe/trunk/unittests/Index/IndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Index/IndexTests.cpp?rev=354878&r1=354877&r2=354878&view=diff
==
--- cfe/trunk/unittests/Index/IndexTests.cpp (original)
+++ cfe/trunk/unittests/Index/IndexTests.cpp Tue Feb 26 06:23:12 2019
@@ -57,6 +57,7 @@ struct TestSymbol {
   std::string QName;
   Position WrittenPos;
   Position DeclPos;
+  SymbolInfo SymInfo;
   // FIXME: add more information.
 };
 
@@ -78,6 +79,7 @@ public:
 if (!ND)
   return true;
 TestSymbol S;
+S.SymInfo = getSymbolInfo(D);
 S.QName = ND->getQualifiedNameAsString();
 S.WrittenPos = Position::fromSourceLocation(Loc, AST->getSourceManager());
 S.DeclPos =
@@ -140,6 +142,7 @@ using testing::UnorderedElementsAre;
 MATCHER_P(QName, Name, "") { return arg.QName == Name; }
 MATCHER_P(WrittenAt, Pos, "") { return arg.WrittenPos == Pos; }
 MATCHER_P(DeclAt, Pos, "") { return arg.DeclPos == Pos; }
+MATCHER_P(Kind, SymKind, "") { return arg.SymInfo.Kind == SymKind; }
 
 TEST(IndexTest, Simple) {
   auto Index = std::make_shared();
@@ -240,6 +243,20 @@ TEST(IndexTest, IndexTypeParmDecls) {
 Contains(QName("Foo::C")), Contains(QName("Foo::NoRef";
 }
 

[clang-tools-extra] r354879 - [clangd] Index UsingDecls

2019-02-26 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Feb 26 06:23:47 2019
New Revision: 354879

URL: http://llvm.org/viewvc/llvm-project?rev=354879&view=rev
Log:
[clangd] Index UsingDecls

Summary:
D58340 enables indexing of USRs, this makes sure test in clangd are
aligned with the change

Reviewers: hokein

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, jdoerfert, 
cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58341

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp

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=354879&r1=354878&r2=354879&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Tue Feb 26 
06:23:47 2019
@@ -17,6 +17,7 @@
 #include "SyncAPI.h"
 #include "TestFS.h"
 #include "TestIndex.h"
+#include "TestTU.h"
 #include "index/MemIndex.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "llvm/Support/Error.h"
@@ -2314,6 +2315,26 @@ TEST(CompletionTest, WorksWithNullType)
   EXPECT_THAT(R.Completions, ElementsAre(Named("loopVar")));
 }
 
+TEST(CompletionTest, UsingDecl) {
+  const char *Header(R"cpp(
+void foo(int);
+namespace std {
+  using ::foo;
+})cpp");
+  const char *Source(R"cpp(
+void bar() {
+  std::^;
+})cpp");
+  auto Index = TestTU::withHeaderCode(Header).index();
+  clangd::CodeCompleteOptions Opts;
+  Opts.Index = Index.get();
+  Opts.AllScopes = true;
+  auto R = completions(Source, {}, Opts);
+  EXPECT_THAT(R.Completions,
+  ElementsAre(AllOf(Scope("std::"), Named("foo"),
+Kind(CompletionItemKind::Reference;
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp?rev=354879&r1=354878&r2=354879&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp Tue Feb 26 
06:23:47 2019
@@ -368,9 +368,6 @@ TEST_F(DocumentSymbolsTest, BasicSymbols
   // Namespace alias
   namespace baz = bar;
 
-  // FIXME: using declaration is not supported as the IndexAction will 
ignore
-  // implicit declarations (the implicit using shadow declaration) by 
default,
-  // and there is no way to customize this behavior at the moment.
   using bar::v2;
   } // namespace foo
 )");
@@ -415,7 +412,7 @@ TEST_F(DocumentSymbolsTest, BasicSymbols
   Children(,
  AllOf(WithName("baz"), WithKind(SymbolKind::Namespace),
Children()),
- AllOf(WithName("v2"), 
WithKind(SymbolKind::Variable}));
+ AllOf(WithName("v2"), 
WithKind(SymbolKind::Namespace}));
 }
 
 TEST_F(DocumentSymbolsTest, DeclarationDefinition) {

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=354879&r1=354878&r2=354879&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Tue Feb 
26 06:23:47 2019
@@ -331,9 +331,6 @@ TEST_F(SymbolCollectorTest, CollectSymbo
 // Namespace alias
 namespace baz = bar;
 
-// FIXME: using declaration is not supported as the IndexAction will ignore
-// implicit declarations (the implicit using shadow declaration) by 
default,
-// and there is no way to customize this behavior at the moment.
 using bar::v2;
 } // namespace foo
   )";
@@ -360,6 +357,7 @@ TEST_F(SymbolCollectorTest, CollectSymbo
AllOf(QName("foo::int32_t"), ForCodeCompletion(true)),
AllOf(QName("foo::v1"), ForCodeCompletion(true)),
AllOf(QName("foo::bar::v2"), ForCodeCompletion(true)),
+   AllOf(QName("foo::v2"), ForCodeCompletion(true)),
AllOf(QName("foo::baz"), ForCodeCompletion(true))}));
 }
 
@@ -1149,6 +1147,16 @@ TEST_F(SymbolCollectorTest, Implementati
   AllOf(QName("Public"), Not(ImplementationDetail();
 }
 
+TEST_F(SymbolCollectorTest

r355668 - [clang][Index] Mark references from Constructors and Destructors to class as NameReference

2019-03-08 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Mar  8 00:30:20 2019
New Revision: 355668

URL: http://llvm.org/viewvc/llvm-project?rev=355668&view=rev
Log:
[clang][Index] Mark references from Constructors and Destructors to class as 
NameReference

Summary:
In current indexing logic we get references to class itself when we see
a constructor/destructor which is only syntactically true. Semantically
this information is not correct. This patch marks that reference as
NameReference to let clients deal with it.

Reviewers: akyrtzi, gribozavr, nathawes, benlangmuir

Reviewed By: gribozavr, nathawes

Subscribers: nathawes, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58814

Modified:
cfe/trunk/include/clang/Index/IndexSymbol.h
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/lib/Index/IndexSymbol.cpp
cfe/trunk/lib/Index/IndexingContext.cpp
cfe/trunk/test/Index/Core/index-source.cpp
cfe/trunk/unittests/Index/IndexTests.cpp

Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=355668&r1=355667&r2=355668&view=diff
==
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Fri Mar  8 00:30:20 2019
@@ -118,8 +118,12 @@ enum class SymbolRole : uint32_t {
   RelationContainedBy = 1 << 17,
   RelationIBTypeOf = 1 << 18,
   RelationSpecializationOf = 1 << 19,
+
+  // Symbol only references the name of the object as written. For example, a
+  // constructor references the class declaration using that role.
+  NameReference = 1 << 20,
 };
-static const unsigned SymbolRoleBitNum = 20;
+static const unsigned SymbolRoleBitNum = 21;
 typedef unsigned SymbolRoleSet;
 
 /// Represents a relation to another symbol for a symbol occurrence.

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=355668&r1=355667&r2=355668&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Fri Mar  8 00:30:20 2019
@@ -247,7 +247,8 @@ public:
 
 if (const CXXConstructorDecl *Ctor = dyn_cast(D)) {
   IndexCtx.handleReference(Ctor->getParent(), Ctor->getLocation(),
-   Ctor->getParent(), Ctor->getDeclContext());
+   Ctor->getParent(), Ctor->getDeclContext(),
+   (unsigned)SymbolRole::NameReference);
 
   // Constructor initializers.
   for (const auto *Init : Ctor->inits()) {
@@ -263,7 +264,8 @@ public:
   if (auto TypeNameInfo = Dtor->getNameInfo().getNamedTypeInfo()) {
 IndexCtx.handleReference(Dtor->getParent(),
  TypeNameInfo->getTypeLoc().getBeginLoc(),
- Dtor->getParent(), Dtor->getDeclContext());
+ Dtor->getParent(), Dtor->getDeclContext(),
+ (unsigned)SymbolRole::NameReference);
   }
 } else if (const auto *Guide = dyn_cast(D)) {
   IndexCtx.handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(),

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=355668&r1=355667&r2=355668&view=diff
==
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Fri Mar  8 00:30:20 2019
@@ -396,6 +396,7 @@ bool index::applyForEachSymbolRoleInterr
   APPLY_FOR_ROLE(RelationContainedBy);
   APPLY_FOR_ROLE(RelationIBTypeOf);
   APPLY_FOR_ROLE(RelationSpecializationOf);
+  APPLY_FOR_ROLE(NameReference);
 
 #undef APPLY_FOR_ROLE
 
@@ -438,6 +439,7 @@ void index::printSymbolRoles(SymbolRoleS
 case SymbolRole::RelationContainedBy: OS << "RelCont"; break;
 case SymbolRole::RelationIBTypeOf: OS << "RelIBType"; break;
 case SymbolRole::RelationSpecializationOf: OS << "RelSpecialization"; 
break;
+case SymbolRole::NameReference: OS << "NameReference"; break;
 }
   });
 }

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=355668&r1=355667&r2=355668&view=diff
==
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Fri Mar  8 00:30:20 2019
@@ -332,6 +332,7 @@ static bool shouldReportOccurrenceForSys
   case SymbolRole::RelationCalledBy:
   case SymbolRole::RelationContainedBy:
   case SymbolRole::RelationSpecializationOf:
+  case SymbolRole::NameReference:
 return true;
   }
   llvm_unreachable("Unsupported SymbolRole value!");

Modified: c

[clang-tools-extra] r355669 - [clangd] Adjust compile commands to be applicable for tooling

2019-03-08 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Mar  8 00:38:25 2019
New Revision: 355669

URL: http://llvm.org/viewvc/llvm-project?rev=355669&view=rev
Log:
[clangd] Adjust compile commands to be applicable for tooling

Summary:
As can be seen in 
https://github.com/llvm-mirror/clang/blob/master/lib/Tooling/Tooling.cpp#L385
clang tool invocations adjust commands normally like this. In clangd we have
different code paths for invoking a frontend action(preamble builds, ast builds,
background index, clangd-indexer) they all work on the same 
GlobalCompilationDatabase
abstraction, but later on are subject to different modifications.

This patch makes sure all of the clangd actions make use of the same compile
commands before invocation.

Enables background-index to work on chromium codebase(since they had dependency
file output in their compile commands).

Reviewers: gribozavr, hokein

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, jdoerfert, 
cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59086

Modified:
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=355669&r1=355668&r2=355669&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Fri Mar  8 
00:38:25 2019
@@ -21,11 +21,17 @@ namespace {
 
 void adjustArguments(tooling::CompileCommand &Cmd,
  llvm::StringRef ResourceDir) {
-  // Strip plugin related command line arguments. Clangd does
-  // not support plugins currently. Therefore it breaks if
-  // compiler tries to load plugins.
-  Cmd.CommandLine =
-  tooling::getStripPluginsAdjuster()(Cmd.CommandLine, Cmd.Filename);
+  tooling::ArgumentsAdjuster ArgsAdjuster = tooling::combineAdjusters(
+  // clangd should not write files to disk, including dependency files
+  // requested on the command line.
+  tooling::getClangStripDependencyFileAdjuster(),
+  // Strip plugin related command line arguments. Clangd does
+  // not support plugins currently. Therefore it breaks if
+  // compiler tries to load plugins.
+  tooling::combineAdjusters(tooling::getStripPluginsAdjuster(),
+tooling::getClangSyntaxOnlyAdjuster()));
+
+  Cmd.CommandLine = ArgsAdjuster(Cmd.CommandLine, Cmd.Filename);
   // Inject the resource dir.
   // FIXME: Don't overwrite it if it's already there.
   if (!ResourceDir.empty())

Modified: 
clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp?rev=355669&r1=355668&r2=355669&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp 
Fri Mar  8 00:38:25 2019
@@ -16,15 +16,18 @@
 namespace clang {
 namespace clangd {
 namespace {
+using ::testing::AllOf;
+using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::EndsWith;
+using ::testing::Not;
 
 TEST(GlobalCompilationDatabaseTest, FallbackCommand) {
   DirectoryBasedGlobalCompilationDatabase DB(None);
   auto Cmd = DB.getFallbackCommand(testPath("foo/bar.cc"));
   EXPECT_EQ(Cmd.Directory, testPath("foo"));
-  EXPECT_THAT(Cmd.CommandLine, ElementsAre(
-EndsWith("clang"), testPath("foo/bar.cc")));
+  EXPECT_THAT(Cmd.CommandLine,
+  ElementsAre(EndsWith("clang"), testPath("foo/bar.cc")));
   EXPECT_EQ(Cmd.Output, "");
 
   // .h files have unknown language, so they are parsed liberally as obj-c++.
@@ -65,16 +68,18 @@ protected:
 
 TEST_F(OverlayCDBTest, GetCompileCommand) {
   OverlayCDB CDB(Base.get(), {}, std::string(""));
-  EXPECT_EQ(CDB.getCompileCommand(testPath("foo.cc")),
-Base->getCompileCommand(testPath("foo.cc")));
+  EXPECT_THAT(CDB.getCompileCommand(testPath("foo.cc"))->CommandLine,
+  AllOf(Contains(testPath("foo.cc")), Contains("-DA=1")));
   EXPECT_EQ(CDB.getCompileCommand(testPath("missing.cc")), llvm::None);
 
   auto Override = cmd(testPath("foo.cc"), "-DA=3");
   CDB.setCompileCommand(testPath("foo.cc"), Override);
-  EXPECT_EQ(CDB.getCompileCommand(testPath("foo.cc")), Override);
+  EXPECT_THAT(CDB.getCompileCommand(testPath("foo.cc"))->CommandLine,
+  Contains("-DA=3"));
   EXPECT_EQ(CDB.getCompileCommand(testPath("missing.cc")), llvm::None);
   CDB.setCompileCommand(testPath("missing.cc"), Override);
-  EXPECT_EQ(CDB.getCompileCommand(testPath("missing.cc")), Override);
+  

r355678 - [clang][Tooling] Delete dots and dotdots when generating absolute paths

2019-03-08 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Mar  8 01:42:04 2019
New Revision: 355678

URL: http://llvm.org/viewvc/llvm-project?rev=355678&view=rev
Log:
[clang][Tooling] Delete dots and dotdots when generating absolute paths

Summary:
GetAllFiles interface returns absolute paths, but keeps dots and dot
dots. This patch makes those paths canonical by deleting them.

Reviewers: hokein

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59079

Modified:
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=355678&r1=355677&r2=355678&view=diff
==
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Fri Mar  8 01:42:04 2019
@@ -370,6 +370,7 @@ bool JSONCompilationDatabase::parse(std:
   SmallString<128> AbsolutePath(
   Directory->getValue(DirectoryStorage));
   llvm::sys::path::append(AbsolutePath, FileName);
+  llvm::sys::path::remove_dots(AbsolutePath, /*remove_dot_dot=*/ true);
   llvm::sys::path::native(AbsolutePath, NativeFilePath);
 } else {
   llvm::sys::path::native(FileName, NativeFilePath);

Modified: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp?rev=355678&r1=355677&r2=355678&view=diff
==
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp Fri Mar  8 01:42:04 
2019
@@ -88,12 +88,17 @@ TEST(JSONCompilationDatabase, GetAllFile
   expected_files.push_back(PathStorage.str());
   llvm::sys::path::native("//net/dir/file2", PathStorage);
   expected_files.push_back(PathStorage.str());
+  llvm::sys::path::native("//net/file1", PathStorage);
+  expected_files.push_back(PathStorage.str());
   EXPECT_EQ(expected_files,
 getAllFiles("[{\"directory\":\"//net/dir\","
 "\"command\":\"command\","
 "\"file\":\"file1\"},"
 " {\"directory\":\"//net/dir\","
 "\"command\":\"command\","
+"\"file\":\"../file1\"},"
+" {\"directory\":\"//net/dir\","
+"\"command\":\"command\","
 "\"file\":\"file2\"}]",
 ErrorMessage, JSONCommandLineSyntax::Gnu))
   << ErrorMessage;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r355679 - [clangd] Make sure constructors do not reference class

2019-03-08 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Mar  8 01:54:37 2019
New Revision: 355679

URL: http://llvm.org/viewvc/llvm-project?rev=355679&view=rev
Log:
[clangd] Make sure constructors do not reference class

Reviewers: gribozavr

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58815

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=355679&r1=355678&r2=355679&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri Mar  8 01:54:37 2019
@@ -15,6 +15,7 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexSymbol.h"
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
 #include "llvm/Support/Path.h"
@@ -154,6 +155,10 @@ public:
   llvm::ArrayRef Relations,
   SourceLocation Loc,
   index::IndexDataConsumer::ASTNodeInfo ASTNode) override {
+// Skip non-semantic references.
+if (Roles & static_cast(index::SymbolRole::NameReference))
+  return true;
+
 if (Loc == SearchedLocation) {
   auto IsImplicitExpr = [](const Expr *E) {
 if (!E)

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=355679&r1=355678&r2=355679&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Fri Mar  8 
01:54:37 2019
@@ -211,7 +211,7 @@ getTokenLocation(SourceLocation TokLoc,
 // the first seen declaration as canonical declaration is not a good enough
 // heuristic.
 bool isPreferredDeclaration(const NamedDecl &ND, index::SymbolRoleSet Roles) {
-  const auto& SM = ND.getASTContext().getSourceManager();
+  const auto &SM = ND.getASTContext().getSourceManager();
   return (Roles & static_cast(index::SymbolRole::Definition)) &&
  isa(&ND) &&
  !SM.isWrittenInMainFile(SM.getExpansionLoc(ND.getLocation()));
@@ -305,6 +305,10 @@ bool SymbolCollector::handleDeclOccurenc
Decl::FriendObjectKind::FOK_None) &&
   !(Roles & static_cast(index::SymbolRole::Definition)))
 return true;
+  // Skip non-semantic references, we should start processing these when we
+  // decide to implement renaming with index support.
+  if ((Roles & static_cast(index::SymbolRole::NameReference)))
+return true;
   // A declaration created for a friend declaration should not be used as the
   // canonical declaration in the index. Use OrigD instead, unless we've 
already
   // picked a replacement for D

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=355679&r1=355678&r2=355679&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Fri Mar  8 01:54:37 
2019
@@ -1337,6 +1337,15 @@ TEST(FindReferences, WithinAST) {
 }
   )cpp",
 
+  R"cpp(// Constructor
+struct Foo {
+  [[F^oo]](int);
+};
+void foo() {
+  Foo f = [[Foo]](42);
+}
+  )cpp",
+
   R"cpp(// Typedef
 typedef int [[Foo]];
 int main() {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r355681 - [clangd] Remove ./ and ../ in the file paths

2019-03-08 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Mar  8 01:57:33 2019
New Revision: 355681

URL: http://llvm.org/viewvc/llvm-project?rev=355681&view=rev
Log:
[clangd] Remove ./ and ../ in the file paths

Reviewers: hokein

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59084

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=355681&r1=355680&r2=355681&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Fri Mar  8 01:57:33 2019
@@ -121,6 +121,7 @@ llvm::SmallString<128> getAbsolutePath(c
   } else {
 AbsolutePath = Cmd.Directory;
 llvm::sys::path::append(AbsolutePath, Cmd.Filename);
+llvm::sys::path::remove_dots(AbsolutePath, true);
   }
   return AbsolutePath;
 }

Modified: clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp?rev=355681&r1=355680&r2=355681&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp Fri Mar  
8 01:57:33 2019
@@ -44,12 +44,14 @@ public:
   llvm::Error storeShard(llvm::StringRef ShardIdentifier,
  IndexFileOut Shard) const override {
 std::lock_guard Lock(StorageMu);
+AccessedPaths.insert(ShardIdentifier);
 Storage[ShardIdentifier] = llvm::to_string(Shard);
 return llvm::Error::success();
   }
   std::unique_ptr
   loadShard(llvm::StringRef ShardIdentifier) const override {
 std::lock_guard Lock(StorageMu);
+AccessedPaths.insert(ShardIdentifier);
 if (Storage.find(ShardIdentifier) == Storage.end()) {
   return nullptr;
 }
@@ -62,6 +64,8 @@ public:
 CacheHits++;
 return llvm::make_unique(std::move(*IndexFile));
   }
+
+  mutable llvm::StringSet<> AccessedPaths;
 };
 
 class BackgroundIndexTest : public ::testing::Test {
@@ -428,5 +432,34 @@ TEST_F(BackgroundIndexTest, ShardStorage
   Contains(AllOf(Named("new_func"), Declared(), Not(Defined();
 }
 
+TEST_F(BackgroundIndexTest, NoDotsInAbsPath) {
+  MockFSProvider FS;
+  llvm::StringMap Storage;
+  size_t CacheHits = 0;
+  MemoryShardStorage MSS(Storage, CacheHits);
+  OverlayCDB CDB(/*Base=*/nullptr);
+  BackgroundIndex Idx(Context::empty(), FS, CDB,
+  [&](llvm::StringRef) { return &MSS; });
+
+  tooling::CompileCommand Cmd;
+  FS.Files[testPath("root/A.cc")] = "";
+  Cmd.Filename = "../A.cc";
+  Cmd.Directory = testPath("root/build");
+  Cmd.CommandLine = {"clang++", "../A.cc"};
+  CDB.setCompileCommand(testPath("root/build/../A.cc"), Cmd);
+
+  FS.Files[testPath("root/B.cc")] = "";
+  Cmd.Filename = "./B.cc";
+  Cmd.Directory = testPath("root");
+  Cmd.CommandLine = {"clang++", "./B.cc"};
+  CDB.setCompileCommand(testPath("root/./B.cc"), Cmd);
+
+  ASSERT_TRUE(Idx.blockUntilIdleForTest());
+  for (llvm::StringRef AbsPath : MSS.AccessedPaths.keys()) {
+EXPECT_FALSE(AbsPath.contains("./")) << AbsPath;
+EXPECT_FALSE(AbsPath.contains("../")) << AbsPath;
+  }
+}
+
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r355683 - [clang][Index] Fix msan failure

2019-03-08 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Mar  8 02:18:40 2019
New Revision: 355683

URL: http://llvm.org/viewvc/llvm-project?rev=355683&view=rev
Log:
[clang][Index] Fix msan failure

Modified:
cfe/trunk/unittests/Index/IndexTests.cpp

Modified: cfe/trunk/unittests/Index/IndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Index/IndexTests.cpp?rev=355683&r1=355682&r2=355683&view=diff
==
--- cfe/trunk/unittests/Index/IndexTests.cpp (original)
+++ cfe/trunk/unittests/Index/IndexTests.cpp Fri Mar  8 02:18:40 2019
@@ -91,10 +91,15 @@ public:
 return true;
   }
 
-  bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *,
-SymbolRoleSet, SourceLocation) override {
+  bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI,
+SymbolRoleSet Roles, SourceLocation Loc) override {
 TestSymbol S;
+S.SymInfo = getSymbolInfoForMacro(*MI);
 S.QName = Name->getName();
+S.WrittenPos = Position::fromSourceLocation(Loc, AST->getSourceManager());
+S.DeclPos = Position::fromSourceLocation(MI->getDefinitionLoc(),
+ AST->getSourceManager());
+S.Roles = Roles;
 Symbols.push_back(std::move(S));
 return true;
   }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r355820 - [clangd] Respect Origin option in createStaticIndexingAction

2019-03-11 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Mar 11 04:01:14 2019
New Revision: 355820

URL: http://llvm.org/viewvc/llvm-project?rev=355820&view=rev
Log:
[clangd] Respect Origin option in createStaticIndexingAction

Summary:
Currently createStaticIndexingAction always set Origin to Static, which
makes it hard to change it later on by different indexers(One needs to go over
each symbol making a new copy).

This patch changes that behavior to rather respect it if set by user.

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59205

Modified:
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/index/IndexAction.h

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=355820&r1=355819&r2=355820&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Mon Mar 11 04:01:14 
2019
@@ -183,7 +183,8 @@ std::unique_ptr createSt
   index::IndexingOptions::SystemSymbolFilterKind::All;
   Opts.CollectIncludePath = true;
   Opts.CountReferences = true;
-  Opts.Origin = SymbolOrigin::Static;
+  if (Opts.Origin == SymbolOrigin::Unknown)
+Opts.Origin = SymbolOrigin::Static;
   Opts.StoreAllDocumentation = false;
   if (RefsCallback != nullptr) {
 Opts.RefFilter = RefKind::All;

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.h?rev=355820&r1=355819&r2=355820&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.h (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.h Mon Mar 11 04:01:14 2019
@@ -22,7 +22,7 @@ namespace clangd {
 //   - include paths are always collected, and canonicalized appropriately
 //   - references are always counted
 //   - all references are collected (if RefsCallback is non-null)
-//   - the symbol origin is always Static
+//   - the symbol origin is set to Static if not specified by caller
 std::unique_ptr createStaticIndexingAction(
 SymbolCollector::Options Opts,
 std::function SymbolsCallback,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356032 - [clangd] Default initialize SymInfo

2019-03-13 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Mar 13 01:42:15 2019
New Revision: 356032

URL: http://llvm.org/viewvc/llvm-project?rev=356032&view=rev
Log:
[clangd] Default initialize SymInfo

Modified:
clang-tools-extra/trunk/clangd/index/Symbol.h

Modified: clang-tools-extra/trunk/clangd/index/Symbol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Symbol.h?rev=356032&r1=356031&r2=356032&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Symbol.h (original)
+++ clang-tools-extra/trunk/clangd/index/Symbol.h Wed Mar 13 01:42:15 2019
@@ -37,7 +37,7 @@ struct Symbol {
   /// The ID of the symbol.
   SymbolID ID;
   /// The symbol information, like symbol kind.
-  index::SymbolInfo SymInfo;
+  index::SymbolInfo SymInfo = index::SymbolInfo();
   /// The unqualified name of the symbol, e.g. "bar" (for ns::bar).
   llvm::StringRef Name;
   /// The containing namespace. e.g. "" (global), "ns::" (top-level namespace).


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356125 - [clangd] Store explicit template specializations in index for code navigation purposes

2019-03-14 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Mar 14 01:35:17 2019
New Revision: 356125

URL: http://llvm.org/viewvc/llvm-project?rev=356125&view=rev
Log:
[clangd] Store explicit template specializations in index for code navigation 
purposes

Summary:
This introduces ~4k new symbols, and ~10k refs for LLVM. We need that
information for providing better code navigation support:
- When references for a class template is requested, we should return these 
specializations as well.
- When children of a specialization is requested, we should be able to query 
for those symbols(instead of just class template)

Number of symbols: 378574 -> 382784
Number of refs: 5098857 -> 5110689

Reviewers: hokein, gribozavr

Reviewed By: gribozavr

Subscribers: nridge, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, 
jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59083

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
clang-tools-extra/trunk/unittests/clangd/DexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=356125&r1=356124&r2=356125&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Mar 14 01:35:17 2019
@@ -1510,6 +1510,13 @@ private:
   }
 };
 
+template  bool isExplicitTemplateSpecialization(const NamedDecl &ND) {
+  if (const auto *TD = dyn_cast(&ND))
+if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return true;
+  return false;
+}
+
 } // namespace
 
 clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const {
@@ -1603,6 +1610,13 @@ bool isIndexedForCodeCompletion(const Na
 };
 return false;
   };
+  // We only complete symbol's name, which is the same as the name of the
+  // *primary* template in case of template specializations.
+  if (isExplicitTemplateSpecialization(ND) ||
+  isExplicitTemplateSpecialization(ND) ||
+  isExplicitTemplateSpecialization(ND))
+return false;
+
   if (InTopLevelScope(ND))
 return true;
 

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=356125&r1=356124&r2=356125&view=diff
==
--- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Thu Mar 14 01:35:17 2019
@@ -11,6 +11,7 @@
 #include "Logger.h"
 #include "Quality.h"
 #include "Trace.h"
+#include "clang/Index/IndexSymbol.h"
 
 namespace clang {
 namespace clangd {
@@ -37,6 +38,15 @@ bool MemIndex::fuzzyFind(
   for (const auto Pair : Index) {
 const Symbol *Sym = Pair.second;
 
+// FIXME: Enable fuzzy find on template specializations once we start
+// storing template arguments in the name. Currently we only store name for
+// class template, which would cause duplication in the results.
+if (Sym->SymInfo.Properties &
+(static_cast(
+ index::SymbolProperty::TemplateSpecialization) |
+ static_cast(
+ index::SymbolProperty::TemplatePartialSpecialization)))
+  continue;
 // Exact match against all possible scopes.
 if (!Req.AnyScope && !llvm::is_contained(Req.Scopes, Sym->Scope))
   continue;

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=356125&r1=356124&r2=356125&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Thu Mar 14 
01:35:17 2019
@@ -221,13 +221,6 @@ RefKind toRefKind(index::SymbolRoleSet R
   return static_cast(static_cast(RefKind::All) & Roles);
 }
 
-template  bool explicitTemplateSpecialization(const NamedDecl &ND) {
-  if (const auto *TD = dyn_cast(&ND))
-if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
-  return true;
-  return false;
-}
-
 } // namespace
 
 SymbolCollector::SymbolCollector(Options Opts) : Opts(std::move(Opts)) {}
@@ -279,10 +272,6 @@ bool SymbolCollector::shouldCollectSymbo
 if (!isa(DeclCtx))
   return false;
   }
-  if (explicitTemplateSpecialization(ND) ||
-  explicitTemplateSpecialization(ND) ||
-  explicitTemplateSpecialization(ND))
-return false;
 
   // Avoid indexing inter

[clang-tools-extra] r356445 - [clangd] Add support for type hierarchy (super types only for now)

2019-03-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Mar 19 02:27:04 2019
New Revision: 356445

URL: http://llvm.org/viewvc/llvm-project?rev=356445&view=rev
Log:
[clangd] Add support for type hierarchy (super types only for now)

Summary:
Patch by Nathan Ridge(@nridge)!

This is an LSP extension proposed here:
https://github.com/Microsoft/vscode-languageserver-node/pull/426

An example client implementation can be found here:
https://github.com/theia-ide/theia/pull/3802

Reviewers: kadircet, sammccall

Reviewed By: kadircet

Subscribers: jdoerfert, sammccall, cfe-commits, mgorny, dschaefer, simark, 
ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet

Tags: #clang

Differential Revision: https://reviews.llvm.org/D56370

Added:
clang-tools-extra/trunk/test/clangd/type-hierarchy.test
clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/FindSymbols.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/XRefs.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.h
clang-tools-extra/trunk/test/clangd/initialize-params.test
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/Matchers.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=356445&r1=356444&r2=356445&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Mar 19 02:27:04 2019
@@ -368,6 +368,7 @@ void ClangdLSPServer::onInitialize(const
   {ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND,
ExecuteCommandParams::CLANGD_APPLY_TWEAK}},
  }},
+{"typeHierarchyProvider", true},
 );
 }
 
@@ -806,6 +807,13 @@ void ClangdLSPServer::onHover(const Text
 std::move(Reply));
 }
 
+void ClangdLSPServer::onTypeHierarchy(
+const TypeHierarchyParams &Params,
+Callback> Reply) {
+  Server->typeHierarchy(Params.textDocument.uri.file(), Params.position,
+Params.resolve, Params.direction, std::move(Reply));
+}
+
 void ClangdLSPServer::applyConfiguration(
 const ConfigurationSettings &Settings) {
   // Per-file update to the compilation database.
@@ -885,6 +893,7 @@ ClangdLSPServer::ClangdLSPServer(class T
   MsgHandler->bind("workspace/didChangeWatchedFiles", 
&ClangdLSPServer::onFileEvent);
   MsgHandler->bind("workspace/didChangeConfiguration", 
&ClangdLSPServer::onChangeConfiguration);
   MsgHandler->bind("textDocument/symbolInfo", &ClangdLSPServer::onSymbolInfo);
+  MsgHandler->bind("textDocument/typeHierarchy", 
&ClangdLSPServer::onTypeHierarchy);
   // clang-format on
 }
 

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=356445&r1=356444&r2=356445&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Tue Mar 19 02:27:04 2019
@@ -93,6 +93,8 @@ private:
   void onRename(const RenameParams &, Callback);
   void onHover(const TextDocumentPositionParams &,
Callback>);
+  void onTypeHierarchy(const TypeHierarchyParams &,
+   Callback>);
   void onChangeConfiguration(const DidChangeConfigurationParams &);
   void onSymbolInfo(const TextDocumentPositionParams &,
 Callback>);

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=356445&r1=356444&r2=356445&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Mar 19 02:27:04 2019
@@ -362,9 +362,8 @@ void ClangdServer::enumerateTweaks(PathR
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
   Callback CB) {
-  auto Action = [Sel](decltype(CB) CB, std::string File,
-std::string TweakID,
-Expected InpAST) {
+  auto Action = [Sel](decltype(CB) CB, std::string File, std::string TweakID,
+  Expected InpAST) {
 if (!InpA

r356541 - [clangd] Print arguments in template specializations

2019-03-20 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Mar 20 02:43:38 2019
New Revision: 356541

URL: http://llvm.org/viewvc/llvm-project?rev=356541&view=rev
Log:
[clangd] Print arguments in template specializations

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59354

Modified:
cfe/trunk/lib/AST/TypePrinter.cpp

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=356541&r1=356540&r2=356541&view=diff
==
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Wed Mar 20 02:43:38 2019
@@ -1632,6 +1632,21 @@ static const TemplateArgument &getArgume
   return A.getArgument();
 }
 
+static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
+  llvm::raw_ostream &OS) {
+  A.print(PP, OS);
+}
+
+static void printArgument(const TemplateArgumentLoc &A,
+  const PrintingPolicy &PP, llvm::raw_ostream &OS) {
+  const auto &Kind = A.getArgument().getKind();
+  assert(Kind != TemplateArgument::Null &&
+ "TemplateArgumentKind can not be null!");
+  if (Kind == TemplateArgument::ArgKind::Type)
+return A.getTypeSourceInfo()->getType().print(OS, PP);
+  return A.getArgument().print(PP, OS);
+}
+
 template
 static void printTo(raw_ostream &OS, ArrayRef Args,
 const PrintingPolicy &Policy, bool SkipBrackets) {
@@ -1653,7 +1668,7 @@ static void printTo(raw_ostream &OS, Arr
 } else {
   if (!FirstArg)
 OS << Comma;
-  Argument.print(Policy, ArgOS);
+  printArgument(Arg, Policy, ArgOS);
 }
 StringRef ArgString = ArgOS.str();
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r356541 - [clangd] Print arguments in template specializations

2019-03-20 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Mar 20 02:43:38 2019
New Revision: 356541

URL: http://llvm.org/viewvc/llvm-project?rev=356541&view=rev
Log:
[clangd] Print arguments in template specializations

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59354

Modified:
clang-tools-extra/trunk/clangd/AST.cpp
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
clang-tools-extra/trunk/unittests/clangd/DexTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/AST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=356541&r1=356540&r2=356541&view=diff
==
--- clang-tools-extra/trunk/clangd/AST.cpp (original)
+++ clang-tools-extra/trunk/clangd/AST.cpp Wed Mar 20 02:43:38 2019
@@ -11,9 +11,12 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/TemplateBase.h"
+#include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Index/USRGeneration.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ScopedPrinter.h"
 
@@ -50,6 +53,22 @@ SourceLocation findNameLoc(const clang::
   return SM.getSpellingLoc(D->getLocation());
 }
 
+static llvm::Optional>
+getTemplateSpecializationArgLocs(const NamedDecl &ND) {
+  if (auto *Func = llvm::dyn_cast(&ND)) {
+if (auto *Args = Func->getTemplateSpecializationArgsAsWritten())
+  return Args->arguments();
+  } else if (auto *Cls =
+ llvm::dyn_cast(&ND)) {
+if (auto *Args = Cls->getTemplateArgsAsWritten())
+  return Args->arguments();
+  } else if (auto *Var = llvm::dyn_cast(&ND))
+return Var->getTemplateArgsInfo().arguments();
+  // We return None for ClassTemplateSpecializationDecls because it does not
+  // contain TemplateArgumentLoc information.
+  return llvm::None;
+}
+
 std::string printQualifiedName(const NamedDecl &ND) {
   std::string QName;
   llvm::raw_string_ostream OS(QName);
@@ -60,6 +79,19 @@ std::string printQualifiedName(const Nam
   // namespaces to query: the preamble doesn't have a dedicated list.
   Policy.SuppressUnwrittenScope = true;
   ND.printQualifiedName(OS, Policy);
+  if (auto Args = getTemplateSpecializationArgLocs(ND))
+printTemplateArgumentList(OS, *Args, Policy);
+  else if (auto *Cls = llvm::dyn_cast(&ND)) {
+if (auto STL = Cls->getTypeAsWritten()
+   ->getTypeLoc()
+   .getAs()) {
+  llvm::SmallVector ArgLocs;
+  ArgLocs.reserve(STL.getNumArgs());
+  for (unsigned I = 0; I < STL.getNumArgs(); ++I)
+ArgLocs.push_back(STL.getArgLoc(I));
+  printTemplateArgumentList(OS, ArgLocs, Policy);
+}
+  }
   OS.flush();
   assert(!StringRef(QName).startswith("::"));
   return QName;

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=356541&r1=356540&r2=356541&view=diff
==
--- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Wed Mar 20 02:43:38 2019
@@ -38,15 +38,6 @@ bool MemIndex::fuzzyFind(
   for (const auto Pair : Index) {
 const Symbol *Sym = Pair.second;
 
-// FIXME: Enable fuzzy find on template specializations once we start
-// storing template arguments in the name. Currently we only store name for
-// class template, which would cause duplication in the results.
-if (Sym->SymInfo.Properties &
-(static_cast(
- index::SymbolProperty::TemplateSpecialization) |
- static_cast(
- index::SymbolProperty::TemplatePartialSpecialization)))
-  continue;
 // Exact match against all possible scopes.
 if (!Req.AnyScope && !llvm::is_contained(Req.Scopes, Sym->Scope))
   continue;

Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=356541&r1=356540&r2=356541&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Wed Mar 20 02:43:38 2019
@@ -86,15 +86,6 @@ void Dex::buildIndex() {
   llvm::DenseMap> TempInvertedIndex;
   for (DocID SymbolRank = 0; SymbolRank < Symbols.size(); ++SymbolRank) {
 const auto *Sym = Symbols[SymbolRank];
-// FIXME: Enable fuzzy find on template specializations once we start
-// storing tem

[clang-tools-extra] r358273 - [clangd] Add TemplateArgumentList into Symbol

2019-04-12 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Apr 12 03:09:24 2019
New Revision: 358273

URL: http://llvm.org/viewvc/llvm-project?rev=358273&view=rev
Log:
[clangd] Add TemplateArgumentList into Symbol

Summary:
Part of re-landing rC356541 with D59599. Changes the way we store
template arguments, previous patch was storing them inside Name field of Symbol.
Which was violating the assumption:
```Symbol::Scope+Symbol::Name == clang::clangd::printQualifiedName```
which was made in multiple places inside codebase. This patch instead moves
those arguments into their own field. Currently the field is meant to be
human-readable, can be made structured if need be.

Reviewers: ioeric, ilya-biryukov, gribozavr

Subscribers: MaskRay, jkorous, arphaman, jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59640

Modified:
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/Symbol.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=358273&r1=358272&r2=358273&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Fri Apr 12 03:09:24 
2019
@@ -282,6 +282,7 @@ void writeSymbol(const Symbol &Sym, cons
   OS.write(static_cast(Sym.SymInfo.Lang));
   writeVar(Strings.index(Sym.Name), OS);
   writeVar(Strings.index(Sym.Scope), OS);
+  writeVar(Strings.index(Sym.TemplateSpecializationArgs), OS);
   writeLocation(Sym.Definition, Strings, OS);
   writeLocation(Sym.CanonicalDeclaration, Strings, OS);
   writeVar(Sym.References, OS);
@@ -309,6 +310,7 @@ Symbol readSymbol(Reader &Data, llvm::Ar
   Sym.SymInfo.Lang = static_cast(Data.consume8());
   Sym.Name = Data.consumeString(Strings);
   Sym.Scope = Data.consumeString(Strings);
+  Sym.TemplateSpecializationArgs = Data.consumeString(Strings);
   Sym.Definition = readLocation(Data, Strings);
   Sym.CanonicalDeclaration = readLocation(Data, Strings);
   Sym.References = Data.consumeVar();

Modified: clang-tools-extra/trunk/clangd/index/Symbol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Symbol.h?rev=358273&r1=358272&r2=358273&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Symbol.h (original)
+++ clang-tools-extra/trunk/clangd/index/Symbol.h Fri Apr 12 03:09:24 2019
@@ -63,6 +63,10 @@ struct Symbol {
   /// candidate list. For example, "(X x, Y y) const" is a function signature.
   /// Only set when the symbol is indexed for completion.
   llvm::StringRef Signature;
+  /// Argument list in human-readable format, will be displayed to help
+  /// disambiguate between different specializations of a template. Empty for
+  /// non-specializations. Example: ""
+  llvm::StringRef TemplateSpecializationArgs;
   /// What to insert when completing this symbol, after the symbol name.
   /// This is in LSP snippet syntax (e.g. "({$0})" for a no-args function).
   /// (When snippets are disabled, the symbol name alone is used).
@@ -143,6 +147,7 @@ llvm::raw_ostream &operator<<(llvm::raw_
 template  void visitStrings(Symbol &S, const Callback &CB) {
   CB(S.Name);
   CB(S.Scope);
+  CB(S.TemplateSpecializationArgs);
   CB(S.Signature);
   CB(S.CompletionSnippetSuffix);
   CB(S.Documentation);

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=358273&r1=358272&r2=358273&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Fri Apr 12 
03:09:24 2019
@@ -524,9 +524,11 @@ const Symbol *SymbolCollector::addDeclar
   Symbol S;
   S.ID = std::move(ID);
   std::string QName = printQualifiedName(ND);
-  std::tie(S.Scope, S.Name) = splitQualifiedName(QName);
   // FIXME: this returns foo:bar: for objective-C methods, we prefer only foo:
   // for consistency with CodeCompletionString and a clean name/signature 
split.
+  std::tie(S.Scope, S.Name) = splitQualifiedName(QName);
+  std::string TemplateSpecializationArgs = printTemplateSpecializationArgs(ND);
+  S.TemplateSpecializationArgs = TemplateSpecializationArgs;
 
   // We collect main-file symbols, but do not use them for code completion.
   if (!IsMainFileOnly && isIndexedForCodeCompletion(ND, Ctx))

Modified: clang-tools-extra/trunk/clangd/index/YAMLSerialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/

r358272 - [clangd] Print template arguments helper

2019-04-12 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Apr 12 03:09:14 2019
New Revision: 358272

URL: http://llvm.org/viewvc/llvm-project?rev=358272&view=rev
Log:
[clangd] Print template arguments helper

Summary:
Prepares ground for printing template arguments as written in the
source code, part of re-landing rC356541 with D59599 applied.

Reviewers: ioeric, ilya-biryukov

Subscribers: mgorny, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59639

Modified:
cfe/trunk/lib/AST/TypePrinter.cpp

Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=358272&r1=358271&r2=358272&view=diff
==
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Fri Apr 12 03:09:14 2019
@@ -1632,6 +1632,19 @@ static const TemplateArgument &getArgume
   return A.getArgument();
 }
 
+static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
+  llvm::raw_ostream &OS) {
+  A.print(PP, OS);
+}
+
+static void printArgument(const TemplateArgumentLoc &A,
+  const PrintingPolicy &PP, llvm::raw_ostream &OS) {
+  const TemplateArgument::ArgKind &Kind = A.getArgument().getKind();
+  if (Kind == TemplateArgument::ArgKind::Type)
+return A.getTypeSourceInfo()->getType().print(OS, PP);
+  return A.getArgument().print(PP, OS);
+}
+
 template
 static void printTo(raw_ostream &OS, ArrayRef Args,
 const PrintingPolicy &Policy, bool SkipBrackets) {
@@ -1653,7 +1666,8 @@ static void printTo(raw_ostream &OS, Arr
 } else {
   if (!FirstArg)
 OS << Comma;
-  Argument.print(Policy, ArgOS);
+  // Tries to print the argument with location info if exists.
+  printArgument(Arg, Policy, ArgOS);
 }
 StringRef ArgString = ArgOS.str();
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r358272 - [clangd] Print template arguments helper

2019-04-12 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Apr 12 03:09:14 2019
New Revision: 358272

URL: http://llvm.org/viewvc/llvm-project?rev=358272&view=rev
Log:
[clangd] Print template arguments helper

Summary:
Prepares ground for printing template arguments as written in the
source code, part of re-landing rC356541 with D59599 applied.

Reviewers: ioeric, ilya-biryukov

Subscribers: mgorny, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59639

Added:
clang-tools-extra/trunk/unittests/clangd/PrintASTTests.cpp
Modified:
clang-tools-extra/trunk/clangd/AST.cpp
clang-tools-extra/trunk/clangd/AST.h
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp

Modified: clang-tools-extra/trunk/clangd/AST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/AST.cpp?rev=358272&r1=358271&r2=358272&view=diff
==
--- clang-tools-extra/trunk/clangd/AST.cpp (original)
+++ clang-tools-extra/trunk/clangd/AST.cpp Fri Apr 12 03:09:14 2019
@@ -11,15 +11,37 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Index/USRGeneration.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 
+namespace {
+llvm::Optional>
+getTemplateSpecializationArgLocs(const NamedDecl &ND) {
+  if (auto *Func = llvm::dyn_cast(&ND)) {
+if (const ASTTemplateArgumentListInfo *Args =
+Func->getTemplateSpecializationArgsAsWritten())
+  return Args->arguments();
+  } else if (auto *Cls =
+ llvm::dyn_cast(&ND)) {
+if (auto *Args = Cls->getTemplateArgsAsWritten())
+  return Args->arguments();
+  } else if (auto *Var = llvm::dyn_cast(&ND))
+return Var->getTemplateArgsInfo().arguments();
+  // We return None for ClassTemplateSpecializationDecls because it does not
+  // contain TemplateArgumentLoc information.
+  return llvm::None;
+}
+} // namespace
+
 // Returns true if the complete name of decl \p D is spelled in the source 
code.
 // This is not the case for:
 //   * symbols formed via macro concatenation, the spelling location will
@@ -65,17 +87,6 @@ std::string printQualifiedName(const Nam
   return QName;
 }
 
-static const TemplateArgumentList *
-getTemplateSpecializationArgs(const NamedDecl &ND) {
-  if (auto *Func = llvm::dyn_cast(&ND))
-return Func->getTemplateSpecializationArgs();
-  if (auto *Cls = llvm::dyn_cast(&ND))
-return &Cls->getTemplateInstantiationArgs();
-  if (auto *Var = llvm::dyn_cast(&ND))
-return &Var->getTemplateInstantiationArgs();
-  return nullptr;
-}
-
 std::string printName(const ASTContext &Ctx, const NamedDecl &ND) {
   std::string Name;
   llvm::raw_string_ostream Out(Name);
@@ -90,9 +101,7 @@ std::string printName(const ASTContext &
   }
   ND.getDeclName().print(Out, PP);
   if (!Out.str().empty()) {
-// FIXME(ibiryukov): do not show args not explicitly written by the user.
-if (auto *ArgList = getTemplateSpecializationArgs(ND))
-  printTemplateArgumentList(Out, ArgList->asArray(), PP);
+Out << printTemplateSpecializationArgs(ND);
 return Out.str();
   }
   // The name was empty, so present an anonymous entity.
@@ -105,6 +114,35 @@ std::string printName(const ASTContext &
   return "(anonymous)";
 }
 
+std::string printTemplateSpecializationArgs(const NamedDecl &ND) {
+  std::string TemplateArgs;
+  llvm::raw_string_ostream OS(TemplateArgs);
+  PrintingPolicy Policy(ND.getASTContext().getLangOpts());
+  if (llvm::Optional> Args =
+  getTemplateSpecializationArgLocs(ND)) {
+printTemplateArgumentList(OS, *Args, Policy);
+  } else if (auto *Cls = llvm::dyn_cast(&ND)) 
{
+if (const TypeSourceInfo *TSI = Cls->getTypeAsWritten()) {
+  // ClassTemplateSpecializationDecls do not contain
+  // TemplateArgumentTypeLocs, they only have TemplateArgumentTypes. So we
+  // create a new argument location list from TypeSourceInfo.
+  auto STL = TSI->getTypeLoc().getAs();
+  llvm::SmallVector ArgLocs;
+  ArgLocs.reserve(STL.getNumArgs());
+  for (unsigned I = 0; I < STL.getNumArgs(); ++I)
+ArgLocs.push_back(STL.getArgLoc(I));
+  printTemplateArgumentList(OS, ArgLocs, Policy);
+} else {
+  // FIXME: Fix cases when getTypeAsWritten returns null inside clang AST,
+  // e.g. friend decls. Currently we fallback to Template Arguments without
+  // location information.
+  printTemplateArgumentList(OS, Cls->getTemplateArgs().asArray(), Policy);
+}
+  }
+  OS.flush();
+  return TemplateArgs;
+}
+
 std::string printNamespaceScope(const DeclContext &DC) {
   for (con

[clang-tools-extra] r358274 - [clangd] Show template argument list in workspacesymbols and documentsymbols responses

2019-04-12 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Apr 12 03:09:37 2019
New Revision: 358274

URL: http://llvm.org/viewvc/llvm-project?rev=358274&view=rev
Log:
[clangd] Show template argument list in workspacesymbols and documentsymbols 
responses

Summary:
Last part of re-landing rC356541. Puts TemplateArgumentsList into
responses of the above mentioned two requests.

Reviewers: ioeric, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59641

Modified:
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
clang-tools-extra/trunk/unittests/clangd/DexTests.cpp
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
clang-tools-extra/trunk/unittests/clangd/IndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestIndex.cpp

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=358274&r1=358273&r2=358274&view=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Fri Apr 12 03:09:37 2019
@@ -94,7 +94,8 @@ getWorkspaceSymbols(llvm::StringRef Quer
 std::string Scope = Sym.Scope;
 llvm::StringRef ScopeRef = Scope;
 ScopeRef.consume_back("::");
-SymbolInformation Info = {Sym.Name, SK, L, ScopeRef};
+SymbolInformation Info = {(Sym.Name + 
Sym.TemplateSpecializationArgs).str(),
+  SK, L, ScopeRef};
 
 SymbolQualitySignals Quality;
 Quality.merge(Sym);

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=358274&r1=358273&r2=358274&view=diff
==
--- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Fri Apr 12 03:09:37 2019
@@ -38,15 +38,6 @@ bool MemIndex::fuzzyFind(
   for (const auto Pair : Index) {
 const Symbol *Sym = Pair.second;
 
-// FIXME: Enable fuzzy find on template specializations once we start
-// storing template arguments in the name. Currently we only store name for
-// class template, which would cause duplication in the results.
-if (Sym->SymInfo.Properties &
-(static_cast(
- index::SymbolProperty::TemplateSpecialization) |
- static_cast(
- index::SymbolProperty::TemplatePartialSpecialization)))
-  continue;
 // Exact match against all possible scopes.
 if (!Req.AnyScope && !llvm::is_contained(Req.Scopes, Sym->Scope))
   continue;

Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=358274&r1=358273&r2=358274&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Fri Apr 12 03:09:37 2019
@@ -86,15 +86,6 @@ void Dex::buildIndex() {
   llvm::DenseMap> TempInvertedIndex;
   for (DocID SymbolRank = 0; SymbolRank < Symbols.size(); ++SymbolRank) {
 const auto *Sym = Symbols[SymbolRank];
-// FIXME: Enable fuzzy find on template specializations once we start
-// storing template arguments in the name. Currently we only store name for
-// class template, which would cause duplication in the results.
-if (Sym->SymInfo.Properties &
-(static_cast(
- index::SymbolProperty::TemplateSpecialization) |
- static_cast(
- index::SymbolProperty::TemplatePartialSpecialization)))
-  continue;
 for (const auto &Token : generateSearchTokens(*Sym))
   TempInvertedIndex[Token].push_back(SymbolRank);
   }

Modified: clang-tools-extra/trunk/unittests/clangd/DexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DexTests.cpp?rev=358274&r1=358273&r2=358274&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/DexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Fri Apr 12 03:09:37 
2019
@@ -11,6 +11,7 @@
 #include "TestIndex.h"
 #include "index/Index.h"
 #include "index/Merge.h"
+#include "index/SymbolID.h"
 #include "index/dex/Dex.h"
 #include "index/dex/Iterator.h"
 #include "index/dex/Token.h"
@@ -24,6 +25,7 @@
 
 using ::testing::AnyOf;
 using ::testing::ElementsAre;
+using ::testing::IsEmpty;
 using ::testing::UnorderedElementsAre;
 
 namespace clang {
@@ -719,30 +721,30 @@ TEST(DexTest, TemplateSpecialization) {
 
   S = symbol("TempSpec");
   S.ID = SymbolID("1");
+  S.Tem

[clang-tools-extra] r358293 - [clangd] Fix an overflow inside a test

2019-04-12 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri Apr 12 09:40:54 2019
New Revision: 358293

URL: http://llvm.org/viewvc/llvm-project?rev=358293&view=rev
Log:
[clangd] Fix an overflow inside a test

Modified:
clang-tools-extra/trunk/unittests/clangd/PrintASTTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/PrintASTTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/PrintASTTests.cpp?rev=358293&r1=358292&r2=358293&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/PrintASTTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/PrintASTTests.cpp Fri Apr 12 
09:40:54 2019
@@ -37,6 +37,8 @@ TEST_P(ASTUtils, PrintTemplateArgs) {
   struct Visitor : RecursiveASTVisitor {
 Visitor(std::vector Points) : Points(std::move(Points)) {}
 bool VisitNamedDecl(const NamedDecl *ND) {
+  if (TemplateArgsAtPoints.size() == Points.size())
+return true;
   auto Pos = sourceLocToPosition(ND->getASTContext().getSourceManager(),
  ND->getLocation());
   if (Pos != Points[TemplateArgsAtPoints.size()])


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r358373 - [clangd] Reorder source files in CMakeLists

2019-04-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Apr 15 00:21:17 2019
New Revision: 358373

URL: http://llvm.org/viewvc/llvm-project?rev=358373&view=rev
Log:
[clangd] Reorder source files in CMakeLists

Modified:
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt

Modified: clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt?rev=358373&r1=358372&r2=358373&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt Mon Apr 15 00:21:17 
2019
@@ -13,7 +13,6 @@ include_directories(
 
 add_extra_unittest(ClangdTests
   Annotations.cpp
-  PrintASTTests.cpp
   BackgroundIndexTests.cpp
   CancellationTests.cpp
   ClangdTests.cpp
@@ -36,6 +35,7 @@ add_extra_unittest(ClangdTests
   IndexActionTests.cpp
   IndexTests.cpp
   JSONTransportTests.cpp
+  PrintASTTests.cpp
   QualityTests.cpp
   RIFFTests.cpp
   SelectionTests.cpp


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r358383 - [clangd] Bump clangd-index version for TemplateArgument changes

2019-04-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Apr 15 02:18:57 2019
New Revision: 358383

URL: http://llvm.org/viewvc/llvm-project?rev=358383&view=rev
Log:
[clangd] Bump clangd-index version for TemplateArgument changes

Modified:
clang-tools-extra/trunk/clangd/index/Serialization.cpp

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=358383&r1=358382&r2=358383&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Mon Apr 15 02:18:57 
2019
@@ -370,7 +370,7 @@ readRefs(Reader &Data, llvm::ArrayRef readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r358413 - [clangd] Fallback to OrigD when SLoc is invalid

2019-04-15 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Apr 15 07:38:46 2019
New Revision: 358413

URL: http://llvm.org/viewvc/llvm-project?rev=358413&view=rev
Log:
[clangd] Fallback to OrigD when SLoc is invalid

Summary:
Some implicit/built-in decls lack the source location
information. Fallback to OrigD that we've seen in the source code
instead of the canonical one in those cases.

Reviewers: sammccall

Subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric, ilya-biryukov

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60689

Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=358413&r1=358412&r2=358413&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Mon Apr 15 
07:38:46 2019
@@ -285,6 +285,11 @@ bool SymbolCollector::handleDeclOccurenc
   assert(ASTCtx && PP.get() && "ASTContext and Preprocessor must be set.");
   assert(CompletionAllocator && CompletionTUInfo);
   assert(ASTNode.OrigD);
+  // Indexing API puts cannonical decl into D, which might not have a valid
+  // source location for implicit/built-in decls. Fallback to original decl in
+  // such cases.
+  if (D->getLocation().isInvalid())
+D = ASTNode.OrigD;
   // If OrigD is an declaration associated with a friend declaration and it's
   // not a definition, skip it. Note that OrigD is the occurrence that the
   // collector is currently visiting.
@@ -540,6 +545,7 @@ const Symbol *SymbolCollector::addDeclar
   S.SymInfo = index::getSymbolInfo(&ND);
   std::string FileURI;
   auto Loc = findNameLoc(&ND);
+  assert(Loc.isValid() && "Invalid source location for NamedDecl");
   // FIXME: use the result to filter out symbols.
   shouldIndexFile(SM, SM.getFileID(Loc), Opts, &FilesToIndexCache);
   if (auto DeclLoc =

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp?rev=358413&r1=358412&r2=358413&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp Mon Apr 
15 07:38:46 2019
@@ -1241,6 +1241,14 @@ TEST_F(SymbolCollectorTest, CBuiltins) {
   EXPECT_THAT(Symbols, Contains(QName("printf")));
 }
 
+TEST_F(SymbolCollectorTest, InvalidSourceLoc) {
+  const char *Header = R"(
+  void operator delete(void*)
+__attribute__((__externally_visible__));)";
+  runSymbolCollector(Header, /**/ "");
+  EXPECT_THAT(Symbols, Contains(QName("operator delete")));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r358664 - [clangd] Use llvm::set_thread_priority in background-index

2019-04-18 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Apr 18 06:46:40 2019
New Revision: 358664

URL: http://llvm.org/viewvc/llvm-project?rev=358664&view=rev
Log:
[clangd] Use llvm::set_thread_priority in background-index

Reviewers: gribozavr

Subscribers: krytarowski, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, 
jfb, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60865

Modified:
clang-tools-extra/trunk/clangd/Threading.cpp
clang-tools-extra/trunk/clangd/Threading.h
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/Threading.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.cpp?rev=358664&r1=358663&r2=358664&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.cpp (original)
+++ clang-tools-extra/trunk/clangd/Threading.cpp Thu Apr 18 06:46:40 2019
@@ -113,33 +113,5 @@ void wait(std::unique_lock &
   CV.wait_until(Lock, D.time());
 }
 
-static std::atomic AvoidThreadStarvation = {false};
-
-void setCurrentThreadPriority(ThreadPriority Priority) {
-  // Some *really* old glibcs are missing SCHED_IDLE.
-#if defined(__linux__) && defined(SCHED_IDLE)
-  sched_param priority;
-  priority.sched_priority = 0;
-  pthread_setschedparam(
-  pthread_self(),
-  Priority == ThreadPriority::Low && !AvoidThreadStarvation ? SCHED_IDLE
-: SCHED_OTHER,
-  &priority);
-#elif defined(__APPLE__)
-  // 
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/getpriority.2.html
-  setpriority(PRIO_DARWIN_THREAD, 0,
-  Priority == ThreadPriority::Low && !AvoidThreadStarvation
-  ? PRIO_DARWIN_BG
-  : 0);
-#elif defined(_WIN32)
-  SetThreadPriority(GetCurrentThread(),
-Priority == ThreadPriority::Low && !AvoidThreadStarvation
-? THREAD_MODE_BACKGROUND_BEGIN
-: THREAD_MODE_BACKGROUND_END);
-#endif
-}
-
-void preventThreadStarvationInTests() { AvoidThreadStarvation = true; }
-
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/Threading.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Threading.h?rev=358664&r1=358663&r2=358664&view=diff
==
--- clang-tools-extra/trunk/clangd/Threading.h (original)
+++ clang-tools-extra/trunk/clangd/Threading.h Thu Apr 18 06:46:40 2019
@@ -117,16 +117,6 @@ private:
   std::size_t InFlightTasks = 0;
 };
 
-enum class ThreadPriority {
-  Low = 0,
-  Normal = 1,
-};
-void setCurrentThreadPriority(ThreadPriority Priority);
-// Avoid the use of scheduler policies that may starve low-priority threads.
-// This prevents tests from timing out on loaded systems.
-// Affects subsequent setThreadPriority() calls.
-void preventThreadStarvationInTests();
-
 } // namespace clangd
 } // namespace clang
 #endif

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=358664&r1=358663&r2=358664&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu Apr 18 06:46:40 2019
@@ -26,7 +26,9 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/SHA1.h"
+#include "llvm/Support/Threading.h"
 
+#include 
 #include 
 #include 
 #include 
@@ -38,6 +40,9 @@
 namespace clang {
 namespace clangd {
 namespace {
+
+static std::atomic PreventStarvation = {false};
+
 // Resolves URI to file paths with cache.
 class URIToFileCache {
 public:
@@ -172,7 +177,7 @@ void BackgroundIndex::run() {
   WithContext Background(BackgroundContext.clone());
   while (true) {
 llvm::Optional Task;
-ThreadPriority Priority;
+llvm::ThreadPriority Priority;
 {
   std::unique_lock Lock(QueueMu);
   QueueCV.wait(Lock, [&] { return ShouldStop || !Queue.empty(); });
@@ -186,11 +191,11 @@ void BackgroundIndex::run() {
   Queue.pop_front();
 }
 
-if (Priority != ThreadPriority::Normal)
-  setCurrentThreadPriority(Priority);
+if (Priority != llvm::ThreadPriority::Default && !PreventStarvation.load())
+  llvm::set_thread_priority(Priority);
 (*Task)();
-if (Priority != ThreadPriority::Normal)
-  setCurrentThreadPriority(ThreadPriority::Normal);
+if (Priority != llvm::ThreadPriority::Default)
+  llvm::set_thread_priority(llvm::ThreadPriority::Default);
 
 {
   std::unique_lo

r358665 - [clang][CIndex] Use llvm::set_thread_priority

2019-04-18 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Apr 18 06:49:20 2019
New Revision: 358665

URL: http://llvm.org/viewvc/llvm-project?rev=358665&view=rev
Log:
[clang][CIndex] Use llvm::set_thread_priority

Reviewers: jkorous, gribozavr

Subscribers: dexonsmith, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60867

Modified:
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=358665&r1=358664&r2=358665&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Apr 18 06:49:20 2019
@@ -8723,9 +8723,7 @@ void clang::setThreadBackgroundPriority(
   if (getenv("LIBCLANG_BGPRIO_DISABLE"))
 return;
 
-#ifdef USE_DARWIN_THREADS
-  setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG);
-#endif
+  llvm::set_thread_priority(llvm::ThreadPriority::Background);
 }
 
 void cxindex::printDiagsToStderr(ASTUnit *Unit) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r359075 - [clang][HeaderSearch] Make sure there are no backslashes in suggestedPath

2019-04-24 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Apr 24 01:45:03 2019
New Revision: 359075

URL: http://llvm.org/viewvc/llvm-project?rev=359075&view=rev
Log:
[clang][HeaderSearch] Make sure there are no backslashes in suggestedPath

Reviewers: sammccall

Differential Revision: https://reviews.llvm.org/D60995

Modified:
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/unittests/Lex/HeaderSearchTest.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=359075&r1=359074&r2=359075&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Wed Apr 24 01:45:03 2019
@@ -706,16 +706,18 @@ public:
   /// Retrieve a uniqued framework name.
   StringRef getUniqueFrameworkName(StringRef Framework);
 
-  /// Suggest a path by which the specified file could be found, for
-  /// use in diagnostics to suggest a #include.
+  /// Suggest a path by which the specified file could be found, for use in
+  /// diagnostics to suggest a #include. Returned path will only contain 
forward
+  /// slashes as separators.
   ///
   /// \param IsSystem If non-null, filled in to indicate whether the suggested
   ///path is relative to a system header directory.
   std::string suggestPathToFileForDiagnostics(const FileEntry *File,
   bool *IsSystem = nullptr);
 
-  /// Suggest a path by which the specified file could be found, for
-  /// use in diagnostics to suggest a #include.
+  /// Suggest a path by which the specified file could be found, for use in
+  /// diagnostics to suggest a #include. Returned path will only contain 
forward
+  /// slashes as separators.
   ///
   /// \param WorkingDir If non-empty, this will be prepended to search 
directory
   /// paths that are relative.

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=359075&r1=359074&r2=359075&view=diff
==
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Apr 24 01:45:03 2019
@@ -1720,5 +1720,5 @@ std::string HeaderSearch::suggestPathToF
 
   if (IsSystem)
 *IsSystem = BestPrefixLength ? BestSearchDir >= SystemDirIdx : false;
-  return File.drop_front(BestPrefixLength);
+  return path::convert_to_slash(File.drop_front(BestPrefixLength));
 }

Modified: cfe/trunk/unittests/Lex/HeaderSearchTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/HeaderSearchTest.cpp?rev=359075&r1=359074&r2=359075&view=diff
==
--- cfe/trunk/unittests/Lex/HeaderSearchTest.cpp (original)
+++ cfe/trunk/unittests/Lex/HeaderSearchTest.cpp Wed Apr 24 01:45:03 2019
@@ -91,5 +91,14 @@ TEST_F(HeaderSearchTest, Dots) {
 "z");
 }
 
+#ifdef _WIN32
+TEST_F(HeaderSearchTest, BackSlash) {
+  addSearchDir("C:\\x\\y\\");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("C:\\x\\y\\z\\t",
+   /*WorkingDir=*/""),
+"z/t");
+}
+#endif
+
 } // namespace
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r359078 - [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

2019-04-24 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Apr 24 02:23:31 2019
New Revision: 359078

URL: http://llvm.org/viewvc/llvm-project?rev=359078&view=rev
Log:
[clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

Summary:
Include insertion in clangd was inserting absolute paths when the
include directory was an absolute path with a double dot. This patch makes sure
double dots are handled both with absolute and relative paths.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60873

Modified:
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/unittests/Lex/HeaderSearchTest.cpp

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=359078&r1=359077&r2=359078&view=diff
==
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Apr 24 02:23:31 2019
@@ -1685,11 +1685,10 @@ std::string HeaderSearch::suggestPathToF
 
 StringRef Dir = SearchDirs[I].getDir()->getName();
 llvm::SmallString<32> DirPath(Dir.begin(), Dir.end());
-if (!WorkingDir.empty() && !path::is_absolute(Dir)) {
+if (!WorkingDir.empty() && !path::is_absolute(Dir))
   fs::make_absolute(WorkingDir, DirPath);
-  path::remove_dots(DirPath, /*remove_dot_dot=*/true);
-  Dir = DirPath;
-}
+path::remove_dots(DirPath, /*remove_dot_dot=*/true);
+Dir = DirPath;
 for (auto NI = path::begin(File), NE = path::end(File),
   DI = path::begin(Dir), DE = path::end(Dir);
  /*termination condition in loop*/; ++NI, ++DI) {

Modified: cfe/trunk/unittests/Lex/HeaderSearchTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/HeaderSearchTest.cpp?rev=359078&r1=359077&r2=359078&view=diff
==
--- cfe/trunk/unittests/Lex/HeaderSearchTest.cpp (original)
+++ cfe/trunk/unittests/Lex/HeaderSearchTest.cpp Wed Apr 24 02:23:31 2019
@@ -100,5 +100,12 @@ TEST_F(HeaderSearchTest, BackSlash) {
 }
 #endif
 
+TEST_F(HeaderSearchTest, DotDotsWithAbsPath) {
+  addSearchDir("/x/../y/");
+  EXPECT_EQ(Search.suggestPathToFileForDiagnostics("/y/z",
+   /*WorkingDir=*/""),
+"z");
+}
+
 } // namespace
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r359078 - [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

2019-04-24 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Apr 24 02:23:31 2019
New Revision: 359078

URL: http://llvm.org/viewvc/llvm-project?rev=359078&view=rev
Log:
[clang][HeaderSuggestion] Handle the case of dotdot with an absolute path

Summary:
Include insertion in clangd was inserting absolute paths when the
include directory was an absolute path with a double dot. This patch makes sure
double dots are handled both with absolute and relative paths.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60873

Modified:
clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp?rev=359078&r1=359077&r2=359078&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Wed Apr 24 
02:23:31 2019
@@ -213,6 +213,11 @@ TEST_F(HeadersTest, DoNotInsertIfInSameF
 TEST_F(HeadersTest, ShortenedInclude) {
   std::string BarHeader = testPath("sub/bar.h");
   EXPECT_EQ(calculate(BarHeader), "\"bar.h\"");
+
+  SearchDirArg = (llvm::Twine("-I") + Subdir + "/..").str();
+  CDB.ExtraClangFlags = {SearchDirArg.c_str()};
+  BarHeader = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(BarHeader), "\"sub/bar.h\"");
 }
 
 TEST_F(HeadersTest, NotShortenedInclude) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r359079 - [clangd] Fix handling of include paths in windows tests

2019-04-24 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Apr 24 02:42:53 2019
New Revision: 359079

URL: http://llvm.org/viewvc/llvm-project?rev=359079&view=rev
Log:
[clangd] Fix handling of include paths in windows tests

Modified:
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp

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=359079&r1=359078&r2=359079&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Wed Apr 24 
02:42:53 2019
@@ -22,6 +22,7 @@
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -699,11 +700,13 @@ TEST(CompletionTest, DynamicIndexInclude
   Server.addDocument(testPath("foo_impl.cpp"), FileContent);
   // Wait for the dynamic index being built.
   ASSERT_TRUE(Server.blockUntilIdleForTest());
-  EXPECT_THAT(
-  completions(Server, "Foo^ foo;").Completions,
-  ElementsAre(AllOf(Named("Foo"),
-HasInclude('"' + testPath("foo_header.h") + '"'),
-InsertInclude(;
+  EXPECT_THAT(completions(Server, "Foo^ foo;").Completions,
+  ElementsAre(AllOf(Named("Foo"),
+HasInclude('"' +
+   llvm::sys::path::convert_to_slash(
+   testPath("foo_header.h")) +
+   '"'),
+InsertInclude(;
 }
 
 TEST(CompletionTest, DynamicIndexMultiFile) {

Modified: clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp?rev=359079&r1=359078&r2=359079&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp Wed Apr 24 
02:42:53 2019
@@ -15,6 +15,7 @@
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "llvm/Support/Path.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -221,7 +222,8 @@ TEST_F(HeadersTest, ShortenedInclude) {
 }
 
 TEST_F(HeadersTest, NotShortenedInclude) {
-  std::string BarHeader = testPath("sub-2/bar.h");
+  std::string BarHeader =
+  llvm::sys::path::convert_to_slash(testPath("sub-2/bar.h"));
   EXPECT_EQ(calculate(BarHeader, ""), "\"" + BarHeader + "\"");
 }
 
@@ -265,8 +267,7 @@ TEST(Headers, NoHeaderSearchInfo) {
   auto Inserting = HeaderFile{HeaderPath, /*Verbatim=*/false};
   auto Verbatim = HeaderFile{"", /*Verbatim=*/true};
 
-  EXPECT_EQ(Inserter.calculateIncludePath(Inserting),
-"\"" + HeaderPath + "\"");
+  EXPECT_EQ(Inserter.calculateIncludePath(Inserting), "\"" + HeaderPath + 
"\"");
   EXPECT_EQ(Inserter.shouldInsertInclude(HeaderPath, Inserting), false);
 
   EXPECT_EQ(Inserter.calculateIncludePath(Verbatim), "");


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r359432 - [clangd] Surface diagnostics from headers inside main file

2019-04-29 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Apr 29 03:25:44 2019
New Revision: 359432

URL: http://llvm.org/viewvc/llvm-project?rev=359432&view=rev
Log:
[clangd] Surface diagnostics from headers inside main file

Reviewers: ioeric, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59302

Modified:
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/clangd/Diagnostics.h
clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/trunk/clangd/unittests/TestTU.cpp
clang-tools-extra/trunk/clangd/unittests/TestTU.h

Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=359432&r1=359431&r2=359432&view=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Mon Apr 29 03:25:44 2019
@@ -13,11 +13,18 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang/Basic/AllDiagnostics.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/Capacity.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "llvm/Support/Signals.h"
 #include 
 
 namespace clang {
@@ -102,6 +109,39 @@ Range diagnosticRange(const clang::Diagn
   return halfOpenToRange(M, R);
 }
 
+void adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info,
+  const LangOptions &LangOpts) {
+  const SourceLocation &DiagLoc = Info.getLocation();
+  const SourceManager &SM = Info.getSourceManager();
+  SourceLocation IncludeInMainFile;
+  auto GetIncludeLoc = [&SM](SourceLocation SLoc) {
+return SM.getIncludeLoc(SM.getFileID(SLoc));
+  };
+  for (auto IncludeLocation = GetIncludeLoc(DiagLoc); 
IncludeLocation.isValid();
+   IncludeLocation = GetIncludeLoc(IncludeLocation))
+IncludeInMainFile = IncludeLocation;
+  if (IncludeInMainFile.isInvalid())
+return;
+
+  // Update diag to point at include inside main file.
+  D.File = SM.getFileEntryForID(SM.getMainFileID())->getName().str();
+  D.Range.start = sourceLocToPosition(SM, IncludeInMainFile);
+  D.Range.end = sourceLocToPosition(
+  SM, Lexer::getLocForEndOfToken(IncludeInMainFile, 0, SM, LangOpts));
+
+  // Add a note that will point to real diagnostic.
+  const auto *FE = SM.getFileEntryForID(SM.getFileID(DiagLoc));
+  D.Notes.emplace_back();
+  Note &N = D.Notes.back();
+  N.AbsFile = FE->tryGetRealPathName();
+  N.File = FE->getName();
+  N.Message = "error occurred here";
+  N.Range = diagnosticRange(Info, LangOpts);
+
+  // Update message to mention original file.
+  D.Message = llvm::Twine("in included file: ", D.Message).str();
+}
+
 bool isInsideMainFile(const SourceLocation Loc, const SourceManager &M) {
   return Loc.isValid() && M.isWrittenInMainFile(M.getFileLoc(Loc));
 }
@@ -378,7 +418,7 @@ std::vector StoreDiags::take(const
 Msg.resize(Rest.size());
 };
 CleanMessage(Diag.Message);
-for (auto& Note : Diag.Notes)
+for (auto &Note : Diag.Notes)
   CleanMessage(Note.Message);
 continue;
   }
@@ -477,6 +517,7 @@ void StoreDiags::HandleDiagnostic(Diagno
 LastDiag = Diag();
 LastDiag->ID = Info.getID();
 FillDiagBase(*LastDiag);
+adjustDiagFromHeader(*LastDiag, Info, *LangOpts);
 
 if (!Info.getFixItHints().empty())
   AddFix(true /* try to invent a message instead of repeating the diag */);
@@ -511,11 +552,15 @@ void StoreDiags::HandleDiagnostic(Diagno
 void StoreDiags::flushLastDiag() {
   if (!LastDiag)
 return;
-  if (mentionsMainFile(*LastDiag))
+  // Only keeps diagnostics inside main file or the first one coming from a
+  // header.
+  if (mentionsMainFile(*LastDiag) ||
+  (LastDiag->Severity >= DiagnosticsEngine::Level::Error &&
+   IncludeLinesWithErrors.insert(LastDiag->Range.start.line).second)) {
 Output.push_back(std::move(*LastDiag));
-  else
-vlog("Dropped diagnostic outside main file: {0}: {1}", LastDiag->File,
- LastDiag->Message);
+  } else {
+vlog("Dropped diagnostic: {0}: {1}", LastDiag->File, LastDiag->Message);
+  }
   LastDiag.reset();
 }
 

Modified: clang-tools-extra/trunk/clangd/Diagnostics.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.h?rev=359432&r1=359431&r2=359432&view=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.h (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.h Mon Apr 29 03:25:44 2019
@@ -14,6 +14,9 @@
 #include "clang/

[clang-tools-extra] r359470 - [clangd] Fix serialization logic for Origin and Flags.

2019-04-29 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Apr 29 10:25:58 2019
New Revision: 359470

URL: http://llvm.org/viewvc/llvm-project?rev=359470&view=rev
Log:
[clangd] Fix serialization logic for Origin and Flags.

Modified:
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=359470&r1=359469&r2=359470&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Mon Apr 29 10:25:58 
2019
@@ -314,8 +314,8 @@ Symbol readSymbol(Reader &Data, llvm::Ar
   Sym.Definition = readLocation(Data, Strings);
   Sym.CanonicalDeclaration = readLocation(Data, Strings);
   Sym.References = Data.consumeVar();
-  Sym.Flags = static_cast(Data.consumeVar());
-  Sym.Origin = static_cast(Data.consumeVar());
+  Sym.Flags = static_cast(Data.consume8());
+  Sym.Origin = static_cast(Data.consume8());
   Sym.Signature = Data.consumeString(Strings);
   Sym.CompletionSnippetSuffix = Data.consumeString(Strings);
   Sym.Documentation = Data.consumeString(Strings);

Modified: clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp?rev=359470&r1=359469&r2=359470&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SerializationTests.cpp Mon Apr 29 
10:25:58 2019
@@ -40,8 +40,8 @@ CanonicalDeclaration:
   End:
 Line: 1
 Column: 1
-Origin:4
-Flags:1
+Origin:128
+Flags:129
 Documentation:'Foo doc'
 ReturnType:'int'
 IncludeHeaders:
@@ -115,7 +115,8 @@ TEST(SerializationTest, YAMLConversions)
   EXPECT_EQ(Sym1.Documentation, "Foo doc");
   EXPECT_EQ(Sym1.ReturnType, "int");
   EXPECT_EQ(StringRef(Sym1.CanonicalDeclaration.FileURI), 
"file:///path/foo.h");
-  EXPECT_EQ(Sym1.Origin, SymbolOrigin::Static);
+  EXPECT_EQ(Sym1.Origin, static_cast(1 << 7));
+  EXPECT_EQ(static_cast(Sym1.Flags), 129);
   EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion);
   EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated);
   EXPECT_THAT(Sym1.IncludeHeaders,


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r359874 - [clangd] Also perform merging for symbol definitions

2019-05-03 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Fri May  3 05:11:14 2019
New Revision: 359874

URL: http://llvm.org/viewvc/llvm-project?rev=359874&view=rev
Log:
[clangd] Also perform merging for symbol definitions

Summary:
clangd currently prefers declarations from codegen files. This patch
implements that behavior for definition locations. If we have definiton
locations both coming from AST and index, clangd will perform a merging to show
the codegen file if that's the case.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61126

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=359874&r1=359873&r2=359874&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri May  3 05:11:14 2019
@@ -346,24 +346,27 @@ std::vector locateSymbolA
 Index->lookup(QueryRequest, [&](const Symbol &Sym) {
   auto &R = Result[ResultIndex.lookup(Sym.ID)];
 
-  // Special case: if the AST yielded a definition, then it may not be
-  // the right *declaration*. Prefer the one from the index.
   if (R.Definition) { // from AST
+// Special case: if the AST yielded a definition, then it may not be
+// the right *declaration*. Prefer the one from the index.
 if (auto Loc = toLSPLocation(Sym.CanonicalDeclaration, *MainFilePath))
   R.PreferredDeclaration = *Loc;
+
+// We might still prefer the definition from the index, e.g. for
+// generated symbols.
+if (auto Loc = toLSPLocation(
+getPreferredLocation(*R.Definition, Sym.Definition, Scratch),
+*MainFilePath))
+  R.Definition = *Loc;
   } else {
 R.Definition = toLSPLocation(Sym.Definition, *MainFilePath);
 
-if (Sym.CanonicalDeclaration) {
-  // Use merge logic to choose AST or index declaration.
-  // We only do this for declarations as definitions from AST
-  // is generally preferred (e.g. definitions in main file).
-  if (auto Loc = toLSPLocation(
-  getPreferredLocation(R.PreferredDeclaration,
-   Sym.CanonicalDeclaration, Scratch),
-  *MainFilePath))
-R.PreferredDeclaration = *Loc;
-}
+// Use merge logic to choose AST or index declaration.
+if (auto Loc = toLSPLocation(
+getPreferredLocation(R.PreferredDeclaration,
+ Sym.CanonicalDeclaration, Scratch),
+*MainFilePath))
+  R.PreferredDeclaration = *Loc;
   }
 });
   }

Modified: clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp?rev=359874&r1=359873&r2=359874&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp Fri May  3 05:11:14 
2019
@@ -186,7 +186,8 @@ TEST(LocateSymbol, WithIndex) {
 
 TEST(LocateSymbol, WithIndexPreferredLocation) {
   Annotations SymbolHeader(R"cpp(
-class $[[Proto]] {};
+class $p[[Proto]] {};
+void $f[[func]]() {};
   )cpp");
   TestTU TU;
   TU.HeaderCode = SymbolHeader.code();
@@ -195,13 +196,25 @@ TEST(LocateSymbol, WithIndexPreferredLoc
 
   Annotations Test(R"cpp(// only declaration in AST.
 // Shift to make range different.
-class [[Proto]];
-P^roto* create();
+class Proto;
+void func() {}
+P$p^roto* create() {
+  fu$f^nc();
+  return nullptr;
+}
   )cpp");
 
   auto AST = TestTU::withCode(Test.code()).build();
-  auto Locs = clangd::locateSymbolAt(AST, Test.point(), Index.get());
-  EXPECT_THAT(Locs, ElementsAre(Sym("Proto", SymbolHeader.range(;
+  {
+auto Locs = clangd::locateSymbolAt(AST, Test.point("p"), Index.get());
+auto CodeGenLoc = SymbolHeader.range("p");
+EXPECT_THAT(Locs, ElementsAre(Sym("Proto", CodeGenLoc, CodeGenLoc)));
+  }
+  {
+auto Locs = clangd::locateSymbolAt(AST, Test.point("f"), Index.get());
+auto CodeGenLoc = SymbolHeader.range("f");
+EXPECT_THAT(Locs, ElementsAre(Sym("func", CodeGenLoc, CodeGenLoc)));
+  }
 }
 
 TEST(LocateSymbol, All) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r360344 - [clangd] Count number of references while merging RefSlabs inside FileIndex

2019-05-09 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu May  9 07:22:07 2019
New Revision: 360344

URL: http://llvm.org/viewvc/llvm-project?rev=360344&view=rev
Log:
[clangd] Count number of references while merging RefSlabs inside FileIndex

Summary:
For counting number of references clangd was relying on merging every
duplication of a symbol. Unfortunately this does not apply to FileIndex(and one
of its users' BackgroundIndex), since we get rid of duplication by simply
dropping symbols coming from non-canonical locations. So only one or two(coming
from canonical declaration header and defined source file, if exists)
replications of the same symbol reaches merging step.

This patch changes reference counting logic to rather count number of different
RefSlabs a given SymbolID exists.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, mgrang, arphaman, jdoerfert, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D59481

Modified:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
clang-tools-extra/trunk/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/trunk/clangd/unittests/FileIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=360344&r1=360343&r2=360344&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Thu May  9 07:22:07 2019
@@ -356,7 +356,8 @@ void BackgroundIndex::update(llvm::Strin
   // This can override a newer version that is added in another thread, if
   // this thread sees the older version but finishes later. This should be
   // rare in practice.
-  IndexedSymbols.update(Path, std::move(SS), std::move(RS));
+  IndexedSymbols.update(Path, std::move(SS), std::move(RS),
+Path == MainFile);
 }
   }
 }
@@ -478,7 +479,8 @@ BackgroundIndex::loadShard(const tooling
   struct ShardInfo {
 std::string AbsolutePath;
 std::unique_ptr Shard;
-FileDigest Digest;
+FileDigest Digest = {};
+bool CountReferences = false;
   };
   std::vector IntermediateSymbols;
   // Make sure we don't have duplicate elements in the queue. Keys are absolute
@@ -539,6 +541,7 @@ BackgroundIndex::loadShard(const tooling
   SI.AbsolutePath = CurDependency.Path;
   SI.Shard = std::move(Shard);
   SI.Digest = I.getValue().Digest;
+  SI.CountReferences = I.getValue().IsTU;
   IntermediateSymbols.push_back(std::move(SI));
   // Check if the source needs re-indexing.
   // Get the digest, skip it if file doesn't exist.
@@ -568,7 +571,8 @@ BackgroundIndex::loadShard(const tooling
 ? llvm::make_unique(std::move(*SI.Shard->Refs))
 : nullptr;
   IndexedFileDigests[SI.AbsolutePath] = SI.Digest;
-  IndexedSymbols.update(SI.AbsolutePath, std::move(SS), std::move(RS));
+  IndexedSymbols.update(SI.AbsolutePath, std::move(SS), std::move(RS),
+SI.CountReferences);
 }
   }
 

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=360344&r1=360343&r2=360344&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Thu May  9 07:22:07 2019
@@ -90,28 +90,36 @@ SymbolSlab indexHeaderSymbols(ASTContext
 }
 
 void FileSymbols::update(PathRef Path, std::unique_ptr Symbols,
- std::unique_ptr Refs) {
+ std::unique_ptr Refs, bool CountReferences) {
   std::lock_guard Lock(Mutex);
   if (!Symbols)
 FileToSymbols.erase(Path);
   else
 FileToSymbols[Path] = std::move(Symbols);
-  if (!Refs)
+  if (!Refs) {
 FileToRefs.erase(Path);
-  else
-FileToRefs[Path] = std::move(Refs);
+return;
+  }
+  RefSlabAndCountReferences Item;
+  Item.CountReferences = CountReferences;
+  Item.Slab = std::move(Refs);
+  FileToRefs[Path] = std::move(Item);
 }
 
 std::unique_ptr
 FileSymbols::buildIndex(IndexType Type, DuplicateHandling DuplicateHandle) {
   std::vector> SymbolSlabs;
   std::vector> RefSlabs;
+  std::vector MainFileRefs;
   {
 std::lock_guard Lock(Mutex);
 for (const auto &FileAndSymbols : FileToSymbols)
   SymbolSlabs.push_back(FileAndSymbols.second);
-for (const auto &FileAndRefs : FileToRefs)
-  RefSlabs.push_back(FileAndRefs.second);
+for (const auto &FileAndRefs : FileToRefs) {
+  RefSlabs.push_back(Fi

[clang-tools-extra] r360349 - [clangd] Bump index version and get rid of wrong assertion

2019-05-09 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu May  9 08:07:53 2019
New Revision: 360349

URL: http://llvm.org/viewvc/llvm-project?rev=360349&view=rev
Log:
[clangd] Bump index version and get rid of wrong assertion

Summary:
After rL360344, BackgroundIndex expects symbols with zero refcounts.
Therefore existing index files are no longer valid.

Assertion regarding finding target of a reference was wrong, since
background-index might still be going on or we might've loaded only some part of
the shards and might be missing the declaring shards for the symbol.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61734

Modified:
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=360349&r1=360348&r2=360349&view=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Thu May  9 08:07:53 2019
@@ -138,7 +138,9 @@ FileSymbols::buildIndex(IndexType Type,
 for (const RefSlab *Refs : MainFileRefs)
   for (const auto &Sym : *Refs) {
 auto It = Merged.find(Sym.first);
-assert(It != Merged.end() && "Reference to unknown symbol");
+// This might happen while background-index is still running.
+if (It == Merged.end())
+  continue;
 It->getSecond().References += Sym.second.size();
   }
 SymsStorage.reserve(Merged.size());

Modified: clang-tools-extra/trunk/clangd/index/Serialization.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Serialization.cpp?rev=360349&r1=360348&r2=360349&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Serialization.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Serialization.cpp Thu May  9 08:07:53 
2019
@@ -370,7 +370,7 @@ readRefs(Reader &Data, llvm::ArrayRef readRIFF(llvm::StringRef Data) {
   auto RIFF = riff::readFile(Data);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r342533 - [clangd] Add option to enable/disable function argument snippets.

2018-09-19 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Sep 19 03:16:44 2018
New Revision: 342533

URL: http://llvm.org/viewvc/llvm-project?rev=342533&view=rev
Log:
[clangd] Add option to enable/disable function argument snippets.

Summary:
Currently LSP clients cannot directly change EnableFunctionArgSnippets 
parameter.
This patch is to provide them with a way to enable/disable that functionality.

Reviewers: hokein, ioeric, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: sammccall, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D51214

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=342533&r1=342532&r2=342533&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Wed Sep 19 03:16:44 2018
@@ -169,6 +169,13 @@ static llvm::cl::opt Co
 "'compile_commands.json' files")),
 llvm::cl::init(FilesystemCompileArgs), llvm::cl::Hidden);
 
+static llvm::cl::opt EnableFunctionArgSnippets(
+"function-arg-placeholders",
+llvm::cl::desc("When disabled, completions contain only parentheses for "
+   "function calls. When enabled, completions also contain "
+   "placeholders for method parameters."),
+llvm::cl::init(clangd::CodeCompleteOptions().EnableFunctionArgSnippets));
+
 int main(int argc, char *argv[]) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
@@ -296,6 +303,7 @@ int main(int argc, char *argv[]) {
 CCOpts.IncludeIndicator.NoInsert.clear();
   }
   CCOpts.SpeculativeIndexRequest = Opts.StaticIndex;
+  CCOpts.EnableFunctionArgSnippets = EnableFunctionArgSnippets;
 
   // Initialize and run ClangdLSPServer.
   ClangdLSPServer LSPServer(


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r343197 - Improve diagnostics range reporting.

2018-09-27 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Sep 27 05:12:42 2018
New Revision: 343197

URL: http://llvm.org/viewvc/llvm-project?rev=343197&view=rev
Log:
Improve diagnostics range reporting.

Summary:
If we have some range information coming from clang diagnostic, promote
that one even if it doesn't contain diagnostic location inside.

Reviewers: sammccall, ioeric

Reviewed By: ioeric

Subscribers: ilya-biryukov, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D52544

Modified:
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp

Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=343197&r1=343196&r2=343197&view=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Thu Sep 27 05:12:42 2018
@@ -52,17 +52,28 @@ Range diagnosticRange(const clang::Diagn
   auto &M = D.getSourceManager();
   auto Loc = M.getFileLoc(D.getLocation());
   // Accept the first range that contains the location.
+  llvm::Optional FallbackRange;
   for (const auto &CR : D.getRanges()) {
 auto R = Lexer::makeFileCharRange(CR, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
+// If there are no ranges that contain the location report the first range.
+if (!FallbackRange)
+  FallbackRange = halfOpenToRange(M, R);
   }
   // The range may be given as a fixit hint instead.
   for (const auto &F : D.getFixItHints()) {
 auto R = Lexer::makeFileCharRange(F.RemoveRange, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
+// If there's a fixit that performs insertion, it has zero-width. Therefore
+// it can't contain the location of the diag, but it might be possible that
+// this should be reported as range. For example missing semicolon.
+if (!FallbackRange && R.getBegin() == R.getEnd())
+  FallbackRange = halfOpenToRange(M, R);
   }
+  if (FallbackRange)
+return *FallbackRange;
   // If no suitable range is found, just use the token at the location.
   auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
   if (!R.isValid()) // Fall back to location only, let the editor deal with it.

Modified: clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp?rev=343197&r1=343196&r2=343197&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp Thu Sep 27 
05:12:42 2018
@@ -79,8 +79,9 @@ TEST(DiagnosticsTest, DiagnosticRanges)
 int main() {
   $typo[[go\
 o]]();
-  foo()$semicolon[[]]
+  foo()$semicolon[[]]//with comments
   $unk[[unknown]]();
+  double bar = $type[["foo"]];
 }
   )cpp");
   EXPECT_THAT(
@@ -93,11 +94,16 @@ o]]();
 Fix(Test.range("typo"), "foo", "change 'go\\ o' to 
'foo'")),
 // This is a pretty normal range.
 WithNote(Diag(Test.range("decl"), "'foo' declared here"))),
-  // This range is zero-width, and at the end of a line.
+  // This range is zero-width and insertion. Therefore make sure we are
+  // not expanding it into other tokens. Since we are not going to
+  // replace those.
   AllOf(Diag(Test.range("semicolon"), "expected ';' after expression"),
 WithFix(Fix(Test.range("semicolon"), ";", "insert ';'"))),
   // This range isn't provided by clang, we expand to the token.
-  Diag(Test.range("unk"), "use of undeclared identifier 'unknown'")));
+  Diag(Test.range("unk"), "use of undeclared identifier 'unknown'"),
+  Diag(Test.range("type"),
+   "cannot initialize a variable of type 'double' with an lvalue "
+   "of type 'const char [4]'")));
 }
 
 TEST(DiagnosticsTest, FlagsMatter) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r343221 - Tell whether file/folder for include completions.

2018-09-27 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Sep 27 07:21:07 2018
New Revision: 343221

URL: http://llvm.org/viewvc/llvm-project?rev=343221&view=rev
Log:
Tell whether file/folder for include completions.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D52547

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=343221&r1=343220&r2=343221&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Sep 27 07:21:07 2018
@@ -349,6 +349,11 @@ struct CodeCompletionBuilder {
   }
   Completion.Kind = toCompletionItemKind(
   C.SemaResult->Kind, C.SemaResult->Declaration, ContextKind);
+  // Sema could provide more info on whether the completion was a file or
+  // folder.
+  if (Completion.Kind == CompletionItemKind::File &&
+  Completion.Name.back() == '/')
+Completion.Kind = CompletionItemKind::Folder;
   for (const auto &FixIt : C.SemaResult->FixIts) {
 Completion.FixIts.push_back(
 toTextEdit(FixIt, ASTCtx.getSourceManager(), 
ASTCtx.getLangOpts()));

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=343221&r1=343220&r2=343221&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Thu Sep 27 07:21:07 2018
@@ -704,6 +704,13 @@ enum class CompletionItemKind {
   Color = 16,
   File = 17,
   Reference = 18,
+  Folder = 19,
+  EnumMember = 20,
+  Constant = 21,
+  Struct = 22,
+  Event = 23,
+  Operator = 24,
+  TypeParameter = 25,
 };
 
 /// Defines whether the insert text in a completion item should be interpreted

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=343221&r1=343220&r2=343221&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Thu Sep 27 
07:21:07 2018
@@ -2073,6 +2073,27 @@ TEST(SignatureHelpTest, ConstructorIniti
   }
 }
 
+TEST(CompletionTest, IncludedCompletionKinds) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  std::string Subdir = testPath("sub");
+  std::string SearchDirArg = (llvm::Twine("-I") + Subdir).str();
+  CDB.ExtraClangFlags = {SearchDirArg.c_str()};
+  std::string BarHeader = testPath("sub/bar.h");
+  FS.Files[BarHeader] = "";
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
+  auto Results = completions(Server,
+  R"cpp(
+#include "^"
+  )cpp"
+  );
+  EXPECT_THAT(Results.Completions,
+  AllOf(Has("sub/", CompletionItemKind::Folder),
+Has("bar.h\"", CompletionItemKind::File)));
+}
+
+
 } // namespace
 } // namespace clangd
 } // namespace clang


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r343237 - Introduce completionItemKind capability support.

2018-09-27 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Sep 27 10:13:07 2018
New Revision: 343237

URL: http://llvm.org/viewvc/llvm-project?rev=343237&view=rev
Log:
Introduce completionItemKind capability support.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D52616

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=343237&r1=343236&r2=343237&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Sep 27 10:13:07 2018
@@ -70,6 +70,14 @@ SymbolKindBitset defaultSymbolKinds() {
   return Defaults;
 }
 
+CompletionItemKindBitset defaultCompletionItemKinds() {
+  CompletionItemKindBitset Defaults;
+  for (size_t I = CompletionItemKindMin;
+   I <= static_cast(CompletionItemKind::Reference); ++I)
+Defaults.set(I);
+  return Defaults;
+}
+
 } // namespace
 
 void ClangdLSPServer::onInitialize(InitializeParams &Params) {
@@ -89,13 +97,20 @@ void ClangdLSPServer::onInitialize(Initi
   Params.capabilities.textDocument.publishDiagnostics.categorySupport;
 
   if (Params.capabilities.workspace && Params.capabilities.workspace->symbol &&
-  Params.capabilities.workspace->symbol->symbolKind) {
+  Params.capabilities.workspace->symbol->symbolKind &&
+  Params.capabilities.workspace->symbol->symbolKind->valueSet) {
 for (SymbolKind Kind :
  *Params.capabilities.workspace->symbol->symbolKind->valueSet) {
   SupportedSymbolKinds.set(static_cast(Kind));
 }
   }
 
+  if (Params.capabilities.textDocument.completion.completionItemKind &&
+  Params.capabilities.textDocument.completion.completionItemKind->valueSet)
+for (CompletionItemKind Kind : *Params.capabilities.textDocument.completion
+.completionItemKind->valueSet)
+  SupportedCompletionItemKinds.set(static_cast(Kind));
+
   reply(json::Object{
   {{"capabilities",
 json::Object{
@@ -347,8 +362,12 @@ void ClangdLSPServer::onCompletion(TextD
return replyError(List.takeError());
  CompletionList LSPList;
  LSPList.isIncomplete = List->HasMore;
- for (const auto &R : List->Completions)
-   LSPList.items.push_back(R.render(CCOpts));
+ for (const auto &R : List->Completions) {
+   CompletionItem C = R.render(CCOpts);
+   C.kind = adjustKindToCapability(
+   C.kind, SupportedCompletionItemKinds);
+   LSPList.items.push_back(std::move(C));
+ }
  return reply(std::move(LSPList));
});
 }
@@ -459,6 +478,7 @@ ClangdLSPServer::ClangdLSPServer(JSONOut
  : CompilationDB::makeDirectoryBased(
std::move(CompileCommandsDir))),
   CCOpts(CCOpts), SupportedSymbolKinds(defaultSymbolKinds()),
+  SupportedCompletionItemKinds(defaultCompletionItemKinds()),
   Server(new ClangdServer(CDB.getCDB(), FSProvider, /*DiagConsumer=*/*this,
   Opts)) {}
 

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=343237&r1=343236&r2=343237&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Thu Sep 27 10:13:07 2018
@@ -164,6 +164,8 @@ private:
   ClangdDiagnosticOptions DiagOpts;
   /// The supported kinds of the client.
   SymbolKindBitset SupportedSymbolKinds;
+  /// The supported completion item kinds of the client.
+  CompletionItemKindBitset SupportedCompletionItemKinds;
 
   // Store of the current versions of the open documents.
   DraftStore DraftMgr;

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=343237&r1=343236&r2=343237&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Sep 27 10:13:07 2018
@@ -496,6 +496,57 @@ json::Value toJSON(const Hover &H) {
   return std::move(Result);
 }
 
+bool fromJSON(const js

r343568 - [clang] Implement Override Suggestions in Sema.

2018-10-02 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Oct  2 02:42:31 2018
New Revision: 343568

URL: http://llvm.org/viewvc/llvm-project?rev=343568&view=rev
Log:
[clang] Implement Override Suggestions in Sema.

Summary:
In clangd we had a new type of completion suggestions for cpp
class/struct/unions that will show override signatures for virtual methods in
base classes. This patch implements it in sema because it is hard to deduce more
info about completion token outside of Sema and handle itchy cases.

See the patch D50898 for more info on the functionality.

In addition to above patch this one also converts the suggestion into a
CK_Pattern with whole insertion text as the name of the suggestion and factors
out CodeCompletionString generation for declerations so that it can be re-used
by others.

Reviewers: ioeric, ilya-biryukov

Reviewed By: ioeric

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D52225

Added:
cfe/trunk/test/CodeCompletion/overrides.cpp
Modified:
cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h?rev=343568&r1=343567&r2=343568&view=diff
==
--- cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h (original)
+++ cfe/trunk/include/clang/Sema/CodeCompleteConsumer.h Tue Oct  2 02:42:31 2018
@@ -946,6 +946,16 @@ public:
  CodeCompletionAllocator &Allocator,
  CodeCompletionTUInfo &CCTUInfo);
 
+  CodeCompletionString *createCodeCompletionStringForDecl(
+  Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
+  bool IncludeBriefComments, const CodeCompletionContext &CCContext,
+  PrintingPolicy &Policy);
+
+  CodeCompletionString *createCodeCompletionStringForOverride(
+  Preprocessor &PP, ASTContext &Ctx, CodeCompletionBuilder &Result,
+  bool IncludeBriefComments, const CodeCompletionContext &CCContext,
+  PrintingPolicy &Policy);
+
   /// Retrieve the name that should be used to order a result.
   ///
   /// If the name needs to be constructed as a string, that string will be

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=343568&r1=343567&r2=343568&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Oct  2 02:42:31 2018
@@ -1598,6 +1598,74 @@ static void AddStaticAssertResult(CodeCo
   Results.AddResult(CodeCompletionResult(Builder.TakeString()));
 }
 
+namespace {
+void printOverrideString(llvm::raw_ostream &OS, CodeCompletionString *CCS) {
+  for (const auto &C : *CCS) {
+if (C.Kind == CodeCompletionString::CK_Optional)
+  printOverrideString(OS, C.Optional);
+else
+  OS << C.Text;
+// Add a space after return type.
+if (C.Kind == CodeCompletionString::CK_ResultType)
+  OS << ' ';
+  }
+}
+} // namespace
+
+static void AddOverrideResults(ResultBuilder &Results,
+   const CodeCompletionContext &CCContext,
+   CodeCompletionBuilder &Builder) {
+  Sema &S = Results.getSema();
+  const auto *CR = llvm::dyn_cast(S.CurContext);
+  // If not inside a class/struct/union return empty.
+  if (!CR)
+return;
+  // First store overrides within current class.
+  // These are stored by name to make querying fast in the later step.
+  llvm::StringMap> Overrides;
+  for (auto *Method : CR->methods()) {
+if (!Method->isVirtual() || !Method->getIdentifier())
+  continue;
+Overrides[Method->getName()].push_back(Method);
+  }
+
+  for (const auto &Base : CR->bases()) {
+const auto *BR = Base.getType().getTypePtr()->getAsCXXRecordDecl();
+if (!BR)
+  continue;
+for (auto *Method : BR->methods()) {
+  if (!Method->isVirtual() || !Method->getIdentifier())
+continue;
+  const auto it = Overrides.find(Method->getName());
+  bool IsOverriden = false;
+  if (it != Overrides.end()) {
+for (auto *MD : it->second) {
+  // If the method in current body is not an overload of this virtual
+  // function, then it overrides this one.
+  if (!S.IsOverload(MD, Method, false)) {
+IsOverriden = true;
+break;
+  }
+}
+  }
+  if (!IsOverriden) {
+// Generates a new CodeCompletionResult by taking this function and
+// converting it into an override declaration with only one chunk in 
the
+// final CodeCompletionString as a TypedTextChunk.
+std::string OverrideSignature;
+llvm::raw_string_ostream OS(OverrideSignature);
+CodeCompletionResult CCR(Method, 0);

[clang-tools-extra] r343567 - [clangd] Remove override result handling logic from clangd

2018-10-02 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Oct  2 02:42:17 2018
New Revision: 343567

URL: http://llvm.org/viewvc/llvm-project?rev=343567&view=rev
Log:
[clangd] Remove override result handling logic from clangd

Summary:
Since we plan to move handling of override suggestions to Sema with
D52225 this patch just makes sure clangd-side has no logic related to that
anymore and updates tests.

Reviewers: ioeric, ilya-biryukov

Reviewed By: ioeric

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D52226

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=343567&r1=343566&r2=343567&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Oct  2 02:42:17 2018
@@ -199,55 +199,6 @@ static llvm::Expected toHead
   return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
 }
 
-// First traverses all method definitions inside current class/struct/union
-// definition. Than traverses base classes to find virtual methods that haven't
-// been overriden within current context.
-// FIXME(kadircet): Currently we cannot see declarations below completion 
point.
-// It is because Sema gets run only upto completion point. Need to find a
-// solution to run it for the whole class/struct/union definition.
-static std::vector
-getNonOverridenMethodCompletionResults(const DeclContext *DC, Sema *S) {
-  const auto *CR = llvm::dyn_cast(DC);
-  // If not inside a class/struct/union return empty.
-  if (!CR)
-return {};
-  // First store overrides within current class.
-  // These are stored by name to make querying fast in the later step.
-  llvm::StringMap> Overrides;
-  for (auto *Method : CR->methods()) {
-if (!Method->isVirtual() || !Method->getIdentifier())
-  continue;
-Overrides[Method->getName()].push_back(Method);
-  }
-
-  std::vector Results;
-  for (const auto &Base : CR->bases()) {
-const auto *BR = Base.getType().getTypePtr()->getAsCXXRecordDecl();
-if (!BR)
-  continue;
-for (auto *Method : BR->methods()) {
-  if (!Method->isVirtual() || !Method->getIdentifier())
-continue;
-  const auto it = Overrides.find(Method->getName());
-  bool IsOverriden = false;
-  if (it != Overrides.end()) {
-for (auto *MD : it->second) {
-  // If the method in current body is not an overload of this virtual
-  // function, then it overrides this one.
-  if (!S->IsOverload(MD, Method, false)) {
-IsOverriden = true;
-break;
-  }
-}
-  }
-  if (!IsOverriden)
-Results.emplace_back(Method, 0);
-}
-  }
-
-  return Results;
-}
-
 /// A code completion result, in clang-native form.
 /// It may be promoted to a CompletionItem if it's among the top-ranked 
results.
 struct CompletionCandidate {
@@ -257,9 +208,6 @@ struct CompletionCandidate {
   const Symbol *IndexResult = nullptr;
   llvm::SmallVector RankedIncludeHeaders;
 
-  // States whether this item is an override suggestion.
-  bool IsOverride = false;
-
   // Returns a token identifying the overload set this is part of.
   // 0 indicates it's not part of any overload set.
   size_t overloadSet() const {
@@ -447,8 +395,6 @@ struct CodeCompletionBuilder {
 Completion.Documentation = getDocComment(ASTCtx, *C.SemaResult,
  /*CommentsFromHeader=*/false);
 }
-if (C.IsOverride)
-  S.OverrideSuffix = true;
   }
 
   CodeCompletion build() {
@@ -456,12 +402,6 @@ struct CodeCompletionBuilder {
 Completion.Signature = summarizeSignature();
 Completion.SnippetSuffix = summarizeSnippet();
 Completion.BundleSize = Bundled.size();
-if (summarizeOverride()) {
-  Completion.Name = Completion.ReturnType + ' ' +
-std::move(Completion.Name) +
-std::move(Completion.Signature) + " override";
-  Completion.Signature.clear();
-}
 return std::move(Completion);
   }
 
@@ -470,7 +410,6 @@ private:
 std::string SnippetSuffix;
 std::string Signature;
 std::string ReturnType;
-bool OverrideSuffix;
   };
 
   // If all BundledEntrys have the same value for a property, return it.
@@ -548,12 +487,6 @@ private:
 return "(…)";
   }
 
-  bool summarizeOverride() const {
-if (auto *OverrideSuffix = onlyValue<&BundledEntry::OverrideSuffix>())
-  return *OverrideSuffix;
-return false;
-  }
-
   ASTContext &ASTCtx;
   CodeCompletion Completion;
   SmallVector Bundled;
@@ -1418,11 +1351,8 @@ private:
 ? queryIndex()
 : SymbolSlab();
 trace::Span Tracer("Populate CodeCompleteResult");
-// Merge S

[clang-tools-extra] r344025 - [clangd] Revert back to previous heuristic for diagnostic range extraction.

2018-10-09 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Tue Oct  9 01:41:12 2018
New Revision: 344025

URL: http://llvm.org/viewvc/llvm-project?rev=344025&view=rev
Log:
[clangd] Revert back to previous heuristic for diagnostic range extraction.

Summary: Also add a few new test cases and a special case into handling of 
empty fixit ranges that  collides with location of a diag.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D52889

Modified:
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp

Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=344025&r1=344024&r2=344025&view=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Tue Oct  9 01:41:12 2018
@@ -51,16 +51,12 @@ bool locationInRange(SourceLocation L, C
 Range diagnosticRange(const clang::Diagnostic &D, const LangOptions &L) {
   auto &M = D.getSourceManager();
   auto Loc = M.getFileLoc(D.getLocation());
-  // Accept the first range that contains the location.
-  llvm::Optional FallbackRange;
   for (const auto &CR : D.getRanges()) {
 auto R = Lexer::makeFileCharRange(CR, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
-// If there are no ranges that contain the location report the first range.
-if (!FallbackRange)
-  FallbackRange = halfOpenToRange(M, R);
   }
+  llvm::Optional FallbackRange;
   // The range may be given as a fixit hint instead.
   for (const auto &F : D.getFixItHints()) {
 auto R = Lexer::makeFileCharRange(F.RemoveRange, M, L);
@@ -69,7 +65,7 @@ Range diagnosticRange(const clang::Diagn
 // If there's a fixit that performs insertion, it has zero-width. Therefore
 // it can't contain the location of the diag, but it might be possible that
 // this should be reported as range. For example missing semicolon.
-if (!FallbackRange && R.getBegin() == R.getEnd())
+if (R.getBegin() == R.getEnd() && Loc == R.getBegin())
   FallbackRange = halfOpenToRange(M, R);
   }
   if (FallbackRange)

Modified: clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp?rev=344025&r1=344024&r2=344025&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp Tue Oct  9 
01:41:12 2018
@@ -75,13 +75,17 @@ Position pos(int line, int character) {
 TEST(DiagnosticsTest, DiagnosticRanges) {
   // Check we report correct ranges, including various edge-cases.
   Annotations Test(R"cpp(
+namespace test{};
 void $decl[[foo]]();
 int main() {
   $typo[[go\
 o]]();
   foo()$semicolon[[]]//with comments
   $unk[[unknown]]();
-  double bar = $type[["foo"]];
+  double $type[[bar]] = "foo";
+  struct Foo { int x; }; Foo a;
+  a.$nomember[[y]];
+  test::$nomembernamespace[[test]];
 }
   )cpp");
   EXPECT_THAT(
@@ -103,7 +107,10 @@ o]]();
   Diag(Test.range("unk"), "use of undeclared identifier 'unknown'"),
   Diag(Test.range("type"),
"cannot initialize a variable of type 'double' with an lvalue "
-   "of type 'const char [4]'")));
+   "of type 'const char [4]'"),
+  Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
+  Diag(Test.range("nomembernamespace"),
+   "no member named 'test' in namespace 'test'")));
 }
 
 TEST(DiagnosticsTest, FlagsMatter) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r353030 - [clang] Add getCommentHandler to PreambleCallbacks

2019-02-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Feb  4 01:42:33 2019
New Revision: 353030

URL: http://llvm.org/viewvc/llvm-project?rev=353030&view=rev
Log:
[clang] Add getCommentHandler to PreambleCallbacks

Summary:
Enables users to add comment handlers to preprocessor when building
preambles.

Reviewers: ilya-biryukov, ioeric

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D57507

Modified:
cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp

Modified: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h?rev=353030&r1=353029&r2=353030&view=diff
==
--- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h (original)
+++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h Mon Feb  4 01:42:33 
2019
@@ -283,6 +283,8 @@ public:
   /// Creates wrapper class for PPCallbacks so we can also process information
   /// about includes that are inside of a preamble
   virtual std::unique_ptr createPPCallbacks();
+  /// The returned CommentHandler will be added to the preprocessor if not 
null.
+  virtual CommentHandler *getCommentHandler();
 };
 
 enum class BuildPreambleError {

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=353030&r1=353029&r2=353030&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Mon Feb  4 01:42:33 2019
@@ -18,6 +18,7 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "llvm/ADT/StringExtras.h"
@@ -346,6 +347,8 @@ llvm::ErrorOr Preco
   Callbacks.createPPCallbacks();
   if (DelegatedPPCallbacks)
 Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks));
+  if (auto CommentHandler = Callbacks.getCommentHandler())
+Clang->getPreprocessor().addCommentHandler(CommentHandler);
 
   Act->Execute();
 
@@ -742,6 +745,7 @@ void PreambleCallbacks::HandleTopLevelDe
 std::unique_ptr PreambleCallbacks::createPPCallbacks() {
   return nullptr;
 }
+CommentHandler *PreambleCallbacks::getCommentHandler() { return nullptr; }
 
 static llvm::ManagedStatic 
BuildPreambleErrCategory;
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r353054 - [clangd] Enable include insertion for static index

2019-02-04 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Feb  4 08:19:57 2019
New Revision: 353054

URL: http://llvm.org/viewvc/llvm-project?rev=353054&view=rev
Log:
[clangd] Enable include insertion for static index

Summary:
This enables include insertion by adding canonical includes into
preambledata.

Reviewers: ioeric, ilya-biryukov

Subscribers: javed.absar, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D57508

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/TUScheduler.cpp
clang-tools-extra/trunk/clangd/TUScheduler.h
clang-tools-extra/trunk/clangd/index/FileIndex.cpp
clang-tools-extra/trunk/clangd/index/FileIndex.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=353054&r1=353053&r2=353054&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Feb  4 08:19:57 2019
@@ -13,6 +13,7 @@
 #include "Headers.h"
 #include "SourceCode.h"
 #include "Trace.h"
+#include "index/CanonicalIncludes.h"
 #include "index/FileIndex.h"
 #include "index/Merge.h"
 #include "refactor/Tweak.h"
@@ -69,9 +70,10 @@ struct UpdateIndexCallbacks : public Par
   : FIndex(FIndex), DiagConsumer(DiagConsumer) {}
 
   void onPreambleAST(PathRef Path, ASTContext &Ctx,
- std::shared_ptr PP) override {
+ std::shared_ptr PP,
+ const CanonicalIncludes &CanonIncludes) override {
 if (FIndex)
-  FIndex->updatePreamble(Path, Ctx, std::move(PP));
+  FIndex->updatePreamble(Path, Ctx, std::move(PP), CanonIncludes);
   }
 
   void onMainAST(PathRef Path, ParsedAST &AST) override {

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=353054&r1=353053&r2=353054&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Mon Feb  4 08:19:57 2019
@@ -16,6 +16,7 @@
 #include "Logger.h"
 #include "SourceCode.h"
 #include "Trace.h"
+#include "index/CanonicalIncludes.h"
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/LangOptions.h"
@@ -99,11 +100,16 @@ public:
 
   IncludeStructure takeIncludes() { return std::move(Includes); }
 
+  CanonicalIncludes takeCanonicalIncludes() {
+addSystemHeadersMapping(&CanonIncludes);
+return std::move(CanonIncludes);
+  }
+
   void AfterExecute(CompilerInstance &CI) override {
 if (!ParsedCallback)
   return;
 trace::Span Tracer("Running PreambleCallback");
-ParsedCallback(CI.getASTContext(), CI.getPreprocessorPtr());
+ParsedCallback(CI.getASTContext(), CI.getPreprocessorPtr(), CanonIncludes);
   }
 
   void BeforeExecute(CompilerInstance &CI) override {
@@ -115,10 +121,17 @@ public:
 return collectIncludeStructureCallback(*SourceMgr, &Includes);
   }
 
+  CommentHandler *getCommentHandler() override {
+IWYUHandler = collectIWYUHeaderMaps(&CanonIncludes);
+return IWYUHandler.get();
+  }
+
 private:
   PathRef File;
   PreambleParsedCallback ParsedCallback;
   IncludeStructure Includes;
+  CanonicalIncludes CanonIncludes;
+  std::unique_ptr IWYUHandler = nullptr;
   SourceManager *SourceMgr = nullptr;
 };
 
@@ -324,6 +337,17 @@ ParsedAST::build(std::unique_ptrgetPreprocessor().addPPCallbacks(
   collectIncludeStructureCallback(Clang->getSourceManager(), &Includes));
 
+  // Copy over the includes from the preamble, then combine with the
+  // non-preamble includes below.
+  CanonicalIncludes CanonIncludes;
+  if (Preamble)
+CanonIncludes = Preamble->CanonIncludes;
+  else
+addSystemHeadersMapping(&CanonIncludes);
+  std::unique_ptr IWYUHandler =
+  collectIWYUHeaderMaps(&CanonIncludes);
+  Clang->getPreprocessor().addCommentHandler(IWYUHandler.get());
+
   if (!Action->Execute())
 log("Execute() failed when building AST for {0}", MainInput.getFile());
 
@@ -353,7 +377,7 @@ ParsedAST::build(std::unique_ptrDiags.begin(), 
Preamble->Diags.end());
   return ParsedAST(std::move(Preamble), std::move(Clang), std::move(Action),
std::move(ParsedDecls), std::move(Diags),
-   std::move(Includes));
+   std::move(Includes), std::move(CanonIncludes));
 }
 
 ParsedAST::ParsedAST(ParsedAST &&Other) = default;
@@ -429,21 +453,28 @@ const IncludeStructure &ParsedAST::getIn
   return In

[clang-tools-extra] r353422 - [clangd] Reduce number of threads used by BackgroundIndex to number of physical cores.

2019-02-07 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Feb  7 08:04:30 2019
New Revision: 353422

URL: http://llvm.org/viewvc/llvm-project?rev=353422&view=rev
Log:
[clangd] Reduce number of threads used by BackgroundIndex to number of physical 
cores.

Summary:
clangd is using as many threads as logical cores for BackgroundIndex
by default. We observed that it increases latency of foreground tasks.

This patch aims to change that default to number of physical cores to get rid of
that extra latency.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57819

Modified:
clang-tools-extra/trunk/clangd/index/Background.h

Modified: clang-tools-extra/trunk/clangd/index/Background.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.h?rev=353422&r1=353421&r2=353422&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Background.h (original)
+++ clang-tools-extra/trunk/clangd/index/Background.h Thu Feb  7 08:04:30 2019
@@ -67,11 +67,12 @@ public:
   /// If BuildIndexPeriodMs is greater than 0, the symbol index will only be
   /// rebuilt periodically (one per \p BuildIndexPeriodMs); otherwise, index is
   /// rebuilt for each indexed file.
-  BackgroundIndex(Context BackgroundContext, const FileSystemProvider &,
-  const GlobalCompilationDatabase &CDB,
-  BackgroundIndexStorage::Factory IndexStorageFactory,
-  size_t BuildIndexPeriodMs = 0,
-  size_t ThreadPoolSize = llvm::hardware_concurrency());
+  BackgroundIndex(
+  Context BackgroundContext, const FileSystemProvider &,
+  const GlobalCompilationDatabase &CDB,
+  BackgroundIndexStorage::Factory IndexStorageFactory,
+  size_t BuildIndexPeriodMs = 0,
+  size_t ThreadPoolSize = llvm::heavyweight_hardware_concurrency());
   ~BackgroundIndex(); // Blocks while the current task finishes.
 
   // Enqueue translation units for indexing.


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r353423 - [clangd] Mention indexing in docs.

2019-02-07 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Feb  7 08:10:39 2019
New Revision: 353423

URL: http://llvm.org/viewvc/llvm-project?rev=353423&view=rev
Log:
[clangd] Mention indexing in docs.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Differential Revision: https://reviews.llvm.org/D57392

Modified:
clang-tools-extra/trunk/docs/clangd.rst

Modified: clang-tools-extra/trunk/docs/clangd.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd.rst?rev=353423&r1=353422&r2=353423&view=diff
==
--- clang-tools-extra/trunk/docs/clangd.rst (original)
+++ clang-tools-extra/trunk/docs/clangd.rst Thu Feb  7 08:10:39 2019
@@ -143,6 +143,25 @@ Emacs Integration
 :program:`Emacs` provides `lsp-mode `_ and
 `Eglot `_ plugins for LSP integration.
 
+Project-wide Index
+==
+
+By default :program:`Clangd` only has a view on symbols coming from files you
+are currently editing. You can extend this view to whole project by providing a
+project-wide index to :program:`Clangd`.
+
+There are two ways you can generate a project-wide index for clangd:
+
+- Passing experimental `-background-index` commandline argument, which will
+  incrementally build an index of projects that you work on and make use of 
that
+  in clangd automatically.
+- Generate an index file using `clangd-indexer
+  
`_
+  Afterwards you can pass generated index file to clangd using
+  `-index-file=/path/to/index_file`.  *Note that clangd-indexer isn't included
+  alongside clangd in the standard clang-tools package. You will likely have to
+  build from source to use this option*
+
 Getting Involved
 ==
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r353687 - [clangd] Make system header mappings available for PreambleParsedCallback

2019-02-11 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Feb 11 02:31:13 2019
New Revision: 353687

URL: http://llvm.org/viewvc/llvm-project?rev=353687&view=rev
Log:
[clangd] Make system header mappings available for PreambleParsedCallback

Summary:
SystemHeaderMappings were added only after takeIncludes call, which
resulted in getting mapping on main file ast updates but not on preamble ast
updates.
Fixes https://github.com/clangd/clangd/issues/8

Reviewers: hokein

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58029

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=353687&r1=353686&r2=353687&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Mon Feb 11 02:31:13 2019
@@ -96,14 +96,13 @@ private:
 class CppFilePreambleCallbacks : public PreambleCallbacks {
 public:
   CppFilePreambleCallbacks(PathRef File, PreambleParsedCallback ParsedCallback)
-  : File(File), ParsedCallback(ParsedCallback) {}
+  : File(File), ParsedCallback(ParsedCallback) {
+addSystemHeadersMapping(&CanonIncludes);
+  }
 
   IncludeStructure takeIncludes() { return std::move(Includes); }
 
-  CanonicalIncludes takeCanonicalIncludes() {
-addSystemHeadersMapping(&CanonIncludes);
-return std::move(CanonIncludes);
-  }
+  CanonicalIncludes takeCanonicalIncludes() { return std::move(CanonIncludes); 
}
 
   void AfterExecute(CompilerInstance &CI) override {
 if (!ParsedCallback)

Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=353687&r1=353686&r2=353687&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Mon Feb 11 
02:31:13 2019
@@ -212,6 +212,39 @@ TEST(FileIndexTest, IncludeCollected) {
   "");
 }
 
+TEST(FileIndexTest, HasSystemHeaderMappingsInPreamble) {
+  FileIndex Index;
+  const std::string Header = R"cpp(
+class Foo {};
+  )cpp";
+  auto MainFile = testPath("foo.cpp");
+  auto HeaderFile = testPath("bits/alloc_traits.h");
+  std::vector Cmd = {"clang", "-xc++", MainFile.c_str(),
+   "-include", HeaderFile.c_str()};
+  // Preparse ParseInputs.
+  ParseInputs PI;
+  PI.CompileCommand.Directory = testRoot();
+  PI.CompileCommand.Filename = MainFile;
+  PI.CompileCommand.CommandLine = {Cmd.begin(), Cmd.end()};
+  PI.Contents = "";
+  PI.FS = buildTestFS({{MainFile, ""}, {HeaderFile, Header}});
+
+  // Prepare preamble.
+  auto CI = buildCompilerInvocation(PI);
+  auto PreambleData = buildPreamble(
+  MainFile, *buildCompilerInvocation(PI), /*OldPreamble=*/nullptr,
+  tooling::CompileCommand(), PI, 
std::make_shared(),
+  /*StoreInMemory=*/true,
+  [&](ASTContext &Ctx, std::shared_ptr PP,
+  const CanonicalIncludes &Includes) {
+Index.updatePreamble(MainFile, Ctx, PP, Includes);
+  });
+  auto Symbols = runFuzzyFind(Index, "");
+  EXPECT_THAT(Symbols, ElementsAre(_));
+  EXPECT_THAT(Symbols.begin()->IncludeHeaders.front().IncludeHeader,
+  "");
+}
+
 TEST(FileIndexTest, TemplateParamsInLabel) {
   auto Source = R"cpp(
 template 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r353694 - [clangd] Fix broken windows build bots.

2019-02-11 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Feb 11 05:01:47 2019
New Revision: 353694

URL: http://llvm.org/viewvc/llvm-project?rev=353694&view=rev
Log:
[clangd] Fix broken windows build bots.

Modified:
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=353694&r1=353693&r2=353694&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Mon Feb 11 
05:01:47 2019
@@ -218,7 +218,7 @@ TEST(FileIndexTest, HasSystemHeaderMappi
 class Foo {};
   )cpp";
   auto MainFile = testPath("foo.cpp");
-  auto HeaderFile = testPath("bits/alloc_traits.h");
+  auto HeaderFile = testPath("algorithm");
   std::vector Cmd = {"clang", "-xc++", MainFile.c_str(),
"-include", HeaderFile.c_str()};
   // Preparse ParseInputs.
@@ -242,7 +242,7 @@ TEST(FileIndexTest, HasSystemHeaderMappi
   auto Symbols = runFuzzyFind(Index, "");
   EXPECT_THAT(Symbols, ElementsAre(_));
   EXPECT_THAT(Symbols.begin()->IncludeHeaders.front().IncludeHeader,
-  "");
+  "");
 }
 
 TEST(FileIndexTest, TemplateParamsInLabel) {


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r353695 - [clang][Index] Add a knob to index function parameters in declarations

2019-02-11 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Feb 11 05:02:21 2019
New Revision: 353695

URL: http://llvm.org/viewvc/llvm-project?rev=353695&view=rev
Log:
[clang][Index] Add a knob to index function parameters in declarations

Summary:
Parameters in declarations are useful for clangd, so that we can
provide symbol information for them as well. It also helps clangd to be
consistent whether a function's definition is accessible or not.

Reviewers: hokein, akyrtzi

Subscribers: ilya-biryukov, ioeric, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57949

Modified:
cfe/trunk/include/clang/Index/IndexingAction.h
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/lib/Index/IndexingContext.cpp
cfe/trunk/lib/Index/IndexingContext.h
cfe/trunk/unittests/Index/IndexTests.cpp

Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=353695&r1=353694&r2=353695&view=diff
==
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Mon Feb 11 05:02:21 2019
@@ -44,6 +44,8 @@ struct IndexingOptions {
   // callback is not available (e.g. after parsing has finished). Note that
   // macro references are not available in Proprocessor.
   bool IndexMacrosInPreprocessor = false;
+  // Has no effect if IndexFunctionLocals are false.
+  bool IndexParametersInDeclarations = false;
 };
 
 /// Creates a frontend action that indexes all symbols (macros and AST decls).

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=353695&r1=353694&r2=353695&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Mon Feb 11 05:02:21 2019
@@ -88,12 +88,11 @@ public:
  /*isBase=*/false, isIBType);
 IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent);
 if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
-  // Only index parameters in definitions, parameters in declarations are
-  // not useful.
   if (const ParmVarDecl *Parm = dyn_cast(D)) {
 auto *DC = Parm->getDeclContext();
 if (auto *FD = dyn_cast(DC)) {
-  if (FD->isThisDeclarationADefinition())
+  if (IndexCtx.shouldIndexParametersInDeclarations() ||
+  FD->isThisDeclarationADefinition())
 IndexCtx.handleDecl(Parm);
 } else if (auto *MD = dyn_cast(DC)) {
   if (MD->isThisDeclarationADefinition())
@@ -102,7 +101,8 @@ public:
   IndexCtx.handleDecl(Parm);
 }
   } else if (const FunctionDecl *FD = dyn_cast(D)) {
-if (FD->isThisDeclarationADefinition()) {
+if (IndexCtx.shouldIndexParametersInDeclarations() ||
+FD->isThisDeclarationADefinition()) {
   for (auto PI : FD->parameters()) {
 IndexCtx.handleDecl(PI);
   }

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=353695&r1=353694&r2=353695&view=diff
==
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Mon Feb 11 05:02:21 2019
@@ -40,6 +40,10 @@ bool IndexingContext::shouldIndexImplici
   return IndexOpts.IndexImplicitInstantiation;
 }
 
+bool IndexingContext::shouldIndexParametersInDeclarations() const {
+  return IndexOpts.IndexParametersInDeclarations;
+}
+
 bool IndexingContext::handleDecl(const Decl *D,
  SymbolRoleSet Roles,
  ArrayRef Relations) {

Modified: cfe/trunk/lib/Index/IndexingContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.h?rev=353695&r1=353694&r2=353695&view=diff
==
--- cfe/trunk/lib/Index/IndexingContext.h (original)
+++ cfe/trunk/lib/Index/IndexingContext.h Mon Feb 11 05:02:21 2019
@@ -61,6 +61,8 @@ public:
 
   bool shouldIndexImplicitInstantiation() const;
 
+  bool shouldIndexParametersInDeclarations() const;
+
   static bool isTemplateImplicitInstantiation(const Decl *D);
 
   bool handleDecl(const Decl *D, SymbolRoleSet Roles = SymbolRoleSet(),

Modified: cfe/trunk/unittests/Index/IndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Index/IndexTests.cpp?rev=353695&r1=353694&r2=353695&view=diff
==
--- cfe/trunk/unittests/Index/IndexTests.cpp (original)
+++ cfe/trunk/unittests/Index/IndexTests.cpp Mon Feb 11 05:02:21 2019
@@ -119,6 +119,21 @@ TEST(IndexTest, IndexPreprocessorMacros)
   EXPEC

[clang-tools-extra] r353696 - [clangd] Index parameters in function decls

2019-02-11 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Feb 11 05:03:08 2019
New Revision: 353696

URL: http://llvm.org/viewvc/llvm-project?rev=353696&view=rev
Log:
[clangd] Index parameters in function decls

Reviewers: hokein

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57950

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=353696&r1=353695&r2=353696&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Mon Feb 11 05:03:08 2019
@@ -215,6 +215,7 @@ IdentifiedSymbol getSymbolAtPosition(Par
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
+  IndexOpts.IndexParametersInDeclarations = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
  AST.getLocalTopLevelDecls(), DeclMacrosFinder, IndexOpts);
 
@@ -400,6 +401,7 @@ findRefs(const std::vector
   IndexOpts.SystemSymbolFilter =
   index::IndexingOptions::SystemSymbolFilterKind::All;
   IndexOpts.IndexFunctionLocals = true;
+  IndexOpts.IndexParametersInDeclarations = true;
   indexTopLevelDecls(AST.getASTContext(), AST.getPreprocessor(),
  AST.getLocalTopLevelDecls(), RefFinder, IndexOpts);
   return std::move(RefFinder).take();

Modified: clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp?rev=353696&r1=353695&r2=353696&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SymbolInfoTests.cpp Mon Feb 11 
05:03:08 2019
@@ -302,6 +302,12 @@ TEST(SymbolInfoTests, All) {
 )cpp",
   {CreateExpectedSymbolDetails("bar", "foo::", "c:@E@foo@bar")}},
   {
+  R"cpp( // Parameters in declarations
+  void foo(int ba^r);
+)cpp",
+  {CreateExpectedSymbolDetails("bar", "foo",
+   "c:TestTU.cpp@50@F@foo#I#@bar")}},
+  {
   R"cpp( // Type inferrence with auto keyword
   struct foo {};
   foo getfoo() { return foo{}; }

Modified: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp?rev=353696&r1=353695&r2=353696&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Mon Feb 11 05:03:08 
2019
@@ -86,6 +86,10 @@ TEST(HighlightsTest, All) {
   auto *X = &[[foo]];
 }
   )cpp",
+
+  R"cpp(// Function parameter in decl
+void foo(int [[^bar]]);
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   4   5   6   7   8   >