Index: clangd/ClangdLSPServer.h =================================================================== --- clangd/ClangdLSPServer.h +++ clangd/ClangdLSPServer.h @@ -121,12 +121,6 @@ setCompilationCommandForFile(PathRef File, tooling::CompileCommand CompilationCommand); - /// Adds extra compilation flags to the compilation command for a particular - /// file. Only valid for directory-based CDB, no-op and error log on - /// InMemoryCDB; - void setExtraFlagsForFile(PathRef File, - std::vector ExtraFlags); - /// Returns a CDB that should be used to get compile commands for the /// current instance of ClangdLSPServer. GlobalCompilationDatabase &getCDB() { return *CDB; } Index: clangd/ClangdLSPServer.cpp =================================================================== --- clangd/ClangdLSPServer.cpp +++ clangd/ClangdLSPServer.cpp @@ -366,8 +366,6 @@ void ClangdLSPServer::onDocumentDidOpen( const DidOpenTextDocumentParams &Params) { PathRef File = Params.textDocument.uri.file(); - if (Params.metadata && !Params.metadata->extraFlags.empty()) - CDB->setExtraFlagsForFile(File, std::move(Params.metadata->extraFlags)); const std::string &Contents = Params.textDocument.text; @@ -811,17 +809,5 @@ ->setCompilationCommandForFile(File, std::move(CompilationCommand)); } -void ClangdLSPServer::CompilationDB::setExtraFlagsForFile( - PathRef File, std::vector ExtraFlags) { - if (!IsDirectoryBased) { - elog("Trying to set extra flags for {0} while using in-memory compilation " - "database", - File); - return; - } - static_cast(CDB.get()) - ->setExtraFlagsForFile(File, std::move(ExtraFlags)); -} - } // namespace clangd } // namespace clang Index: clangd/GlobalCompilationDatabase.h =================================================================== --- clangd/GlobalCompilationDatabase.h +++ clangd/GlobalCompilationDatabase.h @@ -59,16 +59,9 @@ llvm::Optional getCompileCommand(PathRef File) const override; - /// Uses the default fallback command, adding any extra flags. - tooling::CompileCommand getFallbackCommand(PathRef File) const override; - - /// Sets the extra flags that should be added to a file. - void setExtraFlagsForFile(PathRef File, std::vector ExtraFlags); - private: tooling::CompilationDatabase *getCDBForFile(PathRef File) const; tooling::CompilationDatabase *getCDBInDirLocked(PathRef File) const; - void addExtraFlags(PathRef File, tooling::CompileCommand &C) const; mutable std::mutex Mutex; /// Caches compilation databases loaded from directories(keys are @@ -76,8 +69,6 @@ mutable llvm::StringMap> CompilationDatabases; - /// Stores extra flags per file. - llvm::StringMap> ExtraFlagsForFile; /// Used for command argument pointing to folder where compile_commands.json /// is located. llvm::Optional CompileCommandsDir; Index: clangd/GlobalCompilationDatabase.cpp =================================================================== --- clangd/GlobalCompilationDatabase.cpp +++ clangd/GlobalCompilationDatabase.cpp @@ -41,45 +41,14 @@ DirectoryBasedGlobalCompilationDatabase::getCompileCommand(PathRef File) const { if (auto CDB = getCDBForFile(File)) { auto Candidates = CDB->getCompileCommands(File); - if (!Candidates.empty()) { - addExtraFlags(File, Candidates.front()); + if (!Candidates.empty()) return std::move(Candidates.front()); - } } else { log("Failed to find compilation database for {0}", File); } return None; } -tooling::CompileCommand -DirectoryBasedGlobalCompilationDatabase::getFallbackCommand( - PathRef File) const { - auto C = GlobalCompilationDatabase::getFallbackCommand(File); - addExtraFlags(File, C); - return C; -} - -void DirectoryBasedGlobalCompilationDatabase::setExtraFlagsForFile( - PathRef File, std::vector ExtraFlags) { - std::lock_guard Lock(Mutex); - ExtraFlagsForFile[File] = std::move(ExtraFlags); -} - -void DirectoryBasedGlobalCompilationDatabase::addExtraFlags( - PathRef File, tooling::CompileCommand &C) const { - std::lock_guard Lock(Mutex); - - auto It = ExtraFlagsForFile.find(File); - if (It == ExtraFlagsForFile.end()) - return; - - auto &Args = C.CommandLine; - assert(Args.size() >= 2 && "Expected at least [compiler, source file]"); - // The last argument of CommandLine is the name of the input file. - // Add ExtraFlags before it. - Args.insert(Args.end() - 1, It->second.begin(), It->second.end()); -} - tooling::CompilationDatabase * DirectoryBasedGlobalCompilationDatabase::getCDBInDirLocked(PathRef Dir) const { // FIXME(ibiryukov): Invalidate cached compilation databases on changes Index: clangd/Protocol.h =================================================================== --- clangd/Protocol.h +++ clangd/Protocol.h @@ -175,11 +175,6 @@ llvm::json::Value toJSON(const Location &); llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Location &); -struct Metadata { - std::vector extraFlags; -}; -bool fromJSON(const llvm::json::Value &, Metadata &); - struct TextEdit { /// The range of the text document to be manipulated. To insert /// text into a document create a range where start === end. @@ -411,9 +406,6 @@ struct DidOpenTextDocumentParams { /// The document that was opened. TextDocumentItem textDocument; - - /// Extension storing per-file metadata, such as compilation flags. - llvm::Optional metadata; }; bool fromJSON(const llvm::json::Value &, DidOpenTextDocumentParams &); Index: clangd/Protocol.cpp =================================================================== --- clangd/Protocol.cpp +++ clangd/Protocol.cpp @@ -119,14 +119,6 @@ O.map("version", R.version) && O.map("text", R.text); } -bool fromJSON(const json::Value &Params, Metadata &R) { - json::ObjectMapper O(Params); - if (!O) - return false; - O.map("extraFlags", R.extraFlags); - return true; -} - bool fromJSON(const json::Value &Params, TextEdit &R) { json::ObjectMapper O(Params); return O && O.map("range", R.range) && O.map("newText", R.newText); @@ -262,8 +254,7 @@ bool fromJSON(const json::Value &Params, DidOpenTextDocumentParams &R) { json::ObjectMapper O(Params); - return O && O.map("textDocument", R.textDocument) && - O.map("metadata", R.metadata); + return O && O.map("textDocument", R.textDocument); } bool fromJSON(const json::Value &Params, DidCloseTextDocumentParams &R) { Index: test/clangd/extra-flags.test =================================================================== --- test/clangd/extra-flags.test +++ test/clangd/extra-flags.test @@ -1,52 +0,0 @@ -# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s -{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}} ---- -{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"int main() { int i; return i; }"},"metadata":{"extraFlags":["-Wall"]}}} -# CHECK: "method": "textDocument/publishDiagnostics", -# CHECK-NEXT: "params": { -# CHECK-NEXT: "diagnostics": [ -# CHECK-NEXT: { -# CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here", -# CHECK-NEXT: "range": { -# CHECK-NEXT: "end": { -# CHECK-NEXT: "character": 28, -# CHECK-NEXT: "line": 0 -# CHECK-NEXT: }, -# CHECK-NEXT: "start": { -# CHECK-NEXT: "character": 27, -# CHECK-NEXT: "line": 0 -# CHECK-NEXT: } -# CHECK-NEXT: }, -# CHECK-NEXT: "severity": 2 -# CHECK-NEXT: } -# CHECK-NEXT: ], -# CHECK-NEXT: "uri": "file://{{.*}}/foo.c" -# CHECK-NEXT: } ---- -{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":2},"contentChanges":[{"text":"int main() { int i; return i+1; }"}]}} -# CHECK: "method": "textDocument/publishDiagnostics", -# CHECK-NEXT: "params": { -# CHECK-NEXT: "diagnostics": [ -# CHECK-NEXT: { -# CHECK-NEXT: "message": "Variable 'i' is uninitialized when used here", -# CHECK-NEXT: "range": { -# CHECK-NEXT: "end": { -# CHECK-NEXT: "character": 28, -# CHECK-NEXT: "line": 0 -# CHECK-NEXT: }, -# CHECK-NEXT: "start": { -# CHECK-NEXT: "character": 27, -# CHECK-NEXT: "line": 0 -# CHECK-NEXT: } -# CHECK-NEXT: }, -# CHECK-NEXT: "severity": 2 -# CHECK-NEXT: } -# CHECK-NEXT: ], -# CHECK-NEXT: "uri": "file://{{.*}}/foo.c" -# CHECK-NEXT: } ---- -{"jsonrpc":"2.0","id":5,"method":"shutdown"} ---- -{"jsonrpc":"2.0","method":"exit"} - -