Author: sammccall Date: Mon Jun 10 06:01:49 2019 New Revision: 362934 URL: http://llvm.org/viewvc/llvm-project?rev=362934&view=rev Log: [clangd] Stop marshalling/requiring FormattingOptions. We never did anything with them.
Modified: clang-tools-extra/trunk/clangd/Protocol.cpp clang-tools-extra/trunk/clangd/Protocol.h clang-tools-extra/trunk/clangd/test/formatting.test Modified: clang-tools-extra/trunk/clangd/Protocol.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=362934&r1=362933&r2=362934&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.cpp (original) +++ clang-tools-extra/trunk/clangd/Protocol.cpp Mon Jun 10 06:01:49 2019 @@ -402,38 +402,23 @@ bool fromJSON(const llvm::json::Value &P O.map("text", R.text); } -bool fromJSON(const llvm::json::Value &Params, FormattingOptions &R) { - llvm::json::ObjectMapper O(Params); - return O && O.map("tabSize", R.tabSize) && - O.map("insertSpaces", R.insertSpaces); -} - -llvm::json::Value toJSON(const FormattingOptions &P) { - return llvm::json::Object{ - {"tabSize", P.tabSize}, - {"insertSpaces", P.insertSpaces}, - }; -} - bool fromJSON(const llvm::json::Value &Params, DocumentRangeFormattingParams &R) { llvm::json::ObjectMapper O(Params); return O && O.map("textDocument", R.textDocument) && - O.map("range", R.range) && O.map("options", R.options); + O.map("range", R.range); } bool fromJSON(const llvm::json::Value &Params, DocumentOnTypeFormattingParams &R) { llvm::json::ObjectMapper O(Params); return O && O.map("textDocument", R.textDocument) && - O.map("position", R.position) && O.map("ch", R.ch) && - O.map("options", R.options); + O.map("position", R.position) && O.map("ch", R.ch); } bool fromJSON(const llvm::json::Value &Params, DocumentFormattingParams &R) { llvm::json::ObjectMapper O(Params); - return O && O.map("textDocument", R.textDocument) && - O.map("options", R.options); + return O && O.map("textDocument", R.textDocument); } bool fromJSON(const llvm::json::Value &Params, DocumentSymbolParams &R) { Modified: clang-tools-extra/trunk/clangd/Protocol.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=362934&r1=362933&r2=362934&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Protocol.h (original) +++ clang-tools-extra/trunk/clangd/Protocol.h Mon Jun 10 06:01:49 2019 @@ -548,15 +548,13 @@ struct DidChangeConfigurationParams { }; bool fromJSON(const llvm::json::Value &, DidChangeConfigurationParams &); -struct FormattingOptions { - /// Size of a tab in spaces. - int tabSize = 0; - - /// Prefer spaces over tabs. - bool insertSpaces = false; -}; -bool fromJSON(const llvm::json::Value &, FormattingOptions &); -llvm::json::Value toJSON(const FormattingOptions &); +// Note: we do not parse FormattingOptions for *FormattingParams. +// In general, we use a clang-format style detected from common mechanisms +// (.clang-format files and the -fallback-style flag). +// It would be possible to override these with FormatOptions, but: +// - the protocol makes FormatOptions mandatory, so many clients set them to +// useless values, and we can't tell when to respect them +// - we also format in other places, where FormatOptions aren't available. struct DocumentRangeFormattingParams { /// The document to format. @@ -564,9 +562,6 @@ struct DocumentRangeFormattingParams { /// The range to format Range range; - - /// The format options - FormattingOptions options; }; bool fromJSON(const llvm::json::Value &, DocumentRangeFormattingParams &); @@ -579,18 +574,12 @@ struct DocumentOnTypeFormattingParams { /// The character that has been typed. std::string ch; - - /// The format options. - FormattingOptions options; }; bool fromJSON(const llvm::json::Value &, DocumentOnTypeFormattingParams &); struct DocumentFormattingParams { /// The document to format. TextDocumentIdentifier textDocument; - - /// The format options - FormattingOptions options; }; bool fromJSON(const llvm::json::Value &, DocumentFormattingParams &); Modified: clang-tools-extra/trunk/clangd/test/formatting.test URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/formatting.test?rev=362934&r1=362933&r2=362934&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/test/formatting.test (original) +++ clang-tools-extra/trunk/clangd/test/formatting.test Mon Jun 10 06:01:49 2019 @@ -3,7 +3,7 @@ --- {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"int foo ( int x ) {\n x = x+1;\n return x;\n }"}}} --- -{"jsonrpc":"2.0","id":1,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}} +{"jsonrpc":"2.0","id":1,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":4},"end":{"line":1,"character":12}}}} # CHECK: "id": 1, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": [ @@ -65,12 +65,12 @@ # # --- -{"jsonrpc":"2.0","id":2,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":2},"end":{"line":1,"character":12}},"options":{"tabSize":4,"insertSpaces":true}}} +{"jsonrpc":"2.0","id":2,"method":"textDocument/rangeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"range":{"start":{"line":1,"character":2},"end":{"line":1,"character":12}}}} # CHECK: "id": 2, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": [] --- -{"jsonrpc":"2.0","id":3,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}} +{"jsonrpc":"2.0","id":3,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"}}} # CHECK: "id": 3, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": [ @@ -130,14 +130,14 @@ --- {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":9},"contentChanges":[{"text":"int foo(int x) {\n x = x + 1;\n return x;\n}"}]}} --- -{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"},"options":{"tabSize":4,"insertSpaces":true}}} +{"jsonrpc":"2.0","id":4,"method":"textDocument/formatting","params":{"textDocument":{"uri":"test:///foo.c"}}} # CHECK: "id": 4, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": [] --- {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///foo.c","version":5},"contentChanges":[{"text":"int foo ( int x ) {\n x = x + 1;\n return x;\n}"}]}} --- -{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"position":{"line":3,"character":1},"ch":"}","options":{"tabSize":4,"insertSpaces":true}}} +{"jsonrpc":"2.0","id":5,"method":"textDocument/onTypeFormatting","params":{"textDocument":{"uri":"test:///foo.c"},"position":{"line":3,"character":1},"ch":"}"}} # CHECK: "id": 5, # CHECK-NEXT: "jsonrpc": "2.0", # CHECK-NEXT: "result": [ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits