Commit 6ff0228c authored by David Goldman's avatar David Goldman
Browse files

[clang] Add `forceReload` clangd extension to 'textDocument/didChange'

Summary:
- This option forces a preamble rebuild to handle the odd case
  of a missing header file being added

Reviewers: sammccall

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, jfb, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73916
parent b50431de
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -647,7 +647,7 @@ void ClangdLSPServer::onDocumentDidChange(
    return;
  }

  Server->addDocument(File, *Contents, WantDiags);
  Server->addDocument(File, *Contents, WantDiags, Params.forceRebuild);
}

void ClangdLSPServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
+2 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
}

void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
                               WantDiagnostics WantDiags) {
                               WantDiagnostics WantDiags, bool ForceRebuild) {
  auto FS = FSProvider.getFileSystem();

  ParseOptions Opts;
@@ -184,6 +184,7 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
  ParseInputs Inputs;
  Inputs.FS = FS;
  Inputs.Contents = std::string(Contents);
  Inputs.ForceRebuild = ForceRebuild;
  Inputs.Opts = std::move(Opts);
  Inputs.Index = Index;
  bool NewFile = WorkScheduler.update(File, Inputs, WantDiags);
+2 −1
Original line number Diff line number Diff line
@@ -172,7 +172,8 @@ public:
  /// separate thread. When the parsing is complete, DiagConsumer passed in
  /// constructor will receive onDiagnosticsReady callback.
  void addDocument(PathRef File, StringRef Contents,
                   WantDiagnostics WD = WantDiagnostics::Auto);
                   WantDiagnostics WD = WantDiagnostics::Auto,
                   bool ForceRebuild = false);

  /// Get the contents of \p File, which should have been added.
  llvm::StringRef getDocument(PathRef File) const;
+3 −0
Original line number Diff line number Diff line
@@ -45,6 +45,9 @@ struct ParseInputs {
  tooling::CompileCommand CompileCommand;
  IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS;
  std::string Contents;
  // Prevent reuse of the cached preamble/AST. Slow! Useful to workaround
  // clangd's assumption that missing header files will stay missing.
  bool ForceRebuild = false;
  // Used to recover from diagnostics (e.g. find missing includes for symbol).
  const SymbolIndex *Index = nullptr;
  ParseOptions Opts;
+4 −1
Original line number Diff line number Diff line
@@ -430,7 +430,10 @@ bool fromJSON(const llvm::json::Value &Params, DidCloseTextDocumentParams &R) {

bool fromJSON(const llvm::json::Value &Params, DidChangeTextDocumentParams &R) {
  llvm::json::ObjectMapper O(Params);
  return O && O.map("textDocument", R.textDocument) &&
  if (!O)
    return false;
  O.map("forceRebuild", R.forceRebuild);  // Optional clangd extension.
  return O.map("textDocument", R.textDocument) &&
         O.map("contentChanges", R.contentChanges) &&
         O.map("wantDiagnostics", R.wantDiagnostics);
}
Loading