[clang-tools-extra] r354761 - [clangd] Enhance macro hover to see full definition

2019-02-24 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Sun Feb 24 15:47:03 2019
New Revision: 354761

URL: http://llvm.org/viewvc/llvm-project?rev=354761=rev
Log:
[clangd] Enhance macro hover to see full definition

Summary: Signed-off-by: Marc-Andre Laperle 

Reviewers: simark, ilya-biryukov, sammccall, ioeric, hokein

Reviewed By: ilya-biryukov

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

Tags: #clang

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

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=354761=354760=354761=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Sun Feb 24 15:47:03 2019
@@ -558,13 +558,30 @@ static Hover getHoverContents(QualType T
   return H;
 }
 
-/// Generate a \p Hover object given the macro \p MacroInf.
-static Hover getHoverContents(llvm::StringRef MacroName) {
-  Hover H;
-
-  H.contents.value = "#define ";
-  H.contents.value += MacroName;
+/// Generate a \p Hover object given the macro \p MacroDecl.
+static Hover getHoverContents(MacroDecl Decl, ParsedAST ) {
+  SourceManager  = AST.getASTContext().getSourceManager();
+  std::string Definition = Decl.Name;
+
+  // Try to get the full definition, not just the name
+  SourceLocation StartLoc = Decl.Info->getDefinitionLoc();
+  SourceLocation EndLoc = Decl.Info->getDefinitionEndLoc();
+  if (EndLoc.isValid()) {
+EndLoc = Lexer::getLocForEndOfToken(EndLoc, 0, SM,
+AST.getASTContext().getLangOpts());
+bool Invalid;
+StringRef Buffer = SM.getBufferData(SM.getFileID(StartLoc), );
+if (!Invalid) {
+  unsigned StartOffset = SM.getFileOffset(StartLoc);
+  unsigned EndOffset = SM.getFileOffset(EndLoc);
+  if (EndOffset <= Buffer.size() && StartOffset < EndOffset)
+Definition = Buffer.substr(StartOffset, EndOffset - StartOffset).str();
+}
+  }
 
+  Hover H;
+  H.contents.kind = MarkupKind::PlainText;
+  H.contents.value = "#define " + Definition;
   return H;
 }
 
@@ -688,7 +705,7 @@ llvm::Optional getHover(ParsedAST
   auto Symbols = getSymbolAtPosition(AST, SourceLocationBeg);
 
   if (!Symbols.Macros.empty())
-return getHoverContents(Symbols.Macros[0].Name);
+return getHoverContents(Symbols.Macros[0], AST);
 
   if (!Symbols.Decls.empty())
 return getHoverContents(Symbols.Decls[0]);

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=354761=354760=354761=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Sun Feb 24 15:47:03 
2019
@@ -743,7 +743,25 @@ TEST(Hover, All) {
 #define MACRO 2
 #undef macro
   )cpp",
-  "#define MACRO",
+  "#define MACRO 1",
+  },
+  {
+  R"cpp(// Macro
+#define MACRO 0
+#define MACRO2 ^MACRO
+  )cpp",
+  "#define MACRO 0",
+  },
+  {
+  R"cpp(// Macro
+#define MACRO {\
+  return 0;\
+}
+int main() ^MACRO
+  )cpp",
+  R"cpp(#define MACRO {\
+  return 0;\
+})cpp",
   },
   {
   R"cpp(// Forward class declaration


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


[clang-tools-extra] r347509 - [clangd] Add 'Switch header/source' command in clangd-vscode

2018-11-23 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Fri Nov 23 18:53:17 2018
New Revision: 347509

URL: http://llvm.org/viewvc/llvm-project?rev=347509=rev
Log:
[clangd] Add 'Switch header/source' command in clangd-vscode

Summary:
Alt+o is used on Windows/Linux and Option+Cmd+o on macOS.

Signed-off-by: Marc-Andre Laperle 

Reviewers: hokein, ilya-biryukov, ioeric

Reviewed By: ioeric

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

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

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json?rev=347509=347508=347509=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Fri Nov 
23 18:53:17 2018
@@ -74,6 +74,20 @@
 "description": "Names a file that clangd should log a 
performance trace to, in chrome trace-viewer JSON format."
 }
 }
-}
+},
+"commands": [
+{
+"command": "clangd-vscode.switchheadersource",
+"title": "Switch between Source/Header"
+}
+],
+"keybindings": [
+{
+"command": "clangd-vscode.switchheadersource",
+"key": "Alt+o",
+"mac": "Alt+cmd+o",
+"when": "editorTextFocus"
+}
+]
 }
 }

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts?rev=347509=347508=347509=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts 
(original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts Fri 
Nov 23 18:53:17 2018
@@ -12,6 +12,12 @@ function getConfig(option: string, de
 return config.get(option, defaultValue);
 }
 
+namespace SwitchSourceHeaderRequest {
+export const type =
+new vscodelc.RequestType('textDocument/switchSourceHeader');
+}
+
 /**
  *  this method is called when your extension is activate
  *  your extension is activated the very first time the command is executed
@@ -51,8 +57,25 @@ export function activate(context: vscode
 }
 };
 
-const clangdClient = new vscodelc.LanguageClient('Clang Language Server', 
serverOptions, clientOptions);
-console.log('Clang Language Server is now active!');
-
-const disposable = clangdClient.start();
+  const clangdClient = new vscodelc.LanguageClient('Clang Language Server', 
serverOptions, clientOptions);
+  console.log('Clang Language Server is now active!');
+  context.subscriptions.push(clangdClient.start());
+  context.subscriptions.push(vscode.commands.registerCommand(
+  'clangd-vscode.switchheadersource', async () => {
+const uri =
+vscode.Uri.file(vscode.window.activeTextEditor.document.fileName);
+if (!uri) {
+  return;
+}
+const docIdentifier =
+vscodelc.TextDocumentIdentifier.create(uri.toString());
+const sourceUri = await clangdClient.sendRequest(
+SwitchSourceHeaderRequest.type, docIdentifier);
+if (!sourceUri) {
+  return;
+}
+const doc = await vscode.workspace.openTextDocument(
+vscode.Uri.parse(sourceUri));
+vscode.window.showTextDocument(doc);
+  }));
 }


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


[clang-tools-extra] r347119 - [clangd] Fix crash hovering on non-decltype trailing return

2018-11-16 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Fri Nov 16 16:41:14 2018
New Revision: 347119

URL: http://llvm.org/viewvc/llvm-project?rev=347119=rev
Log:
[clangd] Fix crash hovering on non-decltype trailing return

Summary:
More specifically, hovering on "auto" in
auto main() -> int {
return 0;
}

Signed-off-by: Marc-Andre Laperle 

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

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

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

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=347119=347118=347119=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri Nov 16 16:41:14 2018
@@ -605,6 +605,7 @@ public:
   // Handle auto return types:
   //- auto foo() {}
   //- auto& foo() {}
+  //- auto foo() -> int {}
   //- auto foo() -> decltype(1+1) {}
   //- operator auto() const { return 10; }
   bool VisitFunctionDecl(FunctionDecl *D) {
@@ -624,12 +625,13 @@ public:
 const AutoType *AT = D->getReturnType()->getContainedAutoType();
 if (AT && !AT->getDeducedType().isNull()) {
   DeducedType = AT->getDeducedType();
-} else {
+} else if (auto DT = dyn_cast(D->getReturnType())) {
   // auto in a trailing return type just points to a DecltypeType and
   // getContainedAutoType does not unwrap it.
-  const DecltypeType *DT = dyn_cast(D->getReturnType());
   if (!DT->getUnderlyingType().isNull())
 DeducedType = DT->getUnderlyingType();
+} else if (!D->getReturnType().isNull()) {
+  DeducedType = D->getReturnType();
 }
 return true;
   }

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=347119=347118=347119=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Fri Nov 16 16:41:14 
2018
@@ -836,6 +836,14 @@ TEST(Hover, All) {
   "",
   },
   {
+  R"cpp(// simple trailing return type
+^auto main() -> int {
+  return 0;
+}
+  )cpp",
+  "int",
+  },
+  {
   R"cpp(// auto function return with trailing type
 struct Bar {};
 ^auto test() -> decltype(Bar()) {


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


[clang-tools-extra] r336550 - [clangd] Mark "Document Symbols" as implemented in the docs

2018-07-09 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Mon Jul  9 07:34:07 2018
New Revision: 336550

URL: http://llvm.org/viewvc/llvm-project?rev=336550=rev
Log:
[clangd] Mark "Document Symbols" as implemented in the docs

Summary: Signed-off-by: Marc-Andre Laperle 

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

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

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=336550=336549=336550=diff
==
--- clang-tools-extra/trunk/docs/clangd.rst (original)
+++ clang-tools-extra/trunk/docs/clangd.rst Mon Jul  9 07:34:07 2018
@@ -81,7 +81,7 @@ extension to the protocol.
 +-++--+
 | Code Lens   | Yes|   No |
 +-++--+
-| Document Symbols| Yes|   No |
+| Document Symbols| Yes|   Yes|
 +-++--+
 | Workspace Symbols   | Yes|   No |
 +-++--+


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


[clang-tools-extra] r336386 - [clangd] Implementation of textDocument/documentSymbol

2018-07-05 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Thu Jul  5 12:35:01 2018
New Revision: 336386

URL: http://llvm.org/viewvc/llvm-project?rev=336386=rev
Log:
[clangd] Implementation of textDocument/documentSymbol

Summary:
An AST-based approach is used to retrieve the document symbols rather than an
in-memory index query. The index is not an ideal fit to achieve this because of
the file-centric query being done here whereas the index is suited for
project-wide queries. Document symbols also includes more symbols and need to
keep the order as seen in the file.

Signed-off-by: Marc-Andre Laperle 

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

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

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/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test
clang-tools-extra/trunk/test/clangd/symbols.test
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=336386=336385=336386=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Jul  5 12:35:01 2018
@@ -112,6 +112,7 @@ void ClangdLSPServer::onInitialize(Initi
 {"documentHighlightProvider", true},
 {"hoverProvider", true},
 {"renameProvider", true},
+{"documentSymbolProvider", true},
 {"workspaceSymbolProvider", true},
 {"executeCommandProvider",
  json::obj{
@@ -294,6 +295,19 @@ void ClangdLSPServer::onDocumentFormatti
llvm::toString(ReplacementsOrError.takeError()));
 }
 
+void ClangdLSPServer::onDocumentSymbol(DocumentSymbolParams ) {
+  Server.documentSymbols(
+  Params.textDocument.uri.file(),
+  [this](llvm::Expected> Items) {
+if (!Items)
+  return replyError(ErrorCode::InvalidParams,
+llvm::toString(Items.takeError()));
+for (auto  : *Items)
+  Sym.kind = adjustKindToCapability(Sym.kind, SupportedSymbolKinds);
+reply(json::ary(*Items));
+  });
+}
+
 void ClangdLSPServer::onCodeAction(CodeActionParams ) {
   // We provide a code action for each diagnostic at the requested location
   // which has FixIts available.

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=336386=336385=336386=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Thu Jul  5 12:35:01 2018
@@ -62,6 +62,7 @@ private:
   void
   onDocumentRangeFormatting(DocumentRangeFormattingParams ) override;
   void onDocumentFormatting(DocumentFormattingParams ) override;
+  void onDocumentSymbol(DocumentSymbolParams ) override;
   void onCodeAction(CodeActionParams ) override;
   void onCompletion(TextDocumentPositionParams ) override;
   void onSignatureHelp(TextDocumentPositionParams ) override;

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=336386=336385=336386=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Jul  5 12:35:01 2018
@@ -456,6 +456,18 @@ void ClangdServer::workspaceSymbols(
  RootPath ? *RootPath : ""));
 }
 
+void ClangdServer::documentSymbols(
+StringRef File, Callback> CB) {
+  auto Action = [](Callback> CB,
+   llvm::Expected InpAST) {
+if (!InpAST)
+  return CB(InpAST.takeError());
+CB(clangd::getDocumentSymbols(InpAST->AST));
+  };
+  WorkScheduler.runWithAST("documentSymbols", File,
+   Bind(Action, std::move(CB)));
+}
+
 std::vector>
 

[clang-tools-extra] r336119 - [clangd] Implement hover for "auto" and "decltype"

2018-07-02 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Mon Jul  2 09:28:34 2018
New Revision: 336119

URL: http://llvm.org/viewvc/llvm-project?rev=336119=rev
Log:
[clangd] Implement hover for "auto" and "decltype"

Summary:
This allows hovering on keywords that refer to deduced types.
This should cover most useful cases. Not covered:
- auto template parameters: Since this can be instantiated with many types,
it would not be practical to show the types.
- Structured binding: This could be done later to show multiple deduced types
in the hover.
- auto:: (part of concepts): Outside the scope of this patch.

Signed-off-by: Marc-Andre Laperle 

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

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

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.h
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=336119=336118=336119=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Mon Jul  2 09:28:34 2018
@@ -12,6 +12,7 @@
 #include "SourceCode.h"
 #include "URI.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Index/IndexDataConsumer.h"
 #include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
@@ -516,6 +517,18 @@ static Hover getHoverContents(const Decl
   return H;
 }
 
+/// Generate a \p Hover object given the type \p T.
+static Hover getHoverContents(QualType T, ASTContext ) {
+  Hover H;
+  std::string TypeText;
+  llvm::raw_string_ostream OS(TypeText);
+  PrintingPolicy Policy = PrintingPolicyForDecls(ASTCtx.getPrintingPolicy());
+  T.print(OS, Policy);
+  OS.flush();
+  H.contents.value += TypeText;
+  return H;
+}
+
 /// Generate a \p Hover object given the macro \p MacroInf.
 static Hover getHoverContents(StringRef MacroName) {
   Hover H;
@@ -526,6 +539,131 @@ static Hover getHoverContents(StringRef
   return H;
 }
 
+namespace {
+/// Computes the deduced type at a given location by visiting the relevant
+/// nodes. We use this to display the actual type when hovering over an "auto"
+/// keyword or "decltype()" expression.
+/// FIXME: This could have been a lot simpler by visiting AutoTypeLocs but it
+/// seems that the AutoTypeLocs that can be visited along with their AutoType 
do
+/// not have the deduced type set. Instead, we have to go to the appropriate
+/// DeclaratorDecl/FunctionDecl and work our back to the AutoType that does 
have
+/// a deduced type set. The AST should be improved to simplify this scenario.
+class DeducedTypeVisitor : public RecursiveASTVisitor {
+  SourceLocation SearchedLocation;
+  llvm::Optional DeducedType;
+
+public:
+  DeducedTypeVisitor(SourceLocation SearchedLocation)
+  : SearchedLocation(SearchedLocation) {}
+
+  llvm::Optional getDeducedType() { return DeducedType; }
+
+  // Handle auto initializers:
+  //- auto i = 1;
+  //- decltype(auto) i = 1;
+  //- auto& i = 1;
+  bool VisitDeclaratorDecl(DeclaratorDecl *D) {
+if (!D->getTypeSourceInfo() ||
+D->getTypeSourceInfo()->getTypeLoc().getLocStart() != SearchedLocation)
+  return true;
+
+auto DeclT = D->getType();
+// "auto &" is represented as a ReferenceType containing an AutoType
+if (const ReferenceType *RT = dyn_cast(DeclT.getTypePtr()))
+  DeclT = RT->getPointeeType();
+
+const AutoType *AT = dyn_cast(DeclT.getTypePtr());
+if (AT && !AT->getDeducedType().isNull()) {
+  // For auto, use the underlying type because the const& would be
+  // represented twice: written in the code and in the hover.
+  // Example: "const auto I = 1", we only want "int" when hovering on auto,
+  // not "const int".
+  //
+  // For decltype(auto), take the type as is because it cannot be written
+  // with qualifiers or references but its decuded type can be const-ref.
+  DeducedType = AT->isDecltypeAuto() ? DeclT : DeclT.getUnqualifiedType();
+}
+return true;
+  }
+
+  // Handle auto return types:
+  //- auto foo() {}
+  //- auto& foo() {}
+  //- auto foo() -> decltype(1+1) {}
+  //- operator auto() const { return 10; }
+  bool VisitFunctionDecl(FunctionDecl *D) {
+if (!D->getTypeSourceInfo())
+  return true;
+// Loc of auto in return type (c++14).
+auto CurLoc = D->getReturnTypeSourceRange().getBegin();
+// Loc of "auto" in operator auto()
+if (CurLoc.isInvalid() && dyn_cast(D))
+  CurLoc = D->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
+// Loc of "auto" in function with traling return type (c++11).
+if (CurLoc.isInvalid())
+  CurLoc = D->getSourceRange().getBegin();
+if (CurLoc != SearchedLocation)
+  

[clang-tools-extra] r335624 - [clangd] Simplify matches in FindSymbols tests

2018-06-26 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Tue Jun 26 09:57:44 2018
New Revision: 335624

URL: http://llvm.org/viewvc/llvm-project?rev=335624=rev
Log:
[clangd] Simplify matches in FindSymbols tests

Summary:
Instead of checking symbol name and container (scope) separately, check the
qualified name instead. This is much shorter and similar to how it is done
in the SymbolCollector tests.

Signed-off-by: Marc-Andre Laperle 

Reviewers: simark

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

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

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

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=335624=335623=335624=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp Tue Jun 26 
09:57:44 2018
@@ -31,9 +31,10 @@ class IgnoreDiagnostics : public Diagnos
 };
 
 // GMock helpers for matching SymbolInfos items.
-MATCHER_P(Named, Name, "") { return arg.name == Name; }
-MATCHER_P(InContainer, ContainerName, "") {
-  return arg.containerName == ContainerName;
+MATCHER_P(QName, Name, "") {
+  if (arg.containerName.empty())
+return arg.name == Name;
+  return (arg.containerName + "::" + arg.name) == Name;
 }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
 
@@ -106,12 +107,10 @@ TEST_F(WorkspaceSymbolsTest, Globals) {
   #include "foo.h"
   )cpp");
   EXPECT_THAT(getSymbols("global"),
-  UnorderedElementsAre(AllOf(Named("GlobalStruct"), 
InContainer(""),
- WithKind(SymbolKind::Struct)),
-   AllOf(Named("global_func"), InContainer(""),
- WithKind(SymbolKind::Function)),
-   AllOf(Named("global_var"), InContainer(""),
- WithKind(SymbolKind::Variable;
+  UnorderedElementsAre(
+  AllOf(QName("GlobalStruct"), WithKind(SymbolKind::Struct)),
+  AllOf(QName("global_func"), WithKind(SymbolKind::Function)),
+  AllOf(QName("global_var"), WithKind(SymbolKind::Variable;
 }
 
 TEST_F(WorkspaceSymbolsTest, Unnamed) {
@@ -123,12 +122,11 @@ TEST_F(WorkspaceSymbolsTest, Unnamed) {
   #include "foo.h"
   )cpp");
   EXPECT_THAT(getSymbols("UnnamedStruct"),
-  ElementsAre(AllOf(Named("UnnamedStruct"),
+  ElementsAre(AllOf(QName("UnnamedStruct"),
 WithKind(SymbolKind::Variable;
-  EXPECT_THAT(
-  getSymbols("InUnnamed"),
-  ElementsAre(AllOf(Named("InUnnamed"), InContainer("(anonymous struct)"),
-WithKind(SymbolKind::Field;
+  EXPECT_THAT(getSymbols("InUnnamed"),
+  ElementsAre(AllOf(QName("(anonymous struct)::InUnnamed"),
+WithKind(SymbolKind::Field;
 }
 
 TEST_F(WorkspaceSymbolsTest, InMainFile) {
@@ -151,28 +149,20 @@ TEST_F(WorkspaceSymbolsTest, Namespaces)
   addFile("foo.cpp", R"cpp(
   #include "foo.h"
   )cpp");
-  EXPECT_THAT(
-  getSymbols("a"),
-  UnorderedElementsAre(AllOf(Named("ans1"), InContainer("")),
-   AllOf(Named("ai1"), InContainer("ans1")),
-   AllOf(Named("ans2"), InContainer("ans1")),
-   AllOf(Named("ai2"), InContainer("ans1::ans2";
-  EXPECT_THAT(getSymbols("::"),
-  ElementsAre(AllOf(Named("ans1"), InContainer("";
-  EXPECT_THAT(getSymbols("::a"),
-  ElementsAre(AllOf(Named("ans1"), InContainer("";
+  EXPECT_THAT(getSymbols("a"),
+  UnorderedElementsAre(QName("ans1"), QName("ans1::ai1"),
+   QName("ans1::ans2"),
+   QName("ans1::ans2::ai2")));
+  EXPECT_THAT(getSymbols("::"), ElementsAre(QName("ans1")));
+  EXPECT_THAT(getSymbols("::a"), ElementsAre(QName("ans1")));
   EXPECT_THAT(getSymbols("ans1::"),
-  UnorderedElementsAre(AllOf(Named("ai1"), InContainer("ans1")),
-   AllOf(Named("ans2"), InContainer("ans1";
-  EXPECT_THAT(getSymbols("::ans1"),
-  ElementsAre(AllOf(Named("ans1"), InContainer("";
+  UnorderedElementsAre(QName("ans1::ai1"), QName("ans1::ans2")));
+  EXPECT_THAT(getSymbols("::ans1"), ElementsAre(QName("ans1")));
   EXPECT_THAT(getSymbols("::ans1::"),
-  UnorderedElementsAre(AllOf(Named("ai1"), InContainer("ans1")),
-   AllOf(Named("ans2"), InContainer("ans1";
-  EXPECT_THAT(getSymbols("::ans1::ans2"),
-  ElementsAre(AllOf(Named("ans2"), InContainer("ans1";
+ 

[clang-tools-extra] r334018 - [clangd] Remove unused variables

2018-06-05 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Tue Jun  5 07:07:45 2018
New Revision: 334018

URL: http://llvm.org/viewvc/llvm-project?rev=334018=rev
Log:
[clangd] Remove unused variables

Summary: Signed-off-by: Marc-Andre Laperle 

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

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

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

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=334018=334017=334018=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Jun  5 07:07:45 2018
@@ -298,9 +298,8 @@ void ClangdServer::dumpAST(PathRef File,
 
 void ClangdServer::findDefinitions(PathRef File, Position Pos,
Callback> CB) {
-  auto FS = FSProvider.getFileSystem();
-  auto Action = [Pos, FS, this](Callback> CB,
-llvm::Expected InpAST) {
+  auto Action = [Pos, this](Callback> CB,
+llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
 CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
@@ -391,10 +390,8 @@ ClangdServer::formatCode(llvm::StringRef
 
 void ClangdServer::findDocumentHighlights(
 PathRef File, Position Pos, Callback> CB) {
-
-  auto FS = FSProvider.getFileSystem();
-  auto Action = [FS, Pos](Callback> CB,
-  llvm::Expected InpAST) {
+  auto Action = [Pos](Callback> CB,
+  llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
 CB(clangd::findDocumentHighlights(InpAST->AST, Pos));
@@ -405,9 +402,8 @@ void ClangdServer::findDocumentHighlight
 
 void ClangdServer::findHover(PathRef File, Position Pos,
  Callback> CB) {
-  auto FS = FSProvider.getFileSystem();
-  auto Action = [Pos, FS](Callback> CB,
-  llvm::Expected InpAST) {
+  auto Action = [Pos](Callback> CB,
+  llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
 CB(clangd::getHover(InpAST->AST, Pos));


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


[clang-tools-extra] r334017 - [clangd] Add "member" symbols to the index

2018-06-05 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Tue Jun  5 07:01:40 2018
New Revision: 334017

URL: http://llvm.org/viewvc/llvm-project?rev=334017=rev
Log:
[clangd] Add "member" symbols to the index

Summary:
This adds more symbols to the index:
- member variables and functions
- enum constants in scoped enums

The code completion behavior should remain intact but workspace symbols should
now provide much more useful symbols.
Other symbols should be considered such as the ones in "main files" (files not
being included) but this can be done separately as this introduces its fair
share of problems.

Signed-off-by: Marc-Andre Laperle 

Reviewers: ioeric, sammccall

Reviewed By: ioeric, sammccall

Subscribers: hokein, sammccall, jkorous, klimek, ilya-biryukov, jkorous-apple, 
ioeric, MaskRay, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.h
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.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=334017=334016=334017=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Jun  5 07:01:40 2018
@@ -25,6 +25,7 @@
 #include "Trace.h"
 #include "URI.h"
 #include "index/Index.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -949,6 +950,7 @@ private:
 if (Opts.Limit)
   Req.MaxCandidateCount = Opts.Limit;
 Req.Query = Filter->pattern();
+Req.RestrictForCodeCompletion = true;
 Req.Scopes = getQueryScopes(Recorder->CCContext,
 Recorder->CCSema->getSourceManager());
 log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])",
@@ -1089,5 +1091,16 @@ SignatureHelp signatureHelp(PathRef File
   return Result;
 }
 
+bool isIndexedForCodeCompletion(const NamedDecl , ASTContext ) {
+  using namespace clang::ast_matchers;
+  auto InTopLevelScope = hasDeclContext(
+  anyOf(namespaceDecl(), translationUnitDecl(), linkageSpecDecl()));
+  return !match(decl(anyOf(InTopLevelScope,
+   hasDeclContext(
+   enumDecl(InTopLevelScope, 
unless(isScoped()),
+ND, ASTCtx)
+  .empty();
+}
+
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/clangd/CodeComplete.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=334017=334016=334017=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.h (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.h Tue Jun  5 07:01:40 2018
@@ -25,6 +25,7 @@
 #include "clang/Tooling/CompilationDatabase.h"
 
 namespace clang {
+class NamedDecl;
 class PCHContainerOperations;
 namespace clangd {
 
@@ -82,6 +83,17 @@ SignatureHelp signatureHelp(PathRef File
 IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHs);
 
+// For index-based completion, we only consider:
+//   * symbols in namespaces or translation unit scopes (e.g. no class
+// members, no locals)
+//   * enum constants in unscoped enum decl (e.g. "red" in "enum {red};")
+//   * primary templates (no specializations)
+// For the other cases, we let Clang do the completion because it does not
+// need any non-local information and it will be much better at following
+// lookup rules. Other symbols still appear in the index for other purposes,
+// like workspace/symbols or textDocument/definition, but are not used for code
+// completion.
+bool isIndexedForCodeCompletion(const NamedDecl , ASTContext );
 } // namespace clangd
 } // namespace clang
 

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=334017=334016=334017=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Tue Jun  5 07:01:40 2018
@@ -149,9 +149,11 @@ struct Symbol {
   // The number of translation units that 

[clang-tools-extra] r330637 - [clangd] Implementation of workspace/symbol request

2018-04-23 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Mon Apr 23 13:00:52 2018
New Revision: 330637

URL: http://llvm.org/viewvc/llvm-project?rev=330637=rev
Log:
[clangd] Implementation of workspace/symbol request

Summary:
This is a basic implementation of the "workspace/symbol" request which is
used to find symbols by a string query. Since this is similar to code completion
in terms of result, this implementation reuses the "fuzzyFind" in order to get
matches. For now, the scoring algorithm is the same as code completion and
improvements could be done in the future.

The index model doesn't contain quite enough symbols for this to cover
common symbols like methods, enum class enumerators, functions in unamed
namespaces, etc. The index model will be augmented separately to achieve this.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

Subscribers: jkorous, hokein, simark, sammccall, klimek, mgorny, ilya-biryukov, 
mgrang, jkorous-apple, ioeric, MaskRay, cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/FindSymbols.h
clang-tools-extra/trunk/test/clangd/symbols.test
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.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/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/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=330637=330636=330637=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Mon Apr 23 13:00:52 2018
@@ -19,6 +19,7 @@ add_clang_library(clangDaemon
   Context.cpp
   Diagnostics.cpp
   DraftStore.cpp
+  FindSymbols.cpp
   FuzzyMatch.cpp
   GlobalCompilationDatabase.cpp
   Headers.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=330637=330636=330637=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Apr 23 13:00:52 2018
@@ -86,6 +86,14 @@ std::vector replacementsToEdit
   return Edits;
 }
 
+SymbolKindBitset defaultSymbolKinds() {
+  SymbolKindBitset Defaults;
+  for (size_t I = SymbolKindMin; I <= static_cast(SymbolKind::Array);
+   ++I)
+Defaults.set(I);
+  return Defaults;
+}
+
 } // namespace
 
 void ClangdLSPServer::onInitialize(InitializeParams ) {
@@ -97,6 +105,14 @@ void ClangdLSPServer::onInitialize(Initi
   CCOpts.EnableSnippets =
   
Params.capabilities.textDocument.completion.completionItem.snippetSupport;
 
+  if (Params.capabilities.workspace && Params.capabilities.workspace->symbol &&
+  Params.capabilities.workspace->symbol->symbolKind) {
+for (SymbolKind Kind :
+ *Params.capabilities.workspace->symbol->symbolKind->valueSet) {
+  SupportedSymbolKinds.set(static_cast(Kind));
+}
+  }
+
   reply(json::obj{
   {{"capabilities",
 json::obj{
@@ -122,6 +138,7 @@ void ClangdLSPServer::onInitialize(Initi
 {"documentHighlightProvider", true},
 {"hoverProvider", true},
 {"renameProvider", true},
+{"workspaceSymbolProvider", true},
 {"executeCommandProvider",
  json::obj{
  {"commands",
@@ -245,6 +262,20 @@ void ClangdLSPServer::onCommand(ExecuteC
   }
 }
 
+void ClangdLSPServer::onWorkspaceSymbol(WorkspaceSymbolParams ) {
+  Server.workspaceSymbols(
+  Params.query, CCOpts.Limit,
+  [this](llvm::Expected Items) {
+if (!Items)
+  return replyError(ErrorCode::InternalError,
+llvm::toString(Items.takeError()));
+for (auto  : *Items)
+  Sym.kind = adjustKindToCapability(Sym.kind, SupportedSymbolKinds);
+
+reply(json::ary(*Items));
+ 

[clang-tools-extra] r329725 - [clangd] Use operator<< to prevent printers issues in Gtest

2018-04-10 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Tue Apr 10 10:34:46 2018
New Revision: 329725

URL: http://llvm.org/viewvc/llvm-project?rev=329725=rev
Log:
[clangd] Use operator<< to prevent printers issues in Gtest

Summary:
It is possible that there will be two different instantiations of
the printer template for a given type and some tests could end up calling the
wrong (default) one. For example, it was seen in CodeCompleteTests.cpp when
printing CompletionItems that it would use the wrong printer because the default
is also instantiated in ClangdTests.cpp.

With this change, objects that were previously printed with a custom Printer now
get printed through the operator<< which is declared alongside the class.
This rule of the thumb should make it less error-prone.

Reviewers: simark, ilya-biryukov, sammccall

Reviewed By: simark, ilya-biryukov, sammccall

Subscribers: bkramer, hokein, sammccall, klimek, ilya-biryukov, jkorous-apple, 
ioeric, MaskRay, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/JSONExprTests.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=329725=329724=329725=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Tue Apr 10 10:34:46 2018
@@ -446,6 +446,11 @@ json::Expr toJSON(const CompletionItem &
   return std::move(Result);
 }
 
+llvm::raw_ostream <<(llvm::raw_ostream , const CompletionItem ) {
+  O << I.label << " - " << toJSON(I);
+  return O;
+}
+
 bool operator<(const CompletionItem , const CompletionItem ) {
   return (L.sortText.empty() ? L.label : L.sortText) <
  (R.sortText.empty() ? R.label : R.sortText);
@@ -477,6 +482,12 @@ json::Expr toJSON(const SignatureInforma
   return std::move(Result);
 }
 
+llvm::raw_ostream <<(llvm::raw_ostream ,
+  const SignatureInformation ) {
+  O << I.label << " - " << toJSON(I);
+  return O;
+}
+
 json::Expr toJSON(const SignatureHelp ) {
   assert(SH.activeSignature >= 0 &&
  "Unexpected negative value for number of active signatures.");
@@ -502,6 +513,16 @@ json::Expr toJSON(const DocumentHighligh
   };
 }
 
+llvm::raw_ostream <<(llvm::raw_ostream ,
+  const DocumentHighlight ) {
+  O << V.range;
+  if (V.kind == DocumentHighlightKind::Read)
+O << "(r)";
+  if (V.kind == DocumentHighlightKind::Write)
+O << "(w)";
+  return O;
+}
+
 bool fromJSON(const json::Expr , DidChangeConfigurationParams ) {
   json::ObjectMapper O(Params);
   return O && O.map("settings", CCP.settings);

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=329725=329724=329725=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Tue Apr 10 10:34:46 2018
@@ -670,6 +670,7 @@ struct CompletionItem {
   //  between a completion and a completion resolve request.
 };
 json::Expr toJSON(const CompletionItem &);
+llvm::raw_ostream <<(llvm::raw_ostream &, const CompletionItem &);
 
 bool operator<(const CompletionItem &, const CompletionItem &);
 
@@ -708,6 +709,8 @@ struct SignatureInformation {
   std::vector parameters;
 };
 json::Expr toJSON(const SignatureInformation &);
+llvm::raw_ostream <<(llvm::raw_ostream &,
+  const SignatureInformation &);
 
 /// Represents the signature of a callable.
 struct SignatureHelp {
@@ -761,6 +764,7 @@ struct DocumentHighlight {
   }
 };
 json::Expr toJSON(const DocumentHighlight );
+llvm::raw_ostream <<(llvm::raw_ostream &, const DocumentHighlight &);
 
 } // namespace clangd
 } // namespace clang

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=329725=329724=329725=diff
==
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Tue Apr 10 
10:34:46 2018
@@ -22,33 +22,6 @@
 
 namespace clang {
 namespace clangd {
-// Let GMock print completion items and signature help.
-void PrintTo(const CompletionItem , std::ostream *O) {
-  llvm::raw_os_ostream OS(*O);
-  OS << I.label << " - " << toJSON(I);
-}
-void PrintTo(const std::vector , std::ostream *O) {
-  *O << "{\n";
-  for (const auto  : V) {
-*O << 

[clang-tools-extra] r329574 - [clangd-vscode] Update VScode dependencies

2018-04-09 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Mon Apr  9 07:32:12 2018
New Revision: 329574

URL: http://llvm.org/viewvc/llvm-project?rev=329574=rev
Log:
[clangd-vscode] Update VScode dependencies

Summary:
This allows the extension to work with LSP 3.0 and is useful for testing.

Signed-off-by: Marc-Andre Laperle 

Reviewers: ilya-biryukov

Subscribers: hokein, klimek, ilya-biryukov, jkorous-apple, ioeric, MaskRay, 
cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json?rev=329574=329573=329574=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Mon Apr  
9 07:32:12 2018
@@ -6,7 +6,7 @@
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html;,
 "engines": {
-"vscode": "^1.15.0"
+"vscode": "^1.18.0"
 },
 "categories": [
 "Languages",
@@ -32,12 +32,12 @@
 "test": "node ./node_modules/vscode/bin/test"
 },
 "dependencies": {
-"vscode-languageclient": "^3.3.0",
-"vscode-languageserver": "^3.3.0"
+"vscode-languageclient": "^4.0.0",
+"vscode-languageserver": "^4.0.0"
 },
 "devDependencies": {
 "typescript": "^2.0.3",
-"vscode": "^1.0.3",
+"vscode": "^1.1.0",
 "mocha": "^2.3.3",
 "@types/node": "^6.0.40",
 "@types/mocha": "^2.2.32"


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


[clang-tools-extra] r328792 - [clangd] Mark "Source Hover" as implemented in the docs

2018-03-29 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Thu Mar 29 07:49:21 2018
New Revision: 328792

URL: http://llvm.org/viewvc/llvm-project?rev=328792=rev
Log:
[clangd] Mark "Source Hover" as implemented in the docs

Summary: Signed-off-by: Marc-Andre Laperle 

Reviewers: simark

Reviewed By: simark

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

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

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=328792=328791=328792=diff
==
--- clang-tools-extra/trunk/docs/clangd.rst (original)
+++ clang-tools-extra/trunk/docs/clangd.rst Thu Mar 29 07:49:21 2018
@@ -75,7 +75,7 @@ extension to the protocol.
 +-++--+
 | Rename  | Yes|   Yes|
 +-++--+
-| Source hover| Yes|   No |
+| Source hover| Yes|   Yes|
 +-++--+
 | Find References | Yes|   No |
 +-++--+


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


[clang-tools-extra] r325662 - [clangd] #include statements support for Open definition

2018-02-20 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Tue Feb 20 18:39:08 2018
New Revision: 325662

URL: http://llvm.org/viewvc/llvm-project?rev=325662=rev
Log:
[clangd] #include statements support for Open definition

Summary: ctrl-clicking on #include statements now opens the file being pointed 
by that statement.

Reviewers: malaperle, krasimir, bkramer, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: jkorous-apple, ioeric, mgrang, klimek, ilya-biryukov, arphaman, 
cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=325662=325661=325662=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Feb 20 18:39:08 2018
@@ -81,12 +81,60 @@ private:
   std::vector TopLevelDecls;
 };
 
+// Converts a half-open clang source range to an LSP range.
+// Note that clang also uses closed source ranges, which this can't handle!
+Range toRange(CharSourceRange R, const SourceManager ) {
+  // Clang is 1-based, LSP uses 0-based indexes.
+  Position Begin;
+  Begin.line = static_cast(M.getSpellingLineNumber(R.getBegin())) - 1;
+  Begin.character =
+  static_cast(M.getSpellingColumnNumber(R.getBegin())) - 1;
+
+  Position End;
+  End.line = static_cast(M.getSpellingLineNumber(R.getEnd())) - 1;
+  End.character = static_cast(M.getSpellingColumnNumber(R.getEnd())) - 1;
+
+  return {Begin, End};
+}
+
+class InclusionLocationsCollector : public PPCallbacks {
+public:
+  InclusionLocationsCollector(SourceManager ,
+  InclusionLocations )
+  : SourceMgr(SourceMgr), IncLocations(IncLocations) {}
+
+  void InclusionDirective(SourceLocation HashLoc, const Token ,
+  StringRef FileName, bool IsAngled,
+  CharSourceRange FilenameRange, const FileEntry *File,
+  StringRef SearchPath, StringRef RelativePath,
+  const Module *Imported) override {
+auto SR = FilenameRange.getAsRange();
+if (SR.isInvalid() || !File || File->tryGetRealPathName().empty())
+  return;
+
+if (SourceMgr.isInMainFile(SR.getBegin())) {
+  // Only inclusion directives in the main file make sense. The user cannot
+  // select directives not in the main file.
+  IncLocations.emplace_back(toRange(FilenameRange, SourceMgr),
+File->tryGetRealPathName());
+}
+  }
+
+private:
+  SourceManager 
+  InclusionLocations 
+};
+
 class CppFilePreambleCallbacks : public PreambleCallbacks {
 public:
   std::vector takeTopLevelDeclIDs() {
 return std::move(TopLevelDeclIDs);
   }
 
+  InclusionLocations takeInclusionLocations() {
+return std::move(IncLocations);
+  }
+
   void AfterPCHEmitted(ASTWriter ) override {
 TopLevelDeclIDs.reserve(TopLevelDecls.size());
 for (Decl *D : TopLevelDecls) {
@@ -105,9 +153,21 @@ public:
 }
   }
 
+  void BeforeExecute(CompilerInstance ) override {
+SourceMgr = ();
+  }
+
+  std::unique_ptr createPPCallbacks() override {
+assert(SourceMgr && "SourceMgr must be set at this point");
+return llvm::make_unique(*SourceMgr,
+  IncLocations);
+  }
+
 private:
   std::vector TopLevelDecls;
   std::vector TopLevelDeclIDs;
+  InclusionLocations IncLocations;
+  SourceManager *SourceMgr = nullptr;
 };
 
 /// Convert from clang diagnostic level to LSP severity.
@@ -139,22 +199,6 @@ bool locationInRange(SourceLocation L, C
   return L != R.getEnd() && M.isPointWithin(L, R.getBegin(), R.getEnd());
 }
 
-// Converts a half-open clang source range to an LSP range.
-// Note that clang also uses closed source ranges, which this can't handle!
-Range toRange(CharSourceRange R, const SourceManager ) {
-  // Clang is 1-based, LSP uses 0-based indexes.
-  Position Begin;
-  Begin.line = static_cast(M.getSpellingLineNumber(R.getBegin())) - 1;
-  Begin.character =
-  static_cast(M.getSpellingColumnNumber(R.getBegin())) - 1;
-
-  Position End;
-  End.line = static_cast(M.getSpellingLineNumber(R.getEnd())) - 1;
-  End.character = static_cast(M.getSpellingColumnNumber(R.getEnd())) - 1;
-
-  return {Begin, End};
-}
-
 // Clang diags have a location (shown as ^) and 0 or more ranges ().
 // LSP needs a single range.
 Range diagnosticRange(const clang::Diagnostic , const LangOptions ) {
@@ -267,6 +311,17 @@ ParsedAST::Build(std::unique_ptrIncLocations;
+
+  

[clang-tools-extra] r325409 - [clangd] Rename some protocol field to lower case

2018-02-16 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Fri Feb 16 15:12:26 2018
New Revision: 325409

URL: http://llvm.org/viewvc/llvm-project?rev=325409=rev
Log:
[clangd] Rename some protocol field to lower case

Summary:
Also fixes a GCC compilation error.

Signed-off-by: Marc-Andre Laperle 

Subscribers: klimek, ilya-biryukov, jkorous-apple, ioeric, cfe-commits

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

Modified:
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/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=325409=325408=325409=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Fri Feb 16 15:12:26 2018
@@ -397,20 +397,20 @@ static StringRef toTextKind(MarkupKind K
 }
 
 json::Expr toJSON(const MarkupContent ) {
-  if (MC.Value.empty())
+  if (MC.value.empty())
 return nullptr;
 
   return json::obj{
-  {"kind", toTextKind(MC.Kind)},
-  {"value", MC.Value},
+  {"kind", toTextKind(MC.kind)},
+  {"value", MC.value},
   };
 }
 
 json::Expr toJSON(const Hover ) {
-  json::obj Result{{"contents", toJSON(H.Contents)}};
+  json::obj Result{{"contents", toJSON(H.contents)}};
 
-  if (H.Range.hasValue())
-Result["range"] = toJSON(*H.Range);
+  if (H.range.hasValue())
+Result["range"] = toJSON(*H.range);
 
   return std::move(Result);
 }

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=325409=325408=325409=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Fri Feb 16 15:12:26 2018
@@ -486,18 +486,18 @@ enum class MarkupKind {
 };
 
 struct MarkupContent {
-  MarkupKind Kind = MarkupKind::PlainText;
-  std::string Value;
+  MarkupKind kind = MarkupKind::PlainText;
+  std::string value;
 };
 json::Expr toJSON(const MarkupContent );
 
 struct Hover {
   /// The hover's content
-  MarkupContent Contents;
+  MarkupContent contents;
 
   /// An optional range is a range inside a text document
   /// that is used to visualize a hover, e.g. by changing the background color.
-  llvm::Optional Range;
+  llvm::Optional range;
 };
 json::Expr toJSON(const Hover );
 

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=325409=325408=325409=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Fri Feb 16 15:12:26 2018
@@ -382,9 +382,9 @@ static Hover getHoverContents(const Decl
   if (NamedScope) {
 assert(!NamedScope->empty());
 
-H.Contents.Value += "Declared in ";
-H.Contents.Value += *NamedScope;
-H.Contents.Value += "\n\n";
+H.contents.value += "Declared in ";
+H.contents.value += *NamedScope;
+H.contents.value += "\n\n";
   }
 
   // We want to include the template in the Hover.
@@ -401,7 +401,7 @@ static Hover getHoverContents(const Decl
 
   OS.flush();
 
-  H.Contents.Value += DeclText;
+  H.contents.value += DeclText;
   return H;
 }
 
@@ -409,8 +409,8 @@ static Hover getHoverContents(const Decl
 static Hover getHoverContents(StringRef MacroName) {
   Hover H;
 
-  H.Contents.Value = "#define ";
-  H.Contents.Value += MacroName;
+  H.contents.value = "#define ";
+  H.contents.value += MacroName;
 
   return H;
 }

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=325409=325408=325409=diff
==
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp Fri Feb 16 15:12:26 
2018
@@ -559,7 +559,7 @@ TEST(Hover, All) {
 auto AST = build(T.code());
 Hover H = getHover(AST, T.point());
 
-EXPECT_EQ(H.Contents.Value, Test.ExpectedHover) << Test.Input;
+EXPECT_EQ(H.contents.value, Test.ExpectedHover) << Test.Input;
   }
 }
 


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


[clang-tools-extra] r325395 - [clangd] Implement textDocument/hover

2018-02-16 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Fri Feb 16 13:38:15 2018
New Revision: 325395

URL: http://llvm.org/viewvc/llvm-project?rev=325395=rev
Log:
[clangd] Implement textDocument/hover

Summary: Implemention of textDocument/hover as described in LSP definition.

This patch adds a basic Hover implementation.  When hovering a variable,
function, method or namespace, clangd will return a text containing the
declaration's scope, as well as the declaration of the hovered entity.
For example, for a variable:

  Declared in class Foo::Bar

  int hello = 2

For macros, the macro definition is returned.

This patch doesn't include:

- markdown support (the client I use doesn't support it yet)
- range support (optional in the Hover response)
- comments associated to variables/functions/classes

They are kept as future work to keep this patch simpler.

I added tests in XRefsTests.cpp.  hover.test contains one simple
smoketest to make sure the feature works from a black box perspective.

Reviewers: malaperle, krasimir, bkramer, ilya-biryukov

Subscribers: sammccall, mgrang, klimek, rwols, ilya-biryukov, arphaman, 
cfe-commits

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

Signed-off-by: Simon Marchi 
Signed-off-by: William Enright 

Added:
clang-tools-extra/trunk/test/clangd/hover.test
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/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/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/XRefs.h
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=325395=325394=325395=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri Feb 16 13:38:15 2018
@@ -118,6 +118,7 @@ void ClangdLSPServer::onInitialize(Initi
  }},
 {"definitionProvider", true},
 {"documentHighlightProvider", true},
+{"hoverProvider", true},
 {"renameProvider", true},
 {"executeCommandProvider",
  json::obj{
@@ -355,6 +356,19 @@ void ClangdLSPServer::onDocumentHighligh
   });
 }
 
+void ClangdLSPServer::onHover(TextDocumentPositionParams ) {
+  Server.findHover(Params.textDocument.uri.file(), Params.position,
+   [](llvm::Expected H) {
+ if (!H) {
+   replyError(ErrorCode::InternalError,
+  llvm::toString(H.takeError()));
+   return;
+ }
+
+ reply(H->Value);
+   });
+}
+
 ClangdLSPServer::ClangdLSPServer(JSONOutput , unsigned AsyncThreadsCount,
  bool StorePreamblesInMemory,
  const clangd::CodeCompleteOptions ,

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=325395=325394=325395=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Fri Feb 16 13:38:15 2018
@@ -75,6 +75,7 @@ private:
   void onFileEvent(DidChangeWatchedFilesParams ) override;
   void onCommand(ExecuteCommandParams ) override;
   void onRename(RenameParams ) override;
+  void onHover(TextDocumentPositionParams ) override;
 
   std::vector getFixIts(StringRef File, const clangd::Diagnostic );
 

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=325395=325394=325395=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Fri Feb 16 13:38:15 2018
@@ -491,6 +491,29 @@ void ClangdServer::findDocumentHighlight
   WorkScheduler.runWithAST(File, BindWithForward(Action, std::move(Callback)));
 }
 
+void ClangdServer::findHover(
+PathRef File, Position Pos,
+UniqueFunction)> Callback) {
+  Hover FinalHover;
+  auto FileContents = DraftMgr.getDraft(File);
+  if 

[clang-tools-extra] r320988 - [clangd] Update documentation page with new features, instructions

2017-12-18 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Mon Dec 18 06:59:01 2017
New Revision: 320988

URL: http://llvm.org/viewvc/llvm-project?rev=320988=rev
Log:
[clangd] Update documentation page with new features, instructions

Summary:
- Some features were implemented so mark them as such.
- Add installation instructions (LLVM debian packages)

Signed-off-by: Marc-Andre Laperle 

Reviewers: jkorous-apple

Reviewed By: jkorous-apple

Subscribers: jkorous-apple, klimek, ilya-biryukov, cfe-commits

Tags: #clang-tools-extra

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

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=320988=320987=320988=diff
==
--- clang-tools-extra/trunk/docs/clangd.rst (original)
+++ clang-tools-extra/trunk/docs/clangd.rst Mon Dec 18 06:59:01 2017
@@ -23,8 +23,20 @@ At the moment, `Visual Studio Code http://apt.llvm.org/>`_. :program:`Clangd` is included in the
+`clang-tools` package.
+However, it is a good idea to check your distribution's packaging system first
+as it might already be available.
+
+Otherwise, you can install :program:`Clangd` by `building Clangd`_ first.
 
 Building Clangd
 ==
@@ -41,7 +53,8 @@ Here is a list of features that could be
 not they are already implemented in :program:`Clangd` and specified in the
 Language Server Protocol. Note that for some of the features, it is not clear
 whether or not they should be part of the Language Server Protocol, so those
-features might be eventually developed outside :program:`Clangd`.
+features might be eventually developed outside :program:`Clangd` or as an
+extension to the protocol.
 
 +-++--+
 | C/C++ Editor feature|  LSP   |  Clangd  |
@@ -56,18 +69,22 @@ features might be eventually developed o
 +-++--+
 | Go to Definition| Yes|   Yes|
 +-++--+
-| Source hover| Yes|   No |
+| Signature Help  | Yes|   Yes|
 +-++--+
-| Signature Help  | Yes|   No |
+| Document Highlights | Yes|   Yes|
 +-++--+
-| Find References | Yes|   No |
+| Rename  | Yes|   Yes|
 +-++--+
-| Document Highlights | Yes|   No |
+| Source hover| Yes|   No |
 +-++--+
-| Rename  | Yes|   No |
+| Find References | Yes|   No |
 +-++--+
 | Code Lens   | Yes|   No |
 +-++--+
+| Document Symbols| Yes|   No |
++-++--+
+| Workspace Symbols   | Yes|   No |
++-++--+
 | Syntax and Semantic Coloring| No |   No |
 +-++--+
 | Code folding| No |   No |


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


[clang-tools-extra] r317585 - [clangd] Fix opening declarations located in non-preamble inclusion

2017-11-07 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Tue Nov  7 08:16:45 2017
New Revision: 317585

URL: http://llvm.org/viewvc/llvm-project?rev=317585=rev
Log:
[clangd] Fix opening declarations located in non-preamble inclusion

Summary:
When an inclusion is not processed as part of the preamble, its path is
not made into an absolute path as part of the precompiled header code
(adjustFilenameForRelocatableAST in ASTWriter.cpp). Because of this,
when we convert a Decl location to retrieve the file name with
FileEntry->getName(), it is possible for this path to be relative.
Instead, we should try to use tryGetRealPathName first which returns
an absolute path.

Fixes bug 35217.

Reviewers: sammccall, ilya-biryukov, rwols, Nebiroth

Reviewed By: sammccall

Subscribers: cfe-commits, ilya-biryukov

Tags: #clang-tools-extra

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

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

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=317585=317584=317585=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Nov  7 08:16:45 2017
@@ -965,10 +965,15 @@ private:
 End.character = SourceMgr.getSpellingColumnNumber(LocEnd) - 1;
 Range R = {Begin, End};
 Location L;
-L.uri = URI::fromFile(
-SourceMgr.getFilename(SourceMgr.getSpellingLoc(LocStart)));
-L.range = R;
-DeclarationLocations.push_back(L);
+if (const FileEntry *F =
+SourceMgr.getFileEntryForID(SourceMgr.getFileID(LocStart))) {
+  StringRef FilePath = F->tryGetRealPathName();
+  if (FilePath.empty())
+FilePath = F->getName();
+  L.uri = URI::fromFile(FilePath);
+  L.range = R;
+  DeclarationLocations.push_back(L);
+}
   }
 
   void finish() override {


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


[clang-tools-extra] r317322 - [clangd] Handle clangd.applyFix server-side

2017-11-03 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Fri Nov  3 06:39:15 2017
New Revision: 317322

URL: http://llvm.org/viewvc/llvm-project?rev=317322=rev
Log:
[clangd] Handle clangd.applyFix server-side

Summary:
When the user selects a fix-it (or any code action with commands), it is
possible to let the client forward the selected command to the server.
When the clangd.applyFix command is handled on the server, it can send a
workspace/applyEdit request to the client. This has the advantage that
the client doesn't explicitly have to know how to handle
clangd.applyFix. Therefore, the code to handle clangd.applyFix in the VS
Code extension (and any other Clangd client) is not required anymore.

Reviewers: ilya-biryukov, sammccall, Nebiroth, hokein

Reviewed By: hokein

Subscribers: ioeric, hokein, rwols, puremourning, bkramer, ilya-biryukov

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/test/clangd/execute-command.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.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/clangd/clients/clangd-vscode/src/extension.ts
clang-tools-extra/trunk/test/clangd/fixits.test
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=317322=317321=317322=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri Nov  3 06:39:15 2017
@@ -10,27 +10,25 @@
 #include "ClangdLSPServer.h"
 #include "JSONRPCDispatcher.h"
 
+#include "llvm/Support/FormatVariadic.h"
+
 using namespace clang::clangd;
 using namespace clang;
 
 namespace {
 
-std::string
+std::vector
 replacementsToEdits(StringRef Code,
 const std::vector ) {
+  std::vector Edits;
   // Turn the replacements into the format specified by the Language Server
-  // Protocol. Fuse them into one big JSON array.
-  std::string Edits;
+  // Protocol.
   for (auto  : Replacements) {
 Range ReplacementRange = {
 offsetToPosition(Code, R.getOffset()),
 offsetToPosition(Code, R.getOffset() + R.getLength())};
-TextEdit TE = {ReplacementRange, R.getReplacementText()};
-Edits += TextEdit::unparse(TE);
-Edits += ',';
+Edits.push_back({ReplacementRange, R.getReplacementText()});
   }
-  if (!Edits.empty())
-Edits.pop_back();
 
   return Edits;
 }
@@ -47,7 +45,9 @@ void ClangdLSPServer::onInitialize(Ctx C
   "codeActionProvider": true,
   "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">",":"]},
   "signatureHelpProvider": {"triggerCharacters": ["(",","]},
-  "definitionProvider": true
+  "definitionProvider": true,
+  "executeCommandProvider": {"commands": [")" +
+  ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND + R"("]}
 }})");
   if (Params.rootUri && !Params.rootUri->file.empty())
 Server.setRootPath(Params.rootUri->file);
@@ -84,6 +84,34 @@ void ClangdLSPServer::onFileEvent(Ctx C,
   Server.onFileEvent(Params);
 }
 
+void ClangdLSPServer::onCommand(Ctx C, ExecuteCommandParams ) {
+  if (Params.command == ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND &&
+  Params.workspaceEdit) {
+// The flow for "apply-fix" :
+// 1. We publish a diagnostic, including fixits
+// 2. The user clicks on the diagnostic, the editor asks us for code 
actions
+// 3. We send code actions, with the fixit embedded as context
+// 4. The user selects the fixit, the editor asks us to apply it
+// 5. We unwrap the changes and send them back to the editor
+// 6. The editor applies the changes (applyEdit), and sends us a reply (but
+// we ignore it)
+
+ApplyWorkspaceEditParams ApplyEdit;
+ApplyEdit.edit = *Params.workspaceEdit;
+C.reply("\"Fix applied.\"");
+// We don't need the response so id == 1 is OK.
+// Ideally, we would wait for the response and if there is no error, we
+// would reply success/failure to the original RPC.
+C.call("workspace/applyEdit", 
ApplyWorkspaceEditParams::unparse(ApplyEdit));
+  } else {
+// We should not get here because ExecuteCommandParams would not have
+// parsed in the first place and this handler should not be called. But if
+// more commands are added, this will be here has a safe guard.
+C.replyError(
+1, 

[clang-tools-extra] r314693 - [clangd] Handle workspace/didChangeWatchedFiles

2017-10-02 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Mon Oct  2 11:00:37 2017
New Revision: 314693

URL: http://llvm.org/viewvc/llvm-project?rev=314693=rev
Log:
[clangd] Handle workspace/didChangeWatchedFiles

Summary:
The client can send notifications when it detects watched files have
changed. This patch adds the protocol handling for this type of notification.
For now, the notification will be passed down to the ClangdServer, but it will
not be acted upon. However, this will become useful for the indexer to react
to file changes.
The events could also potentially be used to invalidate other caches
(compilation database, etc).

This change also updates the VSCode extension so that it sends the events.

Signed-off-by: Marc-Andre Laperle 

Reviewers: ilya-biryukov, Nebiroth

Subscribers: ilya-biryukov

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/test/clangd/did-change-watch-files.test
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/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/clangd/clients/clangd-vscode/package.json
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=314693=314692=314693=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Oct  2 11:00:37 2017
@@ -73,6 +73,10 @@ void ClangdLSPServer::onDocumentDidChang
  Params.contentChanges[0].text);
 }
 
+void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams ) {
+  Server.onFileEvent(Params);
+}
+
 void ClangdLSPServer::onDocumentDidClose(DidCloseTextDocumentParams Params,
  JSONOutput ) {
   Server.removeDocument(Params.textDocument.uri.file);

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=314693=314692=314693=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Mon Oct  2 11:00:37 2017
@@ -71,6 +71,7 @@ private:
 JSONOutput ) override;
   void onSwitchSourceHeader(TextDocumentIdentifier Params, StringRef ID,
 JSONOutput ) override;
+  void onFileEvent(const DidChangeWatchedFilesParams ) override;
 
   std::vector
   getFixIts(StringRef File, const clangd::Diagnostic );

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=314693=314692=314693=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Oct  2 11:00:37 2017
@@ -424,3 +424,8 @@ ClangdServer::scheduleCancelRebuild(std:
std::move(DeferredCancel));
   return DoneFuture;
 }
+
+void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams ) {
+  // FIXME: Do nothing for now. This will be used for indexing and potentially
+  // invalidating other caches.
+}

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=314693=314692=314693=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Mon Oct  2 11:00:37 2017
@@ -268,6 +268,8 @@ public:
   /// Waits until all requests to worker thread are finished and dumps AST for
   /// \p File. \p File must be in the list of added documents.
   std::string dumpAST(PathRef File);
+  /// Called when an event occurs for a watched file in the workspace.
+  void onFileEvent(const DidChangeWatchedFilesParams );
 
 private:
   std::future

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=314693=314692=314693=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Mon Oct  2 11:00:37 2017
@@ -447,6 +447,84 

[clang-tools-extra] r314377 - [clangd] LSP extension to switch between source/header file

2017-09-27 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Wed Sep 27 20:14:40 2017
New Revision: 314377

URL: http://llvm.org/viewvc/llvm-project?rev=314377=rev
Log:
[clangd] LSP extension to switch between source/header file

Summary:
Small extension to LSP to allow clients to use clangd to switch between C 
header files and source files.
Final version will use the completed clangd indexer to use the index of symbols 
to be able to switch from header to source file when the file names don't match.

Reviewers: malaperle, krasimir, bkramer, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ilya-biryukov, cfe-commits, arphaman

Patch by: William Enright

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=314377=314376=314377=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Sep 27 20:14:40 2017
@@ -72,6 +72,8 @@ public:
 JSONOutput ) override;
   void onGoToDefinition(TextDocumentPositionParams Params, StringRef ID,
 JSONOutput ) override;
+  void onSwitchSourceHeader(TextDocumentIdentifier Params, StringRef ID,
+JSONOutput ) override;  
 
 private:
   ClangdLSPServer 
@@ -226,6 +228,21 @@ void ClangdLSPServer::LSPProtocolCallbac
   R"(,"result":[)" + Locations + R"(]})");
 }
 
+void ClangdLSPServer::LSPProtocolCallbacks::onSwitchSourceHeader(
+TextDocumentIdentifier Params, StringRef ID, JSONOutput ) {
+  llvm::Optional Result =
+  LangServer.Server.switchSourceHeader(Params.uri.file);
+  std::string ResultUri;
+  if (Result)
+ResultUri = URI::unparse(URI::fromFile(*Result));
+  else
+ResultUri = "\"\"";
+
+  Out.writeMessage(
+  R"({"jsonrpc":"2.0","id":)" + ID.str() +
+  R"(,"result":)" + ResultUri + R"(})");
+}
+
 ClangdLSPServer::ClangdLSPServer(JSONOutput , unsigned AsyncThreadsCount,
  bool SnippetCompletions,
  llvm::Optional ResourceDir)

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=314377=314376=314377=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Sep 27 20:14:40 2017
@@ -296,6 +296,66 @@ Tagged ClangdServ
   return make_tagged(std::move(Result), TaggedFS.Tag);
 }
 
+llvm::Optional ClangdServer::switchSourceHeader(PathRef Path) {
+
+  StringRef SourceExtensions[] = {".cpp", ".c", ".cc", ".cxx",
+  ".c++", ".m", ".mm"};
+  StringRef HeaderExtensions[] = {".h", ".hh", ".hpp", ".hxx", ".inc"};
+
+  StringRef PathExt = llvm::sys::path::extension(Path);
+
+  // Lookup in a list of known extensions.
+  auto SourceIter =
+  std::find_if(std::begin(SourceExtensions), std::end(SourceExtensions),
+   [](PathRef SourceExt) {
+ return SourceExt.equals_lower(PathExt);
+   });
+  bool IsSource = SourceIter != std::end(SourceExtensions);
+
+  auto HeaderIter =
+  std::find_if(std::begin(HeaderExtensions), std::end(HeaderExtensions),
+   [](PathRef HeaderExt) {
+ return HeaderExt.equals_lower(PathExt);
+   });
+
+  bool IsHeader = HeaderIter != std::end(HeaderExtensions);
+
+  // We can only switch between extensions known extensions.
+  if (!IsSource && !IsHeader)
+return llvm::None;
+
+  // Array to lookup extensions for the switch. An opposite of where original
+  // extension was found.
+  ArrayRef NewExts;
+  if (IsSource)
+NewExts = HeaderExtensions;
+  else
+NewExts = SourceExtensions;
+
+  // Storage for the new path.
+  SmallString<128> NewPath = StringRef(Path);
+
+  // Instance of vfs::FileSystem, used for file existence checks.
+  auto FS = FSProvider.getTaggedFileSystem(Path).Value;
+
+  // Loop through switched extension candidates.
+  for (StringRef NewExt : NewExts) {
+llvm::sys::path::replace_extension(NewPath, NewExt);
+if (FS->exists(NewPath))
+  return NewPath.str().str(); // First str() to convert from SmallString to
+  // StringRef, second to convert from 
StringRef
+  // to std::string
+
+  

[clang-tools-extra] r314309 - [clangd] Handle InitializeParams and store rootUri

2017-09-27 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Wed Sep 27 08:31:17 2017
New Revision: 314309

URL: http://llvm.org/viewvc/llvm-project?rev=314309=rev
Log:
[clangd] Handle InitializeParams and store rootUri

Summary:
The root Uri is the workspace location and will be useful in the context of
indexing. We could also add more things to InitializeParams in order to
configure Clangd for C/C++ sepecific extensions.

Reviewers: ilya-biryukov, bkramer, krasimir, Nebiroth

Reviewed By: ilya-biryukov

Subscribers: ilya-biryukov

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.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

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=314309=314308=314309=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Sep 27 08:31:17 2017
@@ -51,7 +51,8 @@ class ClangdLSPServer::LSPProtocolCallba
 public:
   LSPProtocolCallbacks(ClangdLSPServer ) : LangServer(LangServer) {}
 
-  void onInitialize(StringRef ID, JSONOutput ) override;
+  void onInitialize(StringRef ID, InitializeParams IP,
+JSONOutput ) override;
   void onShutdown(JSONOutput ) override;
   void onDocumentDidOpen(DidOpenTextDocumentParams Params,
  JSONOutput ) override;
@@ -77,6 +78,7 @@ private:
 };
 
 void ClangdLSPServer::LSPProtocolCallbacks::onInitialize(StringRef ID,
+ InitializeParams IP,
  JSONOutput ) {
   Out.writeMessage(
   R"({"jsonrpc":"2.0","id":)" + ID +
@@ -89,6 +91,10 @@ void ClangdLSPServer::LSPProtocolCallbac
   "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">",":"]},
   "definitionProvider": true
 }}})");
+  if (IP.rootUri && !IP.rootUri->file.empty())
+LangServer.Server.setRootPath(IP.rootUri->file);
+  else if (IP.rootPath && !IP.rootPath->empty())
+LangServer.Server.setRootPath(*IP.rootPath);
 }
 
 void ClangdLSPServer::LSPProtocolCallbacks::onShutdown(JSONOutput ) {

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=314309=314308=314309=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Sep 27 08:31:17 2017
@@ -15,6 +15,7 @@
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 
@@ -154,12 +155,19 @@ ClangdServer::ClangdServer(GlobalCompila
   SnippetCompletions(SnippetCompletions), WorkScheduler(AsyncThreadsCount) 
{
 }
 
+void ClangdServer::setRootPath(PathRef RootPath) {
+  std::string NewRootPath = llvm::sys::path::convert_to_slash(
+  RootPath, llvm::sys::path::Style::posix);
+  if (llvm::sys::fs::is_directory(NewRootPath))
+this->RootPath = NewRootPath;
+}
+
 std::future ClangdServer::addDocument(PathRef File, StringRef Contents) {
   DocVersion Version = DraftMgr.updateDraft(File, Contents);
 
   auto TaggedFS = FSProvider.getTaggedFileSystem(File);
-  std::shared_ptr Resources =
-  Units.getOrCreateFile(File, ResourceDir, CDB, PCHs, TaggedFS.Value, 
Logger);
+  std::shared_ptr Resources = Units.getOrCreateFile(
+  File, ResourceDir, CDB, PCHs, TaggedFS.Value, Logger);
   return scheduleReparseAndDiags(File, VersionedDraft{Version, Contents.str()},
  std::move(Resources), std::move(TaggedFS));
 }

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=314309=314308=314309=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Sep 27 08:31:17 2017
@@ -211,6 +211,9 @@ public:
bool SnippetCompletions, clangd::Logger ,
llvm::Optional ResourceDir = llvm::None);
 
+  /// Set the root path of the workspace.
+  void setRootPath(PathRef RootPath);
+

[clang-tools-extra] r313536 - [clangd] Fix codeAction not decoded properly when sent from some clients

2017-09-18 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Mon Sep 18 08:02:59 2017
New Revision: 313536

URL: http://llvm.org/viewvc/llvm-project?rev=313536=rev
Log:
[clangd] Fix codeAction not decoded properly when sent from some clients

Summary:
Fix for bug https://bugs.llvm.org/show_bug.cgi?id=34559
Also log unknown fields instead of aborting the JSON parsing because it's
common that new optional fields are added either in new versions of the protocol
or extensions.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: ilya-biryukov

Tags: #clang-tools-extra

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

Modified:
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/test/clangd/fixits.test

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=313536=313535=313536=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Mon Sep 18 08:02:59 2017
@@ -13,13 +13,22 @@
 
//===--===//
 
 #include "Protocol.h"
+#include "JSONRPCDispatcher.h"
+
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace clang::clangd;
 
+namespace {
+void logIgnoredField(llvm::StringRef KeyValue, JSONOutput ) {
+  Output.log(llvm::formatv("Ignored unknown field \"{0}\"\n", KeyValue));
+}
+} // namespace
+
 URI URI::fromUri(llvm::StringRef uri) {
   URI Result;
   Result.uri = uri;
@@ -55,7 +64,8 @@ URI URI::parse(llvm::yaml::ScalarNode *P
 std::string URI::unparse(const URI ) { return "\"" + U.uri + "\""; }
 
 llvm::Optional
-TextDocumentIdentifier::parse(llvm::yaml::MappingNode *Params) {
+TextDocumentIdentifier::parse(llvm::yaml::MappingNode *Params,
+  JSONOutput ) {
   TextDocumentIdentifier Result;
   for (auto  : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());
@@ -74,13 +84,14 @@ TextDocumentIdentifier::parse(llvm::yaml
 } else if (KeyValue == "version") {
   // FIXME: parse version, but only for VersionedTextDocumentIdentifiers.
 } else {
-  return llvm::None;
+  logIgnoredField(KeyValue, Output);
 }
   }
   return Result;
 }
 
-llvm::Optional Position::parse(llvm::yaml::MappingNode *Params) {
+llvm::Optional Position::parse(llvm::yaml::MappingNode *Params,
+ JSONOutput ) {
   Position Result;
   for (auto  : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());
@@ -106,7 +117,7 @@ llvm::Optional Position::parse
 return llvm::None;
   Result.character = Val;
 } else {
-  return llvm::None;
+  logIgnoredField(KeyValue, Output);
 }
   }
   return Result;
@@ -119,7 +130,8 @@ std::string Position::unparse(const Posi
   return Result;
 }
 
-llvm::Optional Range::parse(llvm::yaml::MappingNode *Params) {
+llvm::Optional Range::parse(llvm::yaml::MappingNode *Params,
+   JSONOutput ) {
   Range Result;
   for (auto  : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());
@@ -135,17 +147,17 @@ llvm::Optional Range::parse(llvm:
 
 llvm::SmallString<10> Storage;
 if (KeyValue == "start") {
-  auto Parsed = Position::parse(Value);
+  auto Parsed = Position::parse(Value, Output);
   if (!Parsed)
 return llvm::None;
   Result.start = std::move(*Parsed);
 } else if (KeyValue == "end") {
-  auto Parsed = Position::parse(Value);
+  auto Parsed = Position::parse(Value, Output);
   if (!Parsed)
 return llvm::None;
   Result.end = std::move(*Parsed);
 } else {
-  return llvm::None;
+  logIgnoredField(KeyValue, Output);
 }
   }
   return Result;
@@ -168,7 +180,7 @@ std::string Location::unparse(const Loca
 }
 
 llvm::Optional
-TextDocumentItem::parse(llvm::yaml::MappingNode *Params) {
+TextDocumentItem::parse(llvm::yaml::MappingNode *Params, JSONOutput ) {
   TextDocumentItem Result;
   for (auto  : *Params) {
 auto *KeyString = dyn_cast(NextKeyValue.getKey());
@@ -195,13 +207,14 @@ TextDocumentItem::parse(llvm::yaml::Mapp
 } else if (KeyValue == "text") {
   Result.text = Value->getValue(Storage);
 } else {
-  return llvm::None;
+  logIgnoredField(KeyValue, Output);
 }
   }
   return Result;
 }
 
-llvm::Optional Metadata::parse(llvm::yaml::MappingNode *Params) {
+llvm::Optional Metadata::parse(llvm::yaml::MappingNode *Params,
+ JSONOutput ) {
   Metadata Result;
   for (auto  : *Params) {
 auto *KeyString = 

[clang-tools-extra] r307715 - [clangd] Fix Go to Definition not working in VSCode extension

2017-07-11 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Tue Jul 11 14:26:18 2017
New Revision: 307715

URL: http://llvm.org/viewvc/llvm-project?rev=307715=rev
Log:
[clangd] Fix Go to Definition not working in VSCode extension

Summary:
The URI conversion logic was returning 'undefined' when going from server to
VSCode which broke the Go to Definition functionality.

Reviewers: krasimir

Reviewed By: krasimir

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts?rev=307715=307714=307715=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts 
(original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts Tue 
Jul 11 14:26:18 2017
@@ -29,7 +29,7 @@ export function activate(context: vscode
 //the "workaround" below disables temporarily the encoding 
until decoding
 //is implemented properly in clangd
 code2Protocol: (uri: vscode.Uri) : string => uri.toString(true),
-protocol2Code: (uri: string) : vscode.Uri => undefined
+protocol2Code: (uri: string) : vscode.Uri => vscode.Uri.parse(uri)
 }
 };
 


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


[clang-tools-extra] r306558 - [clangd] Add "Go to Declaration" functionality

2017-06-28 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Wed Jun 28 09:12:10 2017
New Revision: 306558

URL: http://llvm.org/viewvc/llvm-project?rev=306558=rev
Log:
[clangd] Add "Go to Declaration" functionality

Summary: This change allows to navigate to most identifiers' declarations in 
code. This is a first step towards implementing "Go to Definition". It reuses 
clangIndex in order to detect which occurrences corresponds to the position 
requested. The occurrences' Decls are then used to generate locations suitable 
for navigating to the declarations.

Reviewers: krasimir, bkramer, ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits, mgorny

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/test/clangd/definitions.test
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.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/test/clangd/formatting.test

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=306558=306557=306558=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Wed Jun 28 09:12:10 2017
@@ -18,6 +18,7 @@ add_clang_library(clangDaemon
   clangBasic
   clangFormat
   clangFrontend
+  clangIndex
   clangSema
   clangTooling
   clangToolingCore

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=306558=306557=306558=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jun 28 09:12:10 2017
@@ -69,6 +69,8 @@ public:
 JSONOutput ) override;
   void onCompletion(TextDocumentPositionParams Params, StringRef ID,
 JSONOutput ) override;
+  void onGoToDefinition(TextDocumentPositionParams Params, StringRef ID,
+JSONOutput ) override;
 
 private:
   ClangdLSPServer 
@@ -84,7 +86,8 @@ void ClangdLSPServer::LSPProtocolCallbac
   "documentRangeFormattingProvider": true,
   "documentOnTypeFormattingProvider": 
{"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
   "codeActionProvider": true,
-  "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">"]}
+  "completionProvider": {"resolveProvider": false, 
"triggerCharacters": [".",">"]},
+  "definitionProvider": true
 }}})");
 }
 
@@ -191,6 +194,25 @@ void ClangdLSPServer::LSPProtocolCallbac
   R"(,"result":[)" + Completions + R"(]})");
 }
 
+void ClangdLSPServer::LSPProtocolCallbacks::onGoToDefinition(
+TextDocumentPositionParams Params, StringRef ID, JSONOutput ) {
+
+  auto Items = LangServer.Server.findDefinitions(
+  Params.textDocument.uri.file,
+  Position{Params.position.line, Params.position.character}).Value;
+
+  std::string Locations;
+  for (const auto  : Items) {
+Locations += Location::unparse(Item);
+Locations += ",";
+  }
+  if (!Locations.empty())
+Locations.pop_back();
+  Out.writeMessage(
+  R"({"jsonrpc":"2.0","id":)" + ID.str() +
+  R"(,"result":[)" + Locations + R"(]})");
+}
+
 ClangdLSPServer::ClangdLSPServer(JSONOutput , bool RunSynchronously)
 : Out(Out), DiagConsumer(*this),
   Server(CDB, DiagConsumer, FSProvider, RunSynchronously) {}

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=306558=306557=306558=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Jun 28 09:12:10 2017
@@ -271,3 +271,17 @@ std::string ClangdServer::dumpAST(PathRe
   });
   return DumpFuture.get();
 }
+
+Tagged
+ClangdServer::findDefinitions(PathRef File, Position Pos) {
+  auto FileContents = DraftMgr.getDraft(File);
+  assert(FileContents.Draft && "findDefinitions is called for non-added 
document");
+
+  std::vector Result;
+  auto TaggedFS = FSProvider.getTaggedFileSystem(File);
+  Units.runOnUnit(File, *FileContents.Draft, ResourceDir, CDB, PCHs,
+  TaggedFS.Value, [&](ClangdUnit ) {
+Result = 

r305588 - [index] Fix typo: inferface -> interface

2017-06-16 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Fri Jun 16 15:58:26 2017
New Revision: 305588

URL: http://llvm.org/viewvc/llvm-project?rev=305588=rev
Log:
[index] Fix typo: inferface -> interface

Reviewers: arphaman

Reviewed By: arphaman

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang-c/CXCompilationDatabase.h
cfe/trunk/include/clang-c/Index.h

Modified: cfe/trunk/include/clang-c/CXCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/CXCompilationDatabase.h?rev=305588=305587=305588=diff
==
--- cfe/trunk/include/clang-c/CXCompilationDatabase.h (original)
+++ cfe/trunk/include/clang-c/CXCompilationDatabase.h Fri Jun 16 15:58:26 2017
@@ -7,7 +7,7 @@
 |*
*|
 
|*===--===*|
 |*
*|
-|* This header provides a public inferface to use CompilationDatabase without 
*|
+|* This header provides a public interface to use CompilationDatabase without 
*|
 |* the full Clang C++ API.
*|
 |*
*|
 
\*===--===*/

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=305588=305587=305588=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Jun 16 15:58:26 2017
@@ -7,7 +7,7 @@
 |*
*|
 
|*===--===*|
 |*
*|
-|* This header provides a public inferface to a Clang library for extracting  
*|
+|* This header provides a public interface to a Clang library for extracting  
*|
 |* high-level symbol information from source files without exposing the full  
*|
 |* Clang C++ API. 
*|
 |*
*|


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


[clang-tools-extra] r302191 - [clangd] Add documentation page

2017-05-04 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Thu May  4 14:57:53 2017
New Revision: 302191

URL: http://llvm.org/viewvc/llvm-project?rev=302191=rev
Log:
[clangd] Add documentation page

Summary:
Add a simple documentation page for Clangd.
This will be useful for interested users and contributors to get basic 
information about how
to get started and the progress of Clangd.

Reviewers: krasimir, bkramer

Reviewed By: krasimir

Subscribers: Prazek, jbcoe, JDevlieghere, mgehre, JonasToth, kromanenkov, 
xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

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

Added: clang-tools-extra/trunk/docs/clangd.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clangd.rst?rev=302191=auto
==
--- clang-tools-extra/trunk/docs/clangd.rst (added)
+++ clang-tools-extra/trunk/docs/clangd.rst Thu May  4 14:57:53 2017
@@ -0,0 +1,106 @@
+
+Clangd
+
+
+.. contents::
+
+.. toctree::
+   :maxdepth: 1
+
+:program:`Clangd` is an implementation of the `Language Server Protocol
+`_ leveraging Clang.
+Clangd's goal is to provide language "smartness" features like code completion,
+find references, etc. for clients such as C/C++ Editors.
+
+Using Clangd
+==
+
+:program:`Clangd` is not meant to be used by C/C++ developers directly but
+rather from a client implementing the protocol. A client would be typically
+implemented in an IDE or an editor.
+
+At the moment, `Visual Studio Code `_ is mainly
+used in order to test :program:`Clangd` but more clients are likely to make
+use of :program:`Clangd` in the future as it matures and becomes a production
+quality tool. If you are interested in trying :program:`Clangd` in combination
+with Visual Studio Code, you can start by `building Clangd`_, then open Visual
+Studio Code in the clangd-vscode folder and launch the extension.
+
+Building Clangd
+==
+
+You can follow the instructions for `building Clang
+`_ but "extra Clang tools" is **not**
+optional.
+
+Current Status
+==
+
+Many features could be implemented in :program:`Clangd`.
+Here is a list of features that could be useful with the status of whether or
+not they are already implemented in :program:`Clangd` and specified in the
+Language Server Protocol. Note that for some of the features, it is not clear
+whether or not they should be part of the Language Server Protocol, so those
+features might be eventually developed outside :program:`Clangd`.
+
++-++--+
+| C/C++ Editor feature|  LSP   |  Clangd  |
++=++==+
+| Formatting  | Yes|   Yes|
++-++--+
+| Completion  | Yes|   Yes|
++-++--+
+| Diagnostics | Yes|   Yes|
++-++--+ 
+| Fix-its | Yes|   Yes|
++-++--+
+| Go to Definition| Yes|   No |
++-++--+
+| Source hover| Yes|   No |
++-++--+
+| Signature Help  | Yes|   No |
++-++--+
+| Find References | Yes|   No |
++-++--+
+| Document Highlights | Yes|   No |
++-++--+
+| Rename  | Yes|   No |
++-++--+
+| Code Lens   | Yes|   No |
++-++--+
+| Syntax and Semantic Coloring| No |   No |
++-++--+
+| Code folding| No |   No |
++-++--+
+| Call hierarchy  | No |   No |
++-++--+
+| Type hierarchy  | No |   No |
++-++--+
+| Organize Includes   | No |   No