[clang-tools-extra] r344614 - Remove possibility to change compile database path at runtime

2018-10-16 Thread Simon Marchi via cfe-commits
Author: simark
Date: Tue Oct 16 08:55:03 2018
New Revision: 344614

URL: http://llvm.org/viewvc/llvm-project?rev=344614=rev
Log:
Remove possibility to change compile database path at runtime

Summary:
This patch removes the possibility to change the compilation database
path at runtime using the didChangeConfiguration request.  Instead, it
is suggested to use the setting on the initialize request, and clangd
whenever the user wants to use a different build configuration.

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

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

Removed:
clang-tools-extra/trunk/test/clangd/compile-commands-path.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=344614=344613=344614=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Tue Oct 16 08:55:03 2018
@@ -81,8 +81,16 @@ CompletionItemKindBitset defaultCompleti
 } // namespace
 
 void ClangdLSPServer::onInitialize(InitializeParams ) {
-  if (Params.initializationOptions)
-applyConfiguration(*Params.initializationOptions);
+  if (Params.initializationOptions) {
+const ClangdInitializationOptions  = *Params.initializationOptions;
+
+// Explicit compilation database path.
+if (Opts.compilationDatabasePath.hasValue()) {
+  CDB.setCompileCommandsDir(Opts.compilationDatabasePath.getValue());
+}
+
+applyConfiguration(Opts.ParamsChange);
+  }
 
   if (Params.rootUri && *Params.rootUri)
 Server->setRootPath(Params.rootUri->file());
@@ -425,17 +433,10 @@ void ClangdLSPServer::onHover(TextDocume
 }
 
 void ClangdLSPServer::applyConfiguration(
-const ClangdConfigurationParamsChange ) {
-  // Compilation database change.
-  if (Settings.compilationDatabasePath.hasValue()) {
-CDB.setCompileCommandsDir(Settings.compilationDatabasePath.getValue());
-
-reparseOpenedFiles();
-  }
-
-  // Update to the compilation database.
-  if (Settings.compilationDatabaseChanges) {
-const auto  = *Settings.compilationDatabaseChanges;
+const ClangdConfigurationParamsChange ) {
+  // Per-file update to the compilation database.
+  if (Params.compilationDatabaseChanges) {
+const auto  = *Params.compilationDatabaseChanges;
 bool ShouldReparseOpenFiles = false;
 for (auto  : CompileCommandUpdates) {
   /// The opened files need to be reparsed only when some existing

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=344614=344613=344614=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Tue Oct 16 08:55:03 2018
@@ -665,10 +665,19 @@ bool fromJSON(const llvm::json::Value 
 bool fromJSON(const json::Value ,
   ClangdConfigurationParamsChange ) {
   json::ObjectMapper O(Params);
-  return O && O.map("compilationDatabasePath", CCPC.compilationDatabasePath) &&
+  return O &&
  O.map("compilationDatabaseChanges", CCPC.compilationDatabaseChanges);
 }
 
+bool fromJSON(const json::Value , ClangdInitializationOptions ) {
+  if (!fromJSON(Params, Opts.ParamsChange)) {
+return false;
+  }
+
+  json::ObjectMapper O(Params);
+  return O && O.map("compilationDatabasePath", Opts.compilationDatabasePath);
+}
+
 bool fromJSON(const json::Value , ReferenceParams ) {
   TextDocumentPositionParams  = R;
   return fromJSON(Params, Base);

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=344614=344613=344614=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Tue Oct 16 08:55:03 2018
@@ -411,8 +411,6 @@ bool fromJSON(const llvm::json::Value &,
 /// "initialize" request and for the "workspace/didChangeConfiguration"
 /// notification since the data received is described as 'any' type in LSP.
 struct ClangdConfigurationParamsChange {
-  llvm::Optional compilationDatabasePath;
-
   // The changes that happened to the compilation database.
   // The key of the map is a file name.
   llvm::Optional>
@@ -420,7 +418,14 @@ struct ClangdConfigurationParamsChange {
 };
 bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
 
-struct ClangdInitializationOptions : public 

[clang-tools-extra] r339483 - [clangd] Avoid duplicates in findDefinitions response

2018-08-10 Thread Simon Marchi via cfe-commits
Author: simark
Date: Fri Aug 10 15:27:53 2018
New Revision: 339483

URL: http://llvm.org/viewvc/llvm-project?rev=339483=rev
Log:
[clangd] Avoid duplicates in findDefinitions response

Summary:
When compile_commands.json contains some source files expressed as
relative paths, we can get duplicate responses to findDefinitions.  The
responses only differ by the URI, which are different versions of the
same file:

"result": [
{
...
"uri": 
"file:///home/emaisin/src/ls-interact/cpp-test/build/../src/first.h"
},
{
...
"uri": "file:///home/emaisin/src/ls-interact/cpp-test/src/first.h"
}
]

In getAbsoluteFilePath, we try to obtain the realpath of the FileEntry
by calling tryGetRealPathName.  However, this can fail and return an
empty string.  It may be bug a bug in clang, but in any case we should
fall back to computing it ourselves if it happens.

I changed getAbsoluteFilePath so that if tryGetRealPathName succeeds, we
return right away (a real path is always absolute).  Otherwise, we try
to build an absolute path, as we did before, but we also call
VFS->getRealPath to make sure to get the canonical path (e.g. without
any ".." in it).

Reviewers: malaperle

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

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

Modified:
clang-tools-extra/trunk/clangd/FindSymbols.cpp
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/TestFS.cpp
clang-tools-extra/trunk/unittests/clangd/TestFS.h
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=339483=339482=339483=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Fri Aug 10 15:27:53 2018
@@ -193,7 +193,7 @@ public:
 const FileEntry *F = SM.getFileEntryForID(SM.getMainFileID());
 if (!F)
   return;
-auto FilePath = getAbsoluteFilePath(F, SM);
+auto FilePath = getRealPath(F, SM);
 if (FilePath)
   MainFileUri = URIForFile(*FilePath);
   }

Modified: clang-tools-extra/trunk/clangd/SourceCode.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.cpp?rev=339483=339482=339483=diff
==
--- clang-tools-extra/trunk/clangd/SourceCode.cpp (original)
+++ clang-tools-extra/trunk/clangd/SourceCode.cpp Fri Aug 10 15:27:53 2018
@@ -185,18 +185,34 @@ std::vector replacementsToEdit
   return Edits;
 }
 
-llvm::Optional
-getAbsoluteFilePath(const FileEntry *F, const SourceManager ) {
-  SmallString<64> FilePath = F->tryGetRealPathName();
-  if (FilePath.empty())
-FilePath = F->getName();
-  if (!llvm::sys::path::is_absolute(FilePath)) {
-if (!SourceMgr.getFileManager().makeAbsolutePath(FilePath)) {
-  log("Could not turn relative path to absolute: {0}", FilePath);
+llvm::Optional getRealPath(const FileEntry *F,
+const SourceManager ) {
+  // Ideally, we get the real path from the FileEntry object.
+  SmallString<128> FilePath = F->tryGetRealPathName();
+  if (!FilePath.empty()) {
+return FilePath.str().str();
+  }
+
+  // Otherwise, we try to compute ourselves.
+  vlog("FileEntry for {0} did not contain the real path.", F->getName());
+
+  llvm::SmallString<128> Path = F->getName();
+
+  if (!llvm::sys::path::is_absolute(Path)) {
+if (!SourceMgr.getFileManager().makeAbsolutePath(Path)) {
+  log("Could not turn relative path to absolute: {0}", Path);
   return llvm::None;
 }
   }
-  return FilePath.str().str();
+
+  llvm::SmallString<128> RealPath;
+  if (SourceMgr.getFileManager().getVirtualFileSystem()->getRealPath(
+  Path, RealPath)) {
+log("Could not compute real path: {0}", Path);
+return Path.str().str();
+  }
+
+  return RealPath.str().str();
 }
 
 TextEdit toTextEdit(const FixItHint , const SourceManager ,

Modified: clang-tools-extra/trunk/clangd/SourceCode.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.h?rev=339483=339482=339483=diff
==
--- clang-tools-extra/trunk/clangd/SourceCode.h (original)
+++ clang-tools-extra/trunk/clangd/SourceCode.h Fri Aug 10 15:27:53 2018
@@ -62,13 +62,20 @@ TextEdit replacementToEdit(StringRef Cod
 std::vector replacementsToEdits(StringRef Code,
   const tooling::Replacements );
 
-/// Get the absolute file path of a given file entry.
-llvm::Optional getAbsoluteFilePath(const 

r339063 - [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-08-06 Thread Simon Marchi via cfe-commits
Author: simark
Date: Mon Aug  6 14:48:20 2018
New Revision: 339063

URL: http://llvm.org/viewvc/llvm-project?rev=339063=rev
Log:
[VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the 
requested name

Summary:
InMemoryFileSystem::status behaves differently than
RealFileSystem::status.  The Name contained in the Status returned by
RealFileSystem::status will be the path as requested by the caller,
whereas InMemoryFileSystem::status returns the normalized path.

For example, when requested the status for "../src/first.h",
RealFileSystem returns a Status with "../src/first.h" as the Name.
InMemoryFileSystem returns "/absolute/path/to/src/first.h".

The reason for this change is that I want to make a unit test in the
clangd testsuite (where we use an InMemoryFileSystem) to reproduce a
bug I get with the clangd program (where a RealFileSystem is used).
This difference in behavior "hides" the bug in the unit test version.

An indirect impact of this change is that a -Wnonportable-include-path
warning is now emitted in test PCH/case-insensitive-include.c.  This is
because the real path of the included file (with the wrong case) was not
available previously, whereas it is now.

Reviewers: malaperle, ilya-biryukov, bkramer

Reviewed By: ilya-biryukov

Subscribers: eric_niebler, malaperle, omtcyfz, hokein, bkramer, ilya-biryukov, 
ioeric, cfe-commits

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

Modified:
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/test/PCH/case-insensitive-include.c
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
cfe/trunk/unittests/Driver/ToolChainTest.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=339063=339062=339063=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Mon Aug  6 14:48:20 2018
@@ -315,9 +315,11 @@ const FileEntry *FileManager::getFile(St
   UFE.InPCH = Data.InPCH;
   UFE.File = std::move(F);
   UFE.IsValid = true;
-  if (UFE.File)
-if (auto RealPathName = UFE.File->getName())
-  UFE.RealPathName = *RealPathName;
+
+  SmallString<128> RealPathName;
+  if (!FS->getRealPath(InterndFileName, RealPathName))
+UFE.RealPathName = RealPathName.str();
+
   return 
 }
 

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=339063=339062=339063=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Mon Aug  6 14:48:20 2018
@@ -474,12 +474,28 @@ class InMemoryNode {
   Status Stat;
   InMemoryNodeKind Kind;
 
+protected:
+  /// Return Stat.  This should only be used for internal/debugging use.  When
+  /// clients wants the Status of this node, they should use
+  /// \p getStatus(StringRef).
+  const Status () const { return Stat; }
+
 public:
   InMemoryNode(Status Stat, InMemoryNodeKind Kind)
   : Stat(std::move(Stat)), Kind(Kind) {}
   virtual ~InMemoryNode() = default;
 
-  const Status () const { return Stat; }
+  /// Return the \p Status for this node. \p RequestedName should be the name
+  /// through which the caller referred to this node. It will override
+  /// \p Status::Name in the return value, to mimic the behavior of \p 
RealFile.
+  Status getStatus(StringRef RequestedName) const {
+return Status::copyWithNewName(Stat, RequestedName);
+  }
+
+  /// Get the filename of this node (the name without the directory part).
+  StringRef getFileName() const {
+return llvm::sys::path::filename(Stat.getName());
+  }
   InMemoryNodeKind getKind() const { return Kind; }
   virtual std::string toString(unsigned Indent) const = 0;
 };
@@ -504,14 +520,21 @@ public:
   }
 };
 
-/// Adapt a InMemoryFile for VFS' File interface.
+/// Adapt a InMemoryFile for VFS' File interface.  The goal is to make
+/// \p InMemoryFileAdaptor mimic as much as possible the behavior of
+/// \p RealFile.
 class InMemoryFileAdaptor : public File {
   InMemoryFile 
+  /// The name to use when returning a Status for this file.
+  std::string RequestedName;
 
 public:
-  explicit InMemoryFileAdaptor(InMemoryFile ) : Node(Node) {}
+  explicit InMemoryFileAdaptor(InMemoryFile , std::string RequestedName)
+  : Node(Node), RequestedName(std::move(RequestedName)) {}
 
-  llvm::ErrorOr status() override { return Node.getStatus(); }
+  llvm::ErrorOr status() override {
+return Node.getStatus(RequestedName);
+  }
 
   llvm::ErrorOr>
   getBuffer(const Twine , int64_t FileSize, bool RequiresNullTerminator,
@@ -711,7 +734,7 @@ lookupInMemoryNode(const InMemoryFileSys
 llvm::ErrorOr InMemoryFileSystem::status(const Twine ) {
   auto Node = lookupInMemoryNode(*this, Root.get(), 

[clang-tools-extra] r338914 - [clangd] Add test for changing build configuration

2018-08-03 Thread Simon Marchi via cfe-commits
Author: simark
Date: Fri Aug  3 12:40:19 2018
New Revision: 338914

URL: http://llvm.org/viewvc/llvm-project?rev=338914=rev
Log:
[clangd] Add test for changing build configuration

Summary:
This patch adds tests for the two ways of changing build configuration
(pointing to a particular compile_commands.json):

- Through the workspace/didChangeConfiguration notification.
- Through the initialize request.

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

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

Added:
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
clang-tools-extra/trunk/test/clangd/compile-commands-path.test

Added: 
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test?rev=338914=auto
==
--- 
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test 
(added)
+++ 
clang-tools-extra/trunk/test/clangd/compile-commands-path-in-initialize.test 
Fri Aug  3 12:40:19 2018
@@ -0,0 +1,35 @@
+# Test that we can set choose a configuration/build directly in the initialize
+# request.
+
+# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+# RUN: mkdir %t.dir/build-1
+# RUN: mkdir %t.dir/build-2
+# RUN: echo '[{"directory": "%/t.dir", "command": "c++ the-file.cpp", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-1", "command": "c++ -DMACRO=1 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-1/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-2", "command": "c++ -DMACRO=2 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-2/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test | FileCheck -strict-whitespace %t.test
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"initializationOptions":{"compilationDatabasePath":"INPUT_DIR/build-1"}}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://INPUT_DIR/the-file.cpp","languageId":"cpp","version":1,"text":"#if
 !defined(MACRO)\n#pragma message (\"MACRO is not defined\")\n#elif MACRO == 
1\n#pragma message (\"MACRO is one\")\n#elif MACRO == 2\n#pragma message 
(\"MACRO is two\")\n#else\n#pragma message (\"woops\")\n#endif\nint main() 
{}\n"}}}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "message": "MACRO is one",
+---
+{"jsonrpc":"2.0","id":0,"method":"workspace/didChangeConfiguration","params":{"settings":{"compilationDatabasePath":"INPUT_DIR/build-2"}}}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "message": "MACRO is two",
+---
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}

Added: clang-tools-extra/trunk/test/clangd/compile-commands-path.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/compile-commands-path.test?rev=338914=auto
==
--- clang-tools-extra/trunk/test/clangd/compile-commands-path.test (added)
+++ clang-tools-extra/trunk/test/clangd/compile-commands-path.test Fri Aug  3 
12:40:19 2018
@@ -0,0 +1,42 @@
+# Test that we can switch between configuration/build using the
+# workspace/didChangeConfiguration notification.
+
+# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+# RUN: mkdir %t.dir/build-1
+# RUN: mkdir %t.dir/build-2
+# RUN: echo '[{"directory": "%/t.dir", "command": "c++ the-file.cpp", "file": 
"the-file.cpp"}]' > %t.dir/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-1", "command": "c++ -DMACRO=1 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-1/compile_commands.json
+# RUN: echo '[{"directory": "%/t.dir/build-2", "command": "c++ -DMACRO=2 
the-file.cpp", "file": "../the-file.cpp"}]' > 
%t.dir/build-2/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test | FileCheck -strict-whitespace %t.test
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---

Re: [clang-tools-extra] r338518 - [clangd] Receive compilationDatabasePath in 'initialize' request

2018-08-01 Thread Simon Marchi via cfe-commits
On 2018-08-01 01:30 PM, Alex L wrote:
> Is there a particular reason why this commit didn't have a corresponding test 
> included?
> Cheers,
> Alex
Back when we made the corresponding change in "onChangeConfiguration", there 
was no
straightforward way to make a lit test for it:

https://reviews.llvm.org/D39571?id=124024#inline-359345

I am not sure, but I think the issue was that we had to hard-code the length of 
the
messages we sent.  Since we had to use temp directory names, the length was not
known in advance.  I don't think we have that limitation anymore.

We would need to create a temporary directory hierarchy, and then refer to it in
the messages we send to switch between build configurations.  Is it something 
that
sounds possible with lit?  Do you know about other tests doing something 
similar?

Thanks,

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


Re: [clang-tools-extra] r338518 - [clangd] Receive compilationDatabasePath in 'initialize' request

2018-08-01 Thread Simon Marchi via cfe-commits
On 2018-08-01 01:30 PM, Alex L wrote:
> Is there a particular reason why this commit didn't have a corresponding test 
> included?
> Cheers,
> Alex

Back when we made the corresponding change in "onChangeConfiguration", there 
was no
straightforward way to make a lit test for it:

https://reviews.llvm.org/D39571?id=124024#inline-359345

I am not sure, but I think the issue was that we had to hard-code the length of 
the
messages we sent.  Since we had to use temp directory names, the length was not
known in advance.  I don't think we have that limitation anymore.

We would need to create a temporary directory hierarchy, and then refer to it in
the messages we send to switch between build configurations.  Is it something 
that
sounds possible with lit?  Do you know about other tests doing something 
similar?

Thanks,

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


[clang-tools-extra] r338518 - [clangd] Receive compilationDatabasePath in 'initialize' request

2018-08-01 Thread Simon Marchi via cfe-commits
Author: simark
Date: Wed Aug  1 04:28:49 2018
New Revision: 338518

URL: http://llvm.org/viewvc/llvm-project?rev=338518=rev
Log:
[clangd] Receive compilationDatabasePath in 'initialize' request

Summary:
That way, as soon as the "initialize" is received by the server, it can start
parsing/indexing with a valid compilation database and not have to wait for a
an initial 'didChangeConfiguration' that might or might not happen.
Then, when the user changes configuration, a didChangeConfiguration can be sent.

Signed-off-by: Marc-Andre Laperle 

Reviewers: malaperle

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

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

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

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=338518=338517=338518=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Aug  1 04:28:49 2018
@@ -72,6 +72,9 @@ SymbolKindBitset defaultSymbolKinds() {
 } // namespace
 
 void ClangdLSPServer::onInitialize(InitializeParams ) {
+  if (Params.initializationOptions)
+applyConfiguration(*Params.initializationOptions);
+
   if (Params.rootUri && *Params.rootUri)
 Server.setRootPath(Params.rootUri->file());
   else if (Params.rootPath && !Params.rootPath->empty())
@@ -398,11 +401,8 @@ void ClangdLSPServer::onHover(TextDocume
});
 }
 
-// FIXME: This function needs to be properly tested.
-void ClangdLSPServer::onChangeConfiguration(
-DidChangeConfigurationParams ) {
-  ClangdConfigurationParamsChange  = Params.settings;
-
+void ClangdLSPServer::applyConfiguration(
+const ClangdConfigurationParamsChange ) {
   // Compilation database change.
   if (Settings.compilationDatabasePath.hasValue()) {
 NonCachedCDB.setCompileCommandsDir(
@@ -413,6 +413,12 @@ void ClangdLSPServer::onChangeConfigurat
   }
 }
 
+// FIXME: This function needs to be properly tested.
+void ClangdLSPServer::onChangeConfiguration(
+DidChangeConfigurationParams ) {
+  applyConfiguration(Params.settings);
+}
+
 ClangdLSPServer::ClangdLSPServer(JSONOutput ,
  const clangd::CodeCompleteOptions ,
  llvm::Optional CompileCommandsDir,

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=338518=338517=338518=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Wed Aug  1 04:28:49 2018
@@ -82,6 +82,7 @@ private:
   /// may be very expensive.  This method is normally called when the
   /// compilation database is changed.
   void reparseOpenedFiles();
+  void applyConfiguration(const ClangdConfigurationParamsChange );
 
   JSONOutput 
   /// Used to indicate that the 'shutdown' request was received from the

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=338518=338517=338518=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Wed Aug  1 04:28:49 2018
@@ -263,7 +263,7 @@ bool fromJSON(const json::Value ,
   O.map("rootPath", R.rootPath);
   O.map("capabilities", R.capabilities);
   O.map("trace", R.trace);
-  // initializationOptions, capabilities unused
+  O.map("initializationOptions", R.initializationOptions);
   return true;
 }
 

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=338518=338517=338518=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Wed Aug  1 04:28:49 2018
@@ -322,6 +322,16 @@ struct ClientCapabilities {
 
 bool fromJSON(const llvm::json::Value &, ClientCapabilities &);
 
+/// Clangd extension to set clangd-specific "initializationOptions" in the
+/// "initialize" request and for the "workspace/didChangeConfiguration"
+/// notification since the data received is described as 'any' type in LSP.
+struct ClangdConfigurationParamsChange {
+  llvm::Optional compilationDatabasePath;
+};
+bool fromJSON(const llvm::json::Value &, ClangdConfigurationParamsChange &);
+
+struct ClangdInitializationOptions : public 

r338057 - [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-26 Thread Simon Marchi via cfe-commits
Author: simark
Date: Thu Jul 26 11:55:02 2018
New Revision: 338057

URL: http://llvm.org/viewvc/llvm-project?rev=338057=rev
Log:
[VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the 
requested name

Summary:

InMemoryFileSystem::status behaves differently than
RealFileSystem::status.  The Name contained in the Status returned by
RealFileSystem::status will be the path as requested by the caller,
whereas InMemoryFileSystem::status returns the normalized path.

For example, when requested the status for "../src/first.h",
RealFileSystem returns a Status with "../src/first.h" as the Name.
InMemoryFileSystem returns "/absolute/path/to/src/first.h".

The reason for this change is that I want to make a unit test in the
clangd testsuite (where we use an InMemoryFileSystem) to reproduce a
bug I get with the clangd program (where a RealFileSystem is used).
This difference in behavior "hides" the bug in the unit test version.

Reviewers: malaperle, ilya-biryukov, bkramer

Subscribers: cfe-commits, ioeric, ilya-biryukov, bkramer, hokein, omtcyfz

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

Modified:
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
cfe/trunk/unittests/Driver/ToolChainTest.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=338057=338056=338057=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Thu Jul 26 11:55:02 2018
@@ -315,9 +315,11 @@ const FileEntry *FileManager::getFile(St
   UFE.InPCH = Data.InPCH;
   UFE.File = std::move(F);
   UFE.IsValid = true;
-  if (UFE.File)
-if (auto RealPathName = UFE.File->getName())
-  UFE.RealPathName = *RealPathName;
+
+  SmallString<128> RealPathName;
+  if (!FS->getRealPath(InterndFileName, RealPathName))
+UFE.RealPathName = RealPathName.str();
+
   return 
 }
 

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=338057=338056=338057=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu Jul 26 11:55:02 2018
@@ -474,12 +474,28 @@ class InMemoryNode {
   Status Stat;
   InMemoryNodeKind Kind;
 
+protected:
+  /// Return Stat.  This should only be used for internal/debugging use.  When
+  /// clients wants the Status of this node, they should use
+  /// \p getStatus(StringRef).
+  const Status () const { return Stat; }
+
 public:
   InMemoryNode(Status Stat, InMemoryNodeKind Kind)
   : Stat(std::move(Stat)), Kind(Kind) {}
   virtual ~InMemoryNode() = default;
 
-  const Status () const { return Stat; }
+  /// Return the \p Status for this node. \p RequestedName should be the name
+  /// through which the caller referred to this node. It will override
+  /// \p Status::Name in the return value, to mimic the behavior of \p 
RealFile.
+  Status getStatus(StringRef RequestedName) const {
+return Status::copyWithNewName(Stat, RequestedName);
+  }
+
+  /// Get the filename of this node (the name without the directory part).
+  StringRef getFileName() const {
+return llvm::sys::path::filename(Stat.getName());
+  }
   InMemoryNodeKind getKind() const { return Kind; }
   virtual std::string toString(unsigned Indent) const = 0;
 };
@@ -504,14 +520,21 @@ public:
   }
 };
 
-/// Adapt a InMemoryFile for VFS' File interface.
+/// Adapt a InMemoryFile for VFS' File interface.  The goal is to make
+/// \p InMemoryFileAdaptor mimic as much as possible the behavior of
+/// \p RealFile.
 class InMemoryFileAdaptor : public File {
   InMemoryFile 
+  /// The name to use when returning a Status for this file.
+  std::string RequestedName;
 
 public:
-  explicit InMemoryFileAdaptor(InMemoryFile ) : Node(Node) {}
+  explicit InMemoryFileAdaptor(InMemoryFile , std::string RequestedName)
+  : Node(Node), RequestedName(std::move(RequestedName)) {}
 
-  llvm::ErrorOr status() override { return Node.getStatus(); }
+  llvm::ErrorOr status() override {
+return Node.getStatus(RequestedName);
+  }
 
   llvm::ErrorOr>
   getBuffer(const Twine , int64_t FileSize, bool RequiresNullTerminator,
@@ -711,7 +734,7 @@ lookupInMemoryNode(const InMemoryFileSys
 llvm::ErrorOr InMemoryFileSystem::status(const Twine ) {
   auto Node = lookupInMemoryNode(*this, Root.get(), Path);
   if (Node)
-return (*Node)->getStatus();
+return (*Node)->getStatus(Path.str());
   return Node.getError();
 }
 
@@ -724,7 +747,8 @@ InMemoryFileSystem::openFileForRead(cons
   // When we have a file provide a heap-allocated wrapper for the memory buffer
   // to match the ownership semantics for File.
   if (auto *F = dyn_cast(*Node))
-

[clang-tools-extra] r337697 - [clangd] Fix category in clangd-vscode's package.json

2018-07-23 Thread Simon Marchi via cfe-commits
Author: simark
Date: Mon Jul 23 07:32:12 2018
New Revision: 337697

URL: http://llvm.org/viewvc/llvm-project?rev=337697=rev
Log:
[clangd] Fix category in clangd-vscode's package.json

Summary:
When opening package.json, vscode shows:

  Use 'Programming  Languages' instead

Replacing "Languages" with this fixes it.

Reviewers: ilya-biryukov

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

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

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=337697=337696=337697=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Mon Jul 
23 07:32:12 2018
@@ -9,7 +9,7 @@
 "vscode": "^1.18.0"
 },
 "categories": [
-"Languages",
+"Programming Languages",
 "Linters",
 "Snippets"
 ],


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


r337284 - [Tooling] Add operator== to CompileCommand

2018-07-17 Thread Simon Marchi via cfe-commits
Author: simark
Date: Tue Jul 17 07:13:05 2018
New Revision: 337284

URL: http://llvm.org/viewvc/llvm-project?rev=337284=rev
Log:
[Tooling] Add operator== to CompileCommand

Summary:
It does the obvious thing of comparing all fields.  This will be needed
for a clangd patch I have in the pipeline.

Subscribers: dblaikie, ilya-biryukov, ioeric, cfe-commits

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

Modified:
cfe/trunk/include/clang/Tooling/CompilationDatabase.h
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/include/clang/Tooling/CompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/CompilationDatabase.h?rev=337284=337283=337284=diff
==
--- cfe/trunk/include/clang/Tooling/CompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/CompilationDatabase.h Tue Jul 17 07:13:05 
2018
@@ -59,6 +59,15 @@ struct CompileCommand {
 
   /// The output file associated with the command.
   std::string Output;
+
+  friend bool operator==(const CompileCommand , const CompileCommand ) 
{
+return LHS.Directory == RHS.Directory && LHS.Filename == RHS.Filename &&
+   LHS.CommandLine == RHS.CommandLine && LHS.Output == RHS.Output;
+  }
+
+  friend bool operator!=(const CompileCommand , const CompileCommand ) 
{
+return !(LHS == RHS);
+  }
 };
 
 /// Interface for compilation databases.

Modified: cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp?rev=337284=337283=337284=diff
==
--- cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp Tue Jul 17 07:13:05 
2018
@@ -736,5 +736,33 @@ TEST_F(InterpolateTest, Case) {
   EXPECT_EQ(getCommand("foo/bar/baz/shout.C"), "clang -D 
FOO/BAR/BAZ/SHOUT.cc");
 }
 
+TEST(CompileCommandTest, EqualityOperator) {
+  CompileCommand CCRef("/foo/bar", "hello.c", {"a", "b"}, "hello.o");
+  CompileCommand CCTest = CCRef;
+
+  EXPECT_TRUE(CCRef == CCTest);
+  EXPECT_FALSE(CCRef != CCTest);
+
+  CCTest = CCRef;
+  CCTest.Directory = "/foo/baz";
+  EXPECT_FALSE(CCRef == CCTest);
+  EXPECT_TRUE(CCRef != CCTest);
+
+  CCTest = CCRef;
+  CCTest.Filename = "bonjour.c";
+  EXPECT_FALSE(CCRef == CCTest);
+  EXPECT_TRUE(CCRef != CCTest);
+
+  CCTest = CCRef;
+  CCTest.CommandLine.push_back("c");
+  EXPECT_FALSE(CCRef == CCTest);
+  EXPECT_TRUE(CCRef != CCTest);
+
+  CCTest = CCRef;
+  CCTest.Output = "bonjour.o";
+  EXPECT_FALSE(CCRef == CCTest);
+  EXPECT_TRUE(CCRef != CCTest);
+}
+
 } // end namespace tooling
 } // end namespace clang


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


r336807 - [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-11 Thread Simon Marchi via cfe-commits
Author: simark
Date: Wed Jul 11 07:08:17 2018
New Revision: 336807

URL: http://llvm.org/viewvc/llvm-project?rev=336807=rev
Log:
[VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the 
requested name

Summary:
InMemoryFileSystem::status behaves differently than
RealFileSystem::status.  The Name contained in the Status returned by
RealFileSystem::status will be the path as requested by the caller,
whereas InMemoryFileSystem::status returns the normalized path.

For example, when requested the status for "../src/first.h",
RealFileSystem returns a Status with "../src/first.h" as the Name.
InMemoryFileSystem returns "/absolute/path/to/src/first.h".

The reason for this change is that I want to make a unit test in the
clangd testsuite (where we use an InMemoryFileSystem) to reproduce a
bug I get with the clangd program (where a RealFileSystem is used).
This difference in behavior "hides" the bug in the unit test version.

In general, I guess it's good if InMemoryFileSystem works as much as
possible like RealFileSystem.

Doing so made the FileEntry::RealPathName value (assigned in
FileManager::getFile) wrong when using the InMemoryFileSystem.  That's
because it assumes that vfs::File::getName will always return the real
path.  I changed to to use FileSystem::getRealPath instead.

Subscribers: ilya-biryukov, ioeric, cfe-commits

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

Modified:
cfe/trunk/lib/Basic/FileManager.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
cfe/trunk/unittests/Driver/ToolChainTest.cpp

Modified: cfe/trunk/lib/Basic/FileManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/FileManager.cpp?rev=336807=336806=336807=diff
==
--- cfe/trunk/lib/Basic/FileManager.cpp (original)
+++ cfe/trunk/lib/Basic/FileManager.cpp Wed Jul 11 07:08:17 2018
@@ -315,9 +315,11 @@ const FileEntry *FileManager::getFile(St
   UFE.InPCH = Data.InPCH;
   UFE.File = std::move(F);
   UFE.IsValid = true;
-  if (UFE.File)
-if (auto RealPathName = UFE.File->getName())
-  UFE.RealPathName = *RealPathName;
+
+  SmallString<128> RealPathName;
+  if (!FS->getRealPath(InterndFileName, RealPathName))
+UFE.RealPathName = RealPathName.str();
+
   return 
 }
 

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=336807=336806=336807=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Wed Jul 11 07:08:17 2018
@@ -471,15 +471,33 @@ enum InMemoryNodeKind { IME_File, IME_Di
 /// The in memory file system is a tree of Nodes. Every node can either be a
 /// file or a directory.
 class InMemoryNode {
-  Status Stat;
   InMemoryNodeKind Kind;
+  Status Stat;
+
+protected:
+  /// Return Stat.  This should only be used for internal/debugging use.  When
+  /// clients wants the Status of this node, they should use
+  /// \p getStatus(StringRef).
+  const Status& getStatus() const {
+return Stat;
+  }
 
 public:
   InMemoryNode(Status Stat, InMemoryNodeKind Kind)
-  : Stat(std::move(Stat)), Kind(Kind) {}
+  : Kind(Kind), Stat(std::move(Stat)) {}
   virtual ~InMemoryNode() = default;
 
-  const Status () const { return Stat; }
+  /// Return the \p Status for this node. \p RequestedName should be the name
+  /// through which the caller referred to this node. It will override
+  /// \p Status::Name in the return value, to mimic the behavior of \p 
RealFile.
+  Status getStatus(StringRef RequestedName) const {
+return Status::copyWithNewName(Stat, RequestedName);
+  }
+
+  /// Get the filename of this node (the name without the directory part).
+  StringRef getFileName() const {
+return llvm::sys::path::filename(Stat.getName());
+  }
   InMemoryNodeKind getKind() const { return Kind; }
   virtual std::string toString(unsigned Indent) const = 0;
 };
@@ -504,14 +522,22 @@ public:
   }
 };
 
-/// Adapt a InMemoryFile for VFS' File interface.
+/// Adapt a InMemoryFile for VFS' File interface.  The goal is to make
+/// \p InMemoryFileAdaptor mimic as much as possible the behavior of
+/// \p RealFile.
 class InMemoryFileAdaptor : public File {
   InMemoryFile 
 
+  /// The name to use when returning a Status for this file.
+  std::string RequestedName;
+
 public:
-  explicit InMemoryFileAdaptor(InMemoryFile ) : Node(Node) {}
+  explicit InMemoryFileAdaptor(InMemoryFile , std::string RequestedName)
+  : Node(Node), RequestedName(std::move(RequestedName)) {}
 
-  llvm::ErrorOr status() override { return Node.getStatus(); }
+  llvm::ErrorOr status() override {
+return Node.getStatus(RequestedName);
+  }
 
   llvm::ErrorOr>
   getBuffer(const Twine , int64_t FileSize, bool RequiresNullTerminator,
@@ -711,7 +737,7 

[clang-tools-extra] r336358 - [clang-move] ClangMoveTests: Remove dots in output paths

2018-07-05 Thread Simon Marchi via cfe-commits
Author: simark
Date: Thu Jul  5 07:53:17 2018
New Revision: 336358

URL: http://llvm.org/viewvc/llvm-project?rev=336358=rev
Log:
[clang-move] ClangMoveTests: Remove dots in output paths

Summary:
Following D48903 ([VirtualFileSystem] InMemoryFileSystem::status: Return
a Status with the requested name), the paths output by clang-move in the
FileToReplacements map may contain leading "./".  For example, where we
would get "foo.h", we'll now get "./foo.h".  This breaks the tests,
because we are doing exact string lookups in the FileToFileID and
Results maps (they contain "foo.h", but we search for "./foo.h").

To mitigate this, try to normalize a little bit the paths output by
clang-move to remove that leading "./".

This patch should be safe to merge before D48903, remove_dots will just
be a no-op.

Reviewers: ilya-biryukov, hokein

Reviewed By: hokein

Subscribers: ioeric, cfe-commits

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

Modified:
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=336358=336357=336358=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Thu Jul  5 
07:53:17 2018
@@ -239,8 +239,10 @@ runClangMoveOnCode(const move::MoveDefin
   // The Key is file name, value is the new code after moving the class.
   std::map Results;
   for (const auto  : FileToReplacements) {
-StringRef FilePath = It.first;
-Results[FilePath] = Context.getRewrittenText(FileToFileID[FilePath]);
+// The path may come out as "./foo.h", normalize to "foo.h".
+SmallString<32> FilePath (It.first);
+llvm::sys::path::remove_dots(FilePath);
+Results[FilePath.str().str()] = 
Context.getRewrittenText(FileToFileID[FilePath]);
   }
   return Results;
 }


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


Re: [clang-tools-extra] r328500 - [clangd] Support incremental document syncing

2018-03-28 Thread Simon Marchi via cfe-commits
On 2018-03-27 01:47 PM, Reid Kleckner wrote:
> One of these new tests does not pass on Windows due to assumptions about 
> absolute path structure. The FileCheck output seems self-explanatory:
> 
> $ "FileCheck" "-strict-whitespace" 
> "C:\b\slave\clang-x86-windows-msvc2015\clang-x86-windows-msvc2015\llvm\tools\clang\tools\extra\test\clangd\textdocument-didchange-fail.test"
> # command stderr:
> C:\b\slave\clang-x86-windows-msvc2015\clang-x86-windows-msvc2015\llvm\tools\clang\tools\extra\test\clangd\textdocument-didchange-fail.test:22:20:
>  error: expected string not found in input
> # CHECK-NEXT:      "uri": "file:///clangd-test/main.cpp"
>                    ^
> :68:7: note: scanning from here
>       "uri": "file:///C%3a/clangd-test/main.cpp"
> 
> I committed a speculative fix for this in r328645, hopefully it does the job.

Makes sense.  Thanks for catching and fixing it!  I received some failure
notifications, but at first sight they seemed unrelated (maybe some of them
were).  I'll look more closely next time.

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


[clang-tools-extra] r328500 - [clangd] Support incremental document syncing

2018-03-26 Thread Simon Marchi via cfe-commits
Author: simark
Date: Mon Mar 26 07:41:40 2018
New Revision: 328500

URL: http://llvm.org/viewvc/llvm-project?rev=328500=rev
Log:
[clangd] Support incremental document syncing

Summary:
This patch adds support for incremental document syncing, as described
in the LSP spec.  The protocol specifies ranges in terms of Position (a
line and a character), and our drafts are stored as plain strings.  So I
see two things that may not be super efficient for very large files:

- Converting a Position to an offset (the positionToOffset function)
  requires searching for end of lines until we reach the desired line.
- When we update a range, we construct a new string, which implies
  copying the whole document.

However, for the typical size of a C++ document and the frequency of
update (at which a user types), it may not be an issue.  This patch aims
at getting the basic feature in, and we can always improve it later if
we find it's too slow.

Signed-off-by: Simon Marchi 

Reviewers: malaperle, ilya-biryukov

Reviewed By: ilya-biryukov

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

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

Added:
clang-tools-extra/trunk/test/clangd/textdocument-didchange-fail.test
clang-tools-extra/trunk/unittests/clangd/DraftStoreTests.cpp
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.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/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=328500=328499=328500=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Mar 26 07:41:40 2018
@@ -100,7 +100,7 @@ void ClangdLSPServer::onInitialize(Initi
   reply(json::obj{
   {{"capabilities",
 json::obj{
-{"textDocumentSync", 1},
+{"textDocumentSync", (int)TextDocumentSyncKind::Incremental},
 {"documentFormattingProvider", true},
 {"documentRangeFormattingProvider", true},
 {"documentOnTypeFormattingProvider",
@@ -147,25 +147,30 @@ void ClangdLSPServer::onDocumentDidOpen(
   PathRef File = Params.textDocument.uri.file();
   std::string  = Params.textDocument.text;
 
-  DraftMgr.updateDraft(File, Contents);
+  DraftMgr.addDraft(File, Contents);
   Server.addDocument(File, Contents, WantDiagnostics::Yes);
 }
 
 void ClangdLSPServer::onDocumentDidChange(DidChangeTextDocumentParams ) 
{
-  if (Params.contentChanges.size() != 1)
-return replyError(ErrorCode::InvalidParams,
-  "can only apply one change at a time");
   auto WantDiags = WantDiagnostics::Auto;
   if (Params.wantDiagnostics.hasValue())
 WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes
   : WantDiagnostics::No;
 
   PathRef File = Params.textDocument.uri.file();
-  std::string  = Params.contentChanges[0].text;
+  llvm::Expected Contents =
+  DraftMgr.updateDraft(File, Params.contentChanges);
+  if (!Contents) {
+// If this fails, we are most likely going to be not in sync anymore with
+// the client.  It is better to remove the draft and let further operations
+// fail rather than giving wrong results.
+DraftMgr.removeDraft(File);
+Server.removeDocument(File);
+log(llvm::toString(Contents.takeError()));
+return;
+  }
 
-  // We only support full syncing right now.
-  DraftMgr.updateDraft(File, Contents);
-  Server.addDocument(File, Contents, WantDiags);
+  Server.addDocument(File, *Contents, WantDiags);
 }
 
 void ClangdLSPServer::onFileEvent(DidChangeWatchedFilesParams ) {

Modified: clang-tools-extra/trunk/clangd/DraftStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DraftStore.cpp?rev=328500=328499=328500=diff
==
--- clang-tools-extra/trunk/clangd/DraftStore.cpp (original)
+++ clang-tools-extra/trunk/clangd/DraftStore.cpp Mon Mar 26 07:41:40 2018
@@ -8,6 +8,8 @@
 
//===--===//
 
 #include "DraftStore.h"
+#include "SourceCode.h"
+#include "llvm/Support/Errc.h"
 
 using namespace clang;
 using namespace clang::clangd;
@@ -32,12 +34,72 @@ std::vector DraftStore::getActiveF
   return ResultVector;
 }
 
-void DraftStore::updateDraft(PathRef File, StringRef Contents) {
+void 

[clang-tools-extra] r328100 - Make positionToOffset return llvm::Expected

2018-03-21 Thread Simon Marchi via cfe-commits
Author: simark
Date: Wed Mar 21 07:36:46 2018
New Revision: 328100

URL: http://llvm.org/viewvc/llvm-project?rev=328100=rev
Log:
Make positionToOffset return llvm::Expected

Summary:

To implement incremental document syncing, we want to verify that the
ranges provided by the front-end are valid.  Currently, positionToOffset
deals with invalid Positions by returning 0 or Code.size(), which are
two valid offsets.  Instead, return an llvm:Expected with an
error if the position is invalid.

According to the LSP, if the character value exceeds the number of
characters of the given line, it should default back to the end of the
line.  It makes sense in some contexts to have this behavior, and does
not in other contexts.  The AllowColumnsBeyondLineLength parameter
allows to decide what to do in that case, default back to the end of the
line, or return an error.

Reviewers: ilya-biryukov

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

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/unittests/clangd/Annotations.cpp
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/SourceCodeTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=328100=328099=328100=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Mar 21 07:36:46 2018
@@ -190,9 +190,13 @@ void ClangdServer::signatureHelp(PathRef
 
 llvm::Expected
 ClangdServer::formatRange(StringRef Code, PathRef File, Range Rng) {
-  size_t Begin = positionToOffset(Code, Rng.start);
-  size_t Len = positionToOffset(Code, Rng.end) - Begin;
-  return formatCode(Code, File, {tooling::Range(Begin, Len)});
+  llvm::Expected Begin = positionToOffset(Code, Rng.start);
+  if (!Begin)
+return Begin.takeError();
+  llvm::Expected End = positionToOffset(Code, Rng.end);
+  if (!End)
+return End.takeError();
+  return formatCode(Code, File, {tooling::Range(*Begin, *End - *Begin)});
 }
 
 llvm::Expected ClangdServer::formatFile(StringRef Code,
@@ -205,11 +209,13 @@ llvm::Expected
 ClangdServer::formatOnType(StringRef Code, PathRef File, Position Pos) {
   // Look for the previous opening brace from the character position and
   // format starting from there.
-  size_t CursorPos = positionToOffset(Code, Pos);
-  size_t PreviousLBracePos = StringRef(Code).find_last_of('{', CursorPos);
+  llvm::Expected CursorPos = positionToOffset(Code, Pos);
+  if (!CursorPos)
+return CursorPos.takeError();
+  size_t PreviousLBracePos = StringRef(Code).find_last_of('{', *CursorPos);
   if (PreviousLBracePos == StringRef::npos)
-PreviousLBracePos = CursorPos;
-  size_t Len = CursorPos - PreviousLBracePos;
+PreviousLBracePos = *CursorPos;
+  size_t Len = *CursorPos - PreviousLBracePos;
 
   return formatCode(Code, File, {tooling::Range(PreviousLBracePos, Len)});
 }

Modified: clang-tools-extra/trunk/clangd/SourceCode.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SourceCode.cpp?rev=328100=328099=328100=diff
==
--- clang-tools-extra/trunk/clangd/SourceCode.cpp (original)
+++ clang-tools-extra/trunk/clangd/SourceCode.cpp Wed Mar 21 07:36:46 2018
@@ -9,23 +9,43 @@
 #include "SourceCode.h"
 
 #include "clang/Basic/SourceManager.h"
+#include "llvm/Support/Errc.h"
+#include "llvm/Support/Error.h"
 
 namespace clang {
 namespace clangd {
 using namespace llvm;
 
-size_t positionToOffset(StringRef Code, Position P) {
+llvm::Expected positionToOffset(StringRef Code, Position P,
+bool AllowColumnsBeyondLineLength) {
   if (P.line < 0)
-return 0;
+return llvm::make_error(
+llvm::formatv("Line value can't be negative ({0})", P.line),
+llvm::errc::invalid_argument);
+  if (P.character < 0)
+return llvm::make_error(
+llvm::formatv("Character value can't be negative ({0})", P.character),
+llvm::errc::invalid_argument);
   size_t StartOfLine = 0;
   for (int I = 0; I != P.line; ++I) {
 size_t NextNL = Code.find('\n', StartOfLine);
 if (NextNL == StringRef::npos)
-  return Code.size();
+  return llvm::make_error(
+  llvm::formatv("Line value is out of range ({0})", P.line),
+  llvm::errc::invalid_argument);
 StartOfLine = NextNL + 1;
   }
+
+  size_t NextNL = Code.find('\n', StartOfLine);
+  if (NextNL == StringRef::npos)
+NextNL = Code.size();
+
+  if (StartOfLine + P.character > NextNL && !AllowColumnsBeyondLineLength)
+return llvm::make_error(
+  

[clang-tools-extra] r327711 - Move DraftMgr from ClangdServer to ClangdLSPServer

2018-03-16 Thread Simon Marchi via cfe-commits
Author: simark
Date: Fri Mar 16 07:30:42 2018
New Revision: 327711

URL: http://llvm.org/viewvc/llvm-project?rev=327711=rev
Log:
Move DraftMgr from ClangdServer to ClangdLSPServer

Summary:
This patch moves the draft manager closer to the edge of Clangd, from
ClangdServer to ClangdLSPServer.  This will make it easier to implement
incremental document sync, by making ClangdServer only deal with
complete documents.

As a result, DraftStore doesn't have to deal with versioning, and thus
its API can be simplified.  It is replaced by a StringMap in
ClangdServer holding a current version number for each file.

Signed-off-by: Simon Marchi 

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

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

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/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.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=327711=327710=327711=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Fri Mar 16 07:30:42 2018
@@ -12,6 +12,7 @@
 #include "JSONRPCDispatcher.h"
 #include "SourceCode.h"
 #include "URI.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
@@ -142,8 +143,12 @@ void ClangdLSPServer::onDocumentDidOpen(
   if (Params.metadata && !Params.metadata->extraFlags.empty())
 CDB.setExtraFlagsForFile(Params.textDocument.uri.file(),
  std::move(Params.metadata->extraFlags));
-  Server.addDocument(Params.textDocument.uri.file(), Params.textDocument.text,
- WantDiagnostics::Yes);
+
+  PathRef File = Params.textDocument.uri.file();
+  std::string  = Params.textDocument.text;
+
+  DraftMgr.updateDraft(File, Contents);
+  Server.addDocument(File, Contents, WantDiagnostics::Yes);
 }
 
 void ClangdLSPServer::onDocumentDidChange(DidChangeTextDocumentParams ) 
{
@@ -154,9 +159,13 @@ void ClangdLSPServer::onDocumentDidChang
   if (Params.wantDiagnostics.hasValue())
 WantDiags = Params.wantDiagnostics.getValue() ? WantDiagnostics::Yes
   : WantDiagnostics::No;
+
+  PathRef File = Params.textDocument.uri.file();
+  std::string  = Params.contentChanges[0].text;
+
   // We only support full syncing right now.
-  Server.addDocument(Params.textDocument.uri.file(),
- Params.contentChanges[0].text, WantDiags);
+  DraftMgr.updateDraft(File, Contents);
+  Server.addDocument(File, Contents, WantDiags);
 }
 
 void ClangdLSPServer::onFileEvent(DidChangeWatchedFilesParams ) {
@@ -188,7 +197,7 @@ void ClangdLSPServer::onCommand(ExecuteC
   } else if (Params.command ==
  ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE) {
 auto  = Params.includeInsertion->textDocument.uri;
-auto Code = Server.getDocument(FileURI.file());
+auto Code = DraftMgr.getDraft(FileURI.file());
 if (!Code)
   return replyError(ErrorCode::InvalidParams,
 ("command " +
@@ -233,7 +242,7 @@ void ClangdLSPServer::onCommand(ExecuteC
 
 void ClangdLSPServer::onRename(RenameParams ) {
   Path File = Params.textDocument.uri.file();
-  llvm::Optional Code = Server.getDocument(File);
+  llvm::Optional Code = DraftMgr.getDraft(File);
   if (!Code)
 return replyError(ErrorCode::InvalidParams,
   "onRename called for non-added file");
@@ -254,13 +263,15 @@ void ClangdLSPServer::onRename(RenamePar
 }
 
 void ClangdLSPServer::onDocumentDidClose(DidCloseTextDocumentParams ) {
-  Server.removeDocument(Params.textDocument.uri.file());
+  PathRef File = Params.textDocument.uri.file();
+  DraftMgr.removeDraft(File);
+  Server.removeDocument(File);
 }
 
 void ClangdLSPServer::onDocumentOnTypeFormatting(
 DocumentOnTypeFormattingParams ) {
   auto File = Params.textDocument.uri.file();
-  auto Code = Server.getDocument(File);
+  auto Code = DraftMgr.getDraft(File);
   if (!Code)
 return replyError(ErrorCode::InvalidParams,
   "onDocumentOnTypeFormatting called for non-added file");
@@ -276,7 +287,7 @@ void ClangdLSPServer::onDocumentOnTypeFo
 void ClangdLSPServer::onDocumentRangeFormatting(
 DocumentRangeFormattingParams ) {
   auto File = Params.textDocument.uri.file();
-  auto Code = Server.getDocument(File);
+  auto Code = DraftMgr.getDraft(File);
   if (!Code)
 return replyError(ErrorCode::InvalidParams,
   

[clang-tools-extra] r327550 - [clangd] Use Contents from inputs in codeComplete and signatureHelp

2018-03-14 Thread Simon Marchi via cfe-commits
Author: simark
Date: Wed Mar 14 11:31:48 2018
New Revision: 327550

URL: http://llvm.org/viewvc/llvm-project?rev=327550=rev
Log:
[clangd] Use Contents from inputs in codeComplete and signatureHelp

Summary:
ClangdServer::{codeComplete,signatureHelp} both use the Contents from
the draft manager.  Since we want to move the draft manager from
ClangdServer to ClangdLSPServer, this patch changes those methods to
find the file contents from InputsAndPreamble, which contains the source
passed in previously.

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

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

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=327550=327549=327550=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Mar 14 11:31:48 2018
@@ -154,9 +154,9 @@ void ClangdServer::codeComplete(PathRef
   // Copy PCHs to avoid accessing this->PCHs concurrently
   std::shared_ptr PCHs = this->PCHs;
   auto FS = FSProvider.getFileSystem();
-  auto Task = [PCHs, Pos, FS, CodeCompleteOpts](
-  std::string Contents, Path File, Callback CB,
-  llvm::Expected IP) {
+  auto Task = [PCHs, Pos, FS,
+   CodeCompleteOpts](Path File, Callback CB,
+ llvm::Expected IP) {
 assert(IP && "error when trying to read preamble for codeComplete");
 auto PreambleData = IP->Preamble;
 
@@ -164,13 +164,12 @@ void ClangdServer::codeComplete(PathRef
 // both the old and the new version in case only one of them matches.
 CompletionList Result = clangd::codeComplete(
 File, IP->Command, PreambleData ? >Preamble : nullptr,
-Contents, Pos, FS, PCHs, CodeCompleteOpts);
+IP->Contents, Pos, FS, PCHs, CodeCompleteOpts);
 CB(std::move(Result));
   };
 
-  WorkScheduler.runWithPreamble(
-  "CodeComplete", File,
-  Bind(Task, std::move(*Latest.Draft), File.str(), std::move(CB)));
+  WorkScheduler.runWithPreamble("CodeComplete", File,
+Bind(Task, File.str(), std::move(CB)));
 }
 
 void ClangdServer::signatureHelp(PathRef File, Position Pos,
@@ -183,8 +182,7 @@ void ClangdServer::signatureHelp(PathRef
 
   auto PCHs = this->PCHs;
   auto FS = FSProvider.getFileSystem();
-  auto Action = [Pos, FS, PCHs](std::string Contents, Path File,
-Callback CB,
+  auto Action = [Pos, FS, PCHs](Path File, Callback CB,
 llvm::Expected IP) {
 if (!IP)
   return CB(IP.takeError());
@@ -192,12 +190,11 @@ void ClangdServer::signatureHelp(PathRef
 auto PreambleData = IP->Preamble;
 CB(clangd::signatureHelp(File, IP->Command,
  PreambleData ? >Preamble : nullptr,
- Contents, Pos, FS, PCHs));
+ IP->Contents, Pos, FS, PCHs));
   };
 
-  WorkScheduler.runWithPreamble(
-  "SignatureHelp", File,
-  Bind(Action, std::move(*Latest.Draft), File.str(), std::move(CB)));
+  WorkScheduler.runWithPreamble("SignatureHelp", File,
+Bind(Action, File.str(), std::move(CB)));
 }
 
 llvm::Expected


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


[clang-tools-extra] r325784 - [clangd] DidChangeConfiguration Notification

2018-02-22 Thread Simon Marchi via cfe-commits
Author: simark
Date: Thu Feb 22 06:00:39 2018
New Revision: 325784

URL: http://llvm.org/viewvc/llvm-project?rev=325784=rev
Log:
[clangd] DidChangeConfiguration Notification

Summary:

Implementation of DidChangeConfiguration notification handling in
clangd.  This currently only supports changing one setting: the path of
the compilation database to be used for the current project.   In other
words, it is no longer necessary to restart clangd with a different
command line argument in order to change the compilation database.

Reviewers: malaperle, krasimir, bkramer, ilya-biryukov

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

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

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

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/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/unittests/clangd/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=325784=325783=325784=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Feb 22 06:00:39 2018
@@ -370,6 +370,18 @@ void ClangdLSPServer::onHover(TextDocume
});
 }
 
+// FIXME: This function needs to be properly tested.
+void ClangdLSPServer::onChangeConfiguration(
+DidChangeConfigurationParams ) {
+  ClangdConfigurationParamsChange  = Params.settings;
+
+  // Compilation database change.
+  if (Settings.compilationDatabasePath.hasValue()) {
+CDB.setCompileCommandsDir(Settings.compilationDatabasePath.getValue());
+Server.reparseOpenedFiles();
+  }
+}
+
 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=325784=325783=325784=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Thu Feb 22 06:00:39 2018
@@ -76,6 +76,7 @@ private:
   void onCommand(ExecuteCommandParams ) override;
   void onRename(RenameParams ) override;
   void onHover(TextDocumentPositionParams ) override;
+  void onChangeConfiguration(DidChangeConfigurationParams ) 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=325784=325783=325784=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Feb 22 06:00:39 2018
@@ -554,6 +554,11 @@ void ClangdServer::scheduleReparseAndDia
WantDiags, std::move(Callback));
 }
 
+void ClangdServer::reparseOpenedFiles() {
+  for (const Path  : DraftMgr.getActiveFiles())
+forceReparse(FilePath);
+}
+
 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=325784=325783=325784=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Thu Feb 22 06:00:39 2018
@@ -163,6 +163,11 @@ public:
   /// and AST and rebuild them from scratch.
   void forceReparse(PathRef File);
 
+  /// Calls forceReparse() on all currently opened files.
+  /// As a result, this method may be very expensive.
+  /// This method is normally called when the compilation database is changed.
+  void reparseOpenedFiles();
+
   /// Run code completion for \p 

[clang-tools-extra] r325596 - [clangd] Fix formatting in XRefs.cpp

2018-02-20 Thread Simon Marchi via cfe-commits
Author: simark
Date: Tue Feb 20 08:57:47 2018
New Revision: 325596

URL: http://llvm.org/viewvc/llvm-project?rev=325596=rev
Log:
[clangd] Fix formatting in XRefs.cpp

This is also to test my commit access.


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

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=325596=325595=325596=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Tue Feb 20 08:57:47 2018
@@ -21,7 +21,7 @@ namespace {
 // Get the definition from a given declaration `D`.
 // Return nullptr if no definition is found, or the declaration type of `D` is
 // not supported.
-const Decl* GetDefinition(const Decl* D) {
+const Decl *GetDefinition(const Decl *D) {
   assert(D);
   if (const auto *TD = dyn_cast(D))
 return TD->getDefinition();
@@ -85,7 +85,7 @@ public:
   // We don't use parameter `D`, as Parameter `D` is the canonical
   // declaration, which is the first declaration of a redeclarable
   // declaration, and it could be a forward declaration.
-  if (const auto* Def = GetDefinition(D)) {
+  if (const auto *Def = GetDefinition(D)) {
 Decls.push_back(Def);
   } else {
 // Couldn't find a definition, fall back to use `D`.


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