[PATCH] D133299: [clangd] Fix LineFoldingOnly flag is not propagated correctly to ClangdServer.

2022-09-05 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG16987998e6a0: [clangd] Fix LineFoldingOnly flag is not 
propagated correctly to ClangdServer. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133299/new/

https://reviews.llvm.org/D133299

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/test/folding-range.test


Index: clang-tools-extra/clangd/test/folding-range.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/folding-range.test
@@ -0,0 +1,24 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+void f() {
+
+}
+---
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":
 {"foldingRange": {"lineFoldingOnly": true}}},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"void
 f() {\n\n}\n","uri":"test:///foo.cpp","version":1}}}
+---
+{"id":1,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"test:///foo.cpp"}}}
+# CHECK:  "id": 1,
+# CHECK-NEXT: "jsonrpc": "2.0",
+# CHECK-NEXT: "result": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "endLine": 1,
+# CHECK-NEXT: "kind": "region", 
+# CHECK-NEXT: "startCharacter": 10,
+# CHECK-NEXT: "startLine": 0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+---
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -466,32 +466,6 @@
   if (Server)
 return Reply(llvm::make_error("server already initialized",
 ErrorCode::InvalidRequest));
-  if (Opts.UseDirBasedCDB) {
-DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
-if (const auto  = Params.initializationOptions.compilationDatabasePath)
-  CDBOpts.CompileCommandsDir = Dir;
-CDBOpts.ContextProvider = Opts.ContextProvider;
-BaseCDB =
-std::make_unique(CDBOpts);
-BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
- std::move(BaseCDB));
-  }
-  auto Mangler = CommandMangler::detect();
-  if (Opts.ResourceDir)
-Mangler.ResourceDir = *Opts.ResourceDir;
-  CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
-  tooling::ArgumentsAdjuster(std::move(Mangler)));
-  {
-// Switch caller's context with LSPServer's background context. Since we
-// rather want to propagate information from LSPServer's context into the
-// Server, CDB, etc.
-WithContext MainContext(BackgroundContext.clone());
-llvm::Optional WithOffsetEncoding;
-if (Opts.Encoding)
-  WithOffsetEncoding.emplace(kCurrentOffsetEncoding, *Opts.Encoding);
-Server.emplace(*CDB, TFS, Opts,
-   static_cast(this));
-  }
 
   Opts.CodeComplete.EnableSnippets = Params.capabilities.CompletionSnippets;
   Opts.CodeComplete.IncludeFixIts = Params.capabilities.CompletionFixes;
@@ -521,6 +495,33 @@
   BackgroundIndexSkipCreate = Params.capabilities.ImplicitProgressCreation;
   Opts.ImplicitCancellation = !Params.capabilities.CancelsStaleRequests;
 
+  if (Opts.UseDirBasedCDB) {
+DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
+if (const auto  = Params.initializationOptions.compilationDatabasePath)
+  CDBOpts.CompileCommandsDir = Dir;
+CDBOpts.ContextProvider = Opts.ContextProvider;
+BaseCDB =
+std::make_unique(CDBOpts);
+BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
+ std::move(BaseCDB));
+  }
+  auto Mangler = CommandMangler::detect();
+  if (Opts.ResourceDir)
+Mangler.ResourceDir = *Opts.ResourceDir;
+  CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
+  tooling::ArgumentsAdjuster(std::move(Mangler)));
+  {
+// Switch caller's context with LSPServer's background context. Since we
+// rather want to propagate information from LSPServer's context into the
+// Server, CDB, etc.
+WithContext MainContext(BackgroundContext.clone());
+llvm::Optional WithOffsetEncoding;
+if (Opts.Encoding)
+  WithOffsetEncoding.emplace(kCurrentOffsetEncoding, *Opts.Encoding);
+Server.emplace(*CDB, TFS, Opts,
+   static_cast(this));
+  }
+
   llvm::json::Object ServerCaps{
   {"textDocumentSync",
llvm::json::Object{


Index: clang-tools-extra/clangd/test/folding-range.test
===
--- /dev/null
+++ 

[PATCH] D133299: [clangd] Fix LineFoldingOnly flag is not propagated correctly to ClangdServer.

2022-09-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 457972.
hokein marked an inline comment as done.
hokein added a comment.

address comment: create the ClangdServer when Opts is fully initialized.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133299/new/

https://reviews.llvm.org/D133299

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/test/folding-range.test


Index: clang-tools-extra/clangd/test/folding-range.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/folding-range.test
@@ -0,0 +1,24 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+void f() {
+
+}
+---
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":
 {"foldingRange": {"lineFoldingOnly": true}}},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"void
 f() {\n\n}\n","uri":"test:///foo.cpp","version":1}}}
+---
+{"id":1,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"test:///foo.cpp"}}}
+# CHECK:  "id": 1,
+# CHECK-NEXT: "jsonrpc": "2.0",
+# CHECK-NEXT: "result": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "endLine": 1,
+# CHECK-NEXT: "kind": "region", 
+# CHECK-NEXT: "startCharacter": 10,
+# CHECK-NEXT: "startLine": 0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+---
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -466,32 +466,6 @@
   if (Server)
 return Reply(llvm::make_error("server already initialized",
 ErrorCode::InvalidRequest));
-  if (Opts.UseDirBasedCDB) {
-DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
-if (const auto  = Params.initializationOptions.compilationDatabasePath)
-  CDBOpts.CompileCommandsDir = Dir;
-CDBOpts.ContextProvider = Opts.ContextProvider;
-BaseCDB =
-std::make_unique(CDBOpts);
-BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
- std::move(BaseCDB));
-  }
-  auto Mangler = CommandMangler::detect();
-  if (Opts.ResourceDir)
-Mangler.ResourceDir = *Opts.ResourceDir;
-  CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
-  tooling::ArgumentsAdjuster(std::move(Mangler)));
-  {
-// Switch caller's context with LSPServer's background context. Since we
-// rather want to propagate information from LSPServer's context into the
-// Server, CDB, etc.
-WithContext MainContext(BackgroundContext.clone());
-llvm::Optional WithOffsetEncoding;
-if (Opts.Encoding)
-  WithOffsetEncoding.emplace(kCurrentOffsetEncoding, *Opts.Encoding);
-Server.emplace(*CDB, TFS, Opts,
-   static_cast(this));
-  }
 
   Opts.CodeComplete.EnableSnippets = Params.capabilities.CompletionSnippets;
   Opts.CodeComplete.IncludeFixIts = Params.capabilities.CompletionFixes;
@@ -521,6 +495,33 @@
   BackgroundIndexSkipCreate = Params.capabilities.ImplicitProgressCreation;
   Opts.ImplicitCancellation = !Params.capabilities.CancelsStaleRequests;
 
+  if (Opts.UseDirBasedCDB) {
+DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
+if (const auto  = Params.initializationOptions.compilationDatabasePath)
+  CDBOpts.CompileCommandsDir = Dir;
+CDBOpts.ContextProvider = Opts.ContextProvider;
+BaseCDB =
+std::make_unique(CDBOpts);
+BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
+ std::move(BaseCDB));
+  }
+  auto Mangler = CommandMangler::detect();
+  if (Opts.ResourceDir)
+Mangler.ResourceDir = *Opts.ResourceDir;
+  CDB.emplace(BaseCDB.get(), Params.initializationOptions.fallbackFlags,
+  tooling::ArgumentsAdjuster(std::move(Mangler)));
+  {
+// Switch caller's context with LSPServer's background context. Since we
+// rather want to propagate information from LSPServer's context into the
+// Server, CDB, etc.
+WithContext MainContext(BackgroundContext.clone());
+llvm::Optional WithOffsetEncoding;
+if (Opts.Encoding)
+  WithOffsetEncoding.emplace(kCurrentOffsetEncoding, *Opts.Encoding);
+Server.emplace(*CDB, TFS, Opts,
+   static_cast(this));
+  }
+
   llvm::json::Object ServerCaps{
   {"textDocumentSync",
llvm::json::Object{


Index: clang-tools-extra/clangd/test/folding-range.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/folding-range.test
@@ -0,0 +1,24 @@
+# RUN: clangd -lit-test < %s 

[PATCH] D133299: [clangd] Fix LineFoldingOnly flag is not propagated correctly to ClangdServer.

2022-09-05 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 accepted this revision.
usaxena95 added a comment.
This revision is now accepted and ready to land.

Thanks. Sorry I missed this.




Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:487-497
   {
 // Switch caller's context with LSPServer's background context. Since we
 // rather want to propagate information from LSPServer's context into the
 // Server, CDB, etc.
 WithContext MainContext(BackgroundContext.clone());
 llvm::Optional WithOffsetEncoding;
 if (Opts.Encoding)

I think we should do this after the Opts has been fully set to avoid the 
confusion


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133299/new/

https://reviews.llvm.org/D133299

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


[PATCH] D133299: [clangd] Fix LineFoldingOnly flag is not propagated correctly to ClangdServer.

2022-09-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: usaxena95, kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

The Opts.LineFoldingOnly must be set before the clangdServer
construction, otherwise this flag is always false when using clangd in VSCode.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133299

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/test/folding-range.test


Index: clang-tools-extra/clangd/test/folding-range.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/folding-range.test
@@ -0,0 +1,24 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+void f() {
+
+}
+---
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":
 {"foldingRange": {"lineFoldingOnly": true}}},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"void
 f() {\n\n}\n","uri":"test:///foo.cpp","version":1}}}
+---
+{"id":1,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"test:///foo.cpp"}}}
+# CHECK:  "id": 1,
+# CHECK-NEXT: "jsonrpc": "2.0",
+# CHECK-NEXT: "result": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "endLine": 1,
+# CHECK-NEXT: "kind": "region", 
+# CHECK-NEXT: "startCharacter": 10,
+# CHECK-NEXT: "startLine": 0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+---
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -459,6 +459,9 @@
  "no longer supported. Migrate to standard semanticTokens request");
   }
 
+  // Must be initialized before creating a ClangdServer object!
+  Opts.LineFoldingOnly = Params.capabilities.LineFoldingOnly;
+
   if (Params.rootUri && *Params.rootUri)
 Opts.WorkspaceRoot = std::string(Params.rootUri->file());
   else if (Params.rootPath && !Params.rootPath->empty())
@@ -514,7 +517,6 @@
   Params.capabilities.HierarchicalDocumentSymbol;
   SupportFileStatus = Params.initializationOptions.FileStatus;
   HoverContentFormat = Params.capabilities.HoverContentFormat;
-  Opts.LineFoldingOnly = Params.capabilities.LineFoldingOnly;
   SupportsOffsetsInSignatureHelp = Params.capabilities.OffsetsInSignatureHelp;
   if (Params.capabilities.WorkDoneProgress)
 BackgroundIndexProgressState = BackgroundIndexProgress::Empty;


Index: clang-tools-extra/clangd/test/folding-range.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/folding-range.test
@@ -0,0 +1,24 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+void f() {
+
+}
+---
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument": {"foldingRange": {"lineFoldingOnly": true}}},"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"cpp","text":"void f() {\n\n}\n","uri":"test:///foo.cpp","version":1}}}
+---
+{"id":1,"jsonrpc":"2.0","method":"textDocument/foldingRange","params":{"textDocument":{"uri":"test:///foo.cpp"}}}
+# CHECK:  "id": 1,
+# CHECK-NEXT: "jsonrpc": "2.0",
+# CHECK-NEXT: "result": [
+# CHECK-NEXT:   {
+# CHECK-NEXT: "endLine": 1,
+# CHECK-NEXT: "kind": "region", 
+# CHECK-NEXT: "startCharacter": 10,
+# CHECK-NEXT: "startLine": 0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+---
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -459,6 +459,9 @@
  "no longer supported. Migrate to standard semanticTokens request");
   }
 
+  // Must be initialized before creating a ClangdServer object!
+  Opts.LineFoldingOnly = Params.capabilities.LineFoldingOnly;
+
   if (Params.rootUri && *Params.rootUri)
 Opts.WorkspaceRoot = std::string(Params.rootUri->file());
   else if (Params.rootPath && !Params.rootPath->empty())
@@ -514,7 +517,6 @@
   Params.capabilities.HierarchicalDocumentSymbol;
   SupportFileStatus = Params.initializationOptions.FileStatus;
   HoverContentFormat = Params.capabilities.HoverContentFormat;
-  Opts.LineFoldingOnly = Params.capabilities.LineFoldingOnly;
   SupportsOffsetsInSignatureHelp = Params.capabilities.OffsetsInSignatureHelp;
   if (Params.capabilities.WorkDoneProgress)